36 uint64_t epoch = sourceDateEpoch.
toUInt64(&ok);
39 static bool warnedOnce=
FALSE;
42 warn_uncond(
"Environment variable SOURCE_DATE_EPOCH does not contain a valid number; value is '%s'\n",
49 auto epoch_start = std::chrono::time_point<std::chrono::system_clock>{};
50 auto epoch_seconds = std::chrono::seconds(epoch);
51 auto build_time = epoch_start + epoch_seconds;
52 std::time_t time = std::chrono::system_clock::to_time_t(build_time);
53 return *gmtime(&time);
58 auto now = std::chrono::system_clock::now();
59 std::time_t time = std::chrono::system_clock::to_time_t(now);
60 return *localtime(&time);
69 (current.tm_wday+6)%7+1,
113 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_year = value-1900; }, 1900, 9999,
"year" },
114 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_mon = value-1; }, 1, 12,
"month" },
115 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_mday = value; }, 1, 31,
"day" },
116 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_hour = value; }, 0, 23,
"hour" },
117 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_min = value; }, 0, 59,
"minute" },
118 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_sec = value; }, 0, 59,
"second" }
126 const auto as_time_t = std::mktime( &cpy ) ;
129 cpy = *std::localtime( &as_time_t ) ;
130 tm.tm_wday = cpy.tm_wday;
145 std::string s = spec.
str();
151 for (
int i=0; i<
fmt.count; i++)
153 int value = std::atoi(m[i+1].str().c_str());
155 if (value<dtf.minVal || value>dtf.
maxVal)
157 return QCString().
sprintf(
"value for %s is %d which is outside of the value range [%d..%d]",
172 return "invalid or non representable date/time argument";
178 auto getYear = [](
const std::tm &dat) {
return dat.tm_year+1900; };
179 auto getMonth = [](
const std::tm &dat) {
return dat.tm_mon+1; };
180 auto getDay = [](
const std::tm &dat) {
return dat.tm_mday; };
181 auto getDayOfWeek = [](
const std::tm &dat) {
return (dat.tm_wday+6)%7+1; };
184 const char *p = format.
data();
185 const char *fmt_zero =
"%02d";
186 const char *fmt_nonzero =
"%d";
187 const char *fmt_selected =
nullptr;
195 fmt_selected = nc==
'-' ? fmt_nonzero : fmt_zero;
196 if (nc==
'-') nc=*++p;
199 case '%': growBuf.
addChar(
'%');
break;
200 case 'y': growBuf.
addInt(fmt_selected,getYear(dt)%100); formatUsed|=
SF_Date;
break;
201 case 'Y': growBuf.
addInt(
"%d",getYear(dt)); formatUsed|=
SF_Date;
break;
202 case 'm': growBuf.
addInt(fmt_selected,getMonth(dt)); formatUsed|=
SF_Date;
break;
205 case 'd': growBuf.
addInt(fmt_selected,getDay(dt)); formatUsed|=
SF_Date;
break;
206 case 'u': growBuf.
addInt(
"%d",getDayOfWeek(dt)); formatUsed|=
SF_Date;
break;
207 case 'w': growBuf.
addInt(
"%d",getDayOfWeek(dt)%7); formatUsed|=
SF_Date;
break;
210 case 'H': growBuf.
addInt(fmt_selected,dt.tm_hour); formatUsed|=
SF_Time;
break;
211 case 'I': growBuf.
addInt(fmt_selected,dt.tm_hour%12); formatUsed|=
SF_Time;
break;
213 case 'M': growBuf.
addInt(fmt_selected,dt.tm_min); formatUsed|=
SF_Time;
break;
214 case 'S': growBuf.
addInt(fmt_selected,dt.tm_sec); formatUsed|=
SF_Seconds;
break;
217 if (*(p-1)==
'-') growBuf.
addChar(
'-');
229 return growBuf.
get();
Class representing a string buffer optimized for growing.
void addInt(const char *fmt, int value)
void addStr(const QCString &s)
This is an alternative implementation of QCString.
uint64_t toUInt64(bool *ok=nullptr, int base=10) const
bool isEmpty() const
Returns TRUE iff the string is empty.
const std::string & str() const
QCString & setNum(short n)
QCString & sprintf(const char *format,...)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Class representing a regular expression.
Object representing the matching results.
QCString dateToString(DateTimeType includeTime)
Returns the current date, when includeTime is set also the time is provided.
std::function< void(std::tm &, int value) > TMFieldAssigner
QCString yearToString()
Returns the current year as a string.
QCString formatDateTime(const QCString &format, const std::tm &dt, int &formatUsed)
Return a string representation for a given std::tm value that is formatted according to the pattern g...
std::tm getCurrentDateTime()
Returns the filled in std::tm for the current date and time.
static void determine_weekday(std::tm &tm)
QCString dateTimeFromString(const QCString &spec, std::tm &dt, int &format)
Returns the filled in std::tm for a given string representing a date and/or time.
static std::array g_assignValues
static std::array g_specFormats
constexpr int SF_Seconds
the seconds are presenting in the format string
constexpr int SF_Date
Date and time related functions.
constexpr int SF_Time
a time is presenting in the format string
Translator * theTranslator
#define warn_uncond(fmt,...)
QCString getenv(const QCString &variable)
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Portable versions of functions that are platform dependent.
const char * qPrint(const char *s)