35 uint64_t epoch = sourceDateEpoch.
toUInt64(&ok);
38 static bool warnedOnce=
FALSE;
41 warn_uncond(
"Environment variable SOURCE_DATE_EPOCH does not contain a valid number; value is '{}'\n",
48 auto epoch_start = std::chrono::time_point<std::chrono::system_clock>{};
49 auto epoch_seconds = std::chrono::seconds(epoch);
50 auto build_time = epoch_start + epoch_seconds;
51 std::time_t time = std::chrono::system_clock::to_time_t(build_time);
52 return *gmtime(&time);
57 auto now = std::chrono::system_clock::now();
58 std::time_t time = std::chrono::system_clock::to_time_t(now);
59 return *localtime(&time);
68 (current.tm_wday+6)%7+1,
112 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_year = value-1900; }, 1900, 9999,
"year" },
113 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_mon = value-1; }, 1, 12,
"month" },
114 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_mday = value; }, 1, 31,
"day" },
115 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_hour = value; }, 0, 23,
"hour" },
116 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_min = value; }, 0, 59,
"minute" },
117 DateTimeField{ [](std::tm &tm,
int value) { tm.tm_sec = value; }, 0, 59,
"second" }
125 const auto as_time_t = std::mktime( &cpy ) ;
128 cpy = *std::localtime( &as_time_t ) ;
129 tm.tm_wday = cpy.tm_wday;
144 const std::string &s = spec.
str();
150 for (
int i=0; i<
fmt.count; i++)
152 int value = std::atoi(m[i+1].str().c_str());
154 if (value<dtf.minVal || value>dtf.
maxVal)
156 return QCString().
sprintf(
"value for %s is %d which is outside of the value range [%d..%d]",
171 return "invalid or non representable date/time argument";
177 auto getYear = [](
const std::tm &dat) {
return dat.tm_year+1900; };
178 auto getMonth = [](
const std::tm &dat) {
return dat.tm_mon+1; };
179 auto getDay = [](
const std::tm &dat) {
return dat.tm_mday; };
180 auto getDayOfWeek = [](
const std::tm &dat) {
return (dat.tm_wday+6)%7+1; };
183 auto addInt = [&result](
const char *
fmt,
int value) {
189 const char *p = format.
data();
190 const char *fmt_zero =
"%02d";
191 const char *fmt_nonzero =
"%d";
192 const char *fmt_selected =
nullptr;
200 fmt_selected = nc==
'-' ? fmt_nonzero : fmt_zero;
201 if (nc==
'-') nc=*++p;
204 case '%': result+=
'%';
break;
205 case 'y': addInt(fmt_selected,getYear(dt)%100); formatUsed|=
SF_Date;
break;
206 case 'Y': addInt(
"%d",getYear(dt)); formatUsed|=
SF_Date;
break;
207 case 'm': addInt(fmt_selected,getMonth(dt)); formatUsed|=
SF_Date;
break;
210 case 'd': addInt(fmt_selected,getDay(dt)); formatUsed|=
SF_Date;
break;
211 case 'u': addInt(
"%d",getDayOfWeek(dt)); formatUsed|=
SF_Date;
break;
212 case 'w': addInt(
"%d",getDayOfWeek(dt)%7); formatUsed|=
SF_Date;
break;
213 case 'a': result+=
theTranslator->trDayOfWeek(getDayOfWeek(dt),
false,
false); formatUsed|=
SF_Date;
break;
214 case 'A': result+=
theTranslator->trDayOfWeek(getDayOfWeek(dt),
false,
true); formatUsed|=
SF_Date;
break;
215 case 'H': addInt(fmt_selected,dt.tm_hour); formatUsed|=
SF_Time;
break;
216 case 'I': addInt(fmt_selected,dt.tm_hour%12); formatUsed|=
SF_Time;
break;
218 case 'M': addInt(fmt_selected,dt.tm_min); formatUsed|=
SF_Time;
break;
219 case 'S': addInt(fmt_selected,dt.tm_sec); formatUsed|=
SF_Seconds;
break;
222 if (*(p-1)==
'-') result+=
'-';
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)
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
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.