49 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
55 static const char *
const Months[] = {
56 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
57 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 65 static const struct Tz TimeZones[] = {
66 {
"aat", 1, 0,
true },
67 {
"adt", 4, 0,
false },
68 {
"ast", 3, 0,
false },
70 {
"bst", 1, 0,
false },
71 {
"cat", 1, 0,
false },
72 {
"cdt", 5, 0,
true },
73 {
"cest", 2, 0,
false },
74 {
"cet", 1, 0,
false },
75 {
"cst", 6, 0,
true },
78 {
"eat", 3, 0,
false },
79 {
"edt", 4, 0,
true },
80 {
"eest", 3, 0,
false },
81 {
"eet", 2, 0,
false },
82 {
"egst", 0, 0,
false },
83 {
"egt", 1, 0,
true },
84 {
"est", 5, 0,
true },
85 {
"gmt", 0, 0,
false },
86 {
"gst", 4, 0,
false },
87 {
"hkt", 8, 0,
false },
88 {
"ict", 7, 0,
false },
89 {
"idt", 3, 0,
false },
90 {
"ist", 2, 0,
false },
92 {
"jst", 9, 0,
false },
93 {
"kst", 9, 0,
false },
94 {
"mdt", 6, 0,
true },
95 {
"met", 1, 0,
false },
96 {
"met dst", 2, 0,
false },
97 {
"msd", 4, 0,
false },
98 {
"msk", 3, 0,
false },
99 {
"mst", 7, 0,
true },
100 {
"nzdt", 13, 0,
false },
101 {
"nzst", 12, 0,
false },
102 {
"pdt", 7, 0,
true },
103 {
"pst", 8, 0,
true },
104 {
"sat", 2, 0,
false },
105 {
"smt", 4, 0,
false },
106 {
"sst", 11, 0,
true },
108 {
"utc", 0, 0,
false },
109 {
"wat", 0, 0,
false },
110 {
"west", 1, 0,
false },
111 {
"wet", 0, 0,
false },
112 {
"wgst", 2, 0,
true },
113 {
"wgt", 3, 0,
true },
114 {
"wst", 8, 0,
false },
131 time_t t = (((lt.tm_hour - utc->tm_hour) * 60) + (lt.tm_min - utc->tm_min)) * 60;
133 int yday = (lt.tm_yday - utc->tm_yday);
162 return t + (w ? 1 : -1) * (((time_t) h * 3600) + ((time_t) m * 60));
174 static const struct Tz *
find_tz(
const char *s,
size_t len)
179 return &TimeZones[i];
194 int y = tm->tm_year + 1900;
195 return ((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0));
235 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
239 if (t->tm_year > 10000)
241 if (t->tm_year < -10000)
244 if ((t->tm_mday < 1) || (t->tm_mday > 31))
246 if ((t->tm_hour < 0) || (t->tm_hour > 23) || (t->tm_min < 0) ||
247 (t->tm_min > 59) || (t->tm_sec < 0) || (t->tm_sec > 60))
251 if (t->tm_year > 9999)
260 if ((t->tm_year % 4) || (t->tm_mon < 2))
265 g += (t->tm_year - 70) * (time_t) 365;
266 g += (t->tm_year - 69) / 4;
301 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
305 while (tm->tm_sec < 0)
310 while (tm->tm_sec >= 60)
315 while (tm->tm_min < 0)
320 while (tm->tm_min >= 60)
325 while (tm->tm_hour < 0)
330 while (tm->tm_hour >= 24)
336 while (tm->tm_mon < 0)
341 while (tm->tm_mon >= 12)
346 while (tm->tm_mday <= 0)
357 while (tm->tm_mday > (DaysPerMonth[tm->tm_mon] + (leap =
is_leap_year_feb(tm))))
359 tm->tm_mday -= DaysPerMonth[tm->tm_mon] + leap;
390 tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec,
391 (
int) tz / 60, (
int) abs((
int) tz) % 60);
427 struct timeval tv = { 0, 0 };
428 gettimeofday(&tv, NULL);
431 return (uint64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
465 struct tm tm = { 0 };
490 else if (tm.tm_year >= 1900)
494 int hour, min, sec = 0;
499 if ((hour > 23) || (min > 59) || (sec > 60))
508 bool zoccident =
false;
513 zoccident = (direction ==
'-');
517 const struct Tz *tz =
556 return snprintf(buf, buflen,
"%02d-%s-%d %02d:%02d:%02d %+03d%02d",
557 tm.tm_mday,
Months[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour,
558 tm.tm_min, tm.tm_sec, (
int) tz / 60, (
int) abs((
int) tz) % 60);
578 return snprintf(buf, buflen,
"%s, %d %s %d %02d:%02d:%02d UTC",
580 tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
610 int zhours, zminutes;
612 bool zoccident = (direction ==
'-');
633 return now + timeout;
645 struct tm tm = { 0 };
650 localtime_r(&t, &tm);
663 struct tm tm = { 0 };
686 return strftime(buf, buflen, format, &tm);
697 .tv_nsec = (ms % 1000) * 1000000UL,
699 nanosleep(&sleep, NULL);
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Tue, 3 Mar [2020] 14:32:55 +0200
uint64_t mutt_date_epoch_ms(void)
Return the number of milliseconds since the Unix epoch.
Manage precompiled / predefined regular expressions.
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
void mutt_date_make_date(struct Buffer *buf)
Write a date in RFC822 format to a buffer.
Tue, [3] Mar 2020 14:32:55 +0200
Memory management wrappers.
struct tm mutt_date_localtime(time_t t)
Converts calendar time to a broken-down time structure expressed in user timezone.
Tue, 3 Mar 2020 14:32:55[UT]
[16-MAR-2020 15:09:35 -0700]
Tue, 3 Mar 2020 14:32:[55] +0200
static const char *const Months[]
Months of the year (abbreviated)
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
String manipulation buffer.
void mutt_date_normalize_time(struct tm *tm)
Fix the contents of a struct tm.
static const char * timestamp(time_t stamp)
Create a YYYY-MM-DD HH:MM:SS timestamp.
Tue, [3] Mar 2020 14:32:55 +0200
#define MUTT_DATE_NOW
Constant representing the 'current time', see: mutt_date_gmtime(), mutt_date_localtime() ...
15-MAR-2020 15:09:35 [-0700]
struct tm mutt_date_gmtime(time_t t)
Converts calendar time to a broken-down time structure expressed in UTC timezone. ...
time_t mutt_date_local_tz(time_t t)
Calculate the local timezone in seconds east of UTC.
15-MAR-2020 [15:09:35] -0700
time_t mutt_date_parse_date(const char *s, struct Tz *tz_out)
Parse a date string in RFC822 format.
static int is_leap_year_feb(struct tm *tm)
Is a given February in a leap year.
Tue, 3 Mar 2020 14:[32]:55 +0200
Tue, 3 Mar [2020] 14:32:55 +0200
unsigned char zhours
Hours away from UTC.
char tzname[8]
Name, e.g. UTC.
Tue, 3 Mar 2020 14:32:55 [+0200]
15-MAR-[2020] 15:09:35 -0700
String manipulation functions.
bool mutt_istrn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings ignoring case (to a maximum), safely.
#define mutt_array_size(x)
time_t mutt_date_add_timeout(time_t now, time_t timeout)
Safely add a timeout to a given time_t value.
Tue, 3 [Jan] 2020 14:32:55 +0200
int mutt_date_make_tls(char *buf, size_t buflen, time_t timestamp)
Format date in TLS certificate verification style.
Tue, 3 Mar 2020 14:[32]:55 +0200
[Mon, (Comment) 16 Mar 2020 15:09:35 -0700]
bool zoccident
True if west of UTC, False if East.
Tue, 3 Mar 2020 14:32:55 [+0200]
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Tue, 3 Mar 2020 [14]:32:55 +0200
[ 4]-MAR-2020 15:09:35 -0700
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
match a precompiled regex against a string
static const struct Tz * find_tz(const char *s, size_t len)
Look up a timezone.
static time_t add_tz_offset(time_t t, bool w, time_t h, time_t m)
Compute and add a timezone offset to an UTC time.
Tue, 3 [Jan] 2020 14:32:55 +0200
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
[Mon, 16 Mar 2020 15:09:35 -0700]
static time_t compute_tz(time_t g, struct tm *utc)
Calculate the number of seconds east of UTC.
15-[MAR]-2020 15:09:35 -0700
unsigned char zminutes
Minutes away from UTC.
General purpose object for storing and parsing strings.
List of recognised Timezones.
Tue, 3 Mar 2020 14:32:[55] +0200
int mutt_date_check_month(const char *s)
Is the string a valid month name.
int mutt_date_make_imap(char *buf, size_t buflen, time_t timestamp)
Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz.
Time value with nanosecond precision.
#define mutt_debug(LEVEL,...)
time_t mutt_date_parse_imap(const char *s)
Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz.
static const char *const Weekdays[]
Day of the week (abbreviated)
Time and date handling routines.
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Tue, 3 Mar 2020 [14]:32:55 +0200
void mutt_date_sleep_ms(size_t ms)
Sleep for milliseconds.
Tue, 3 Mar 2020 14:32:55[UT]
Manage regular expressions.