NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
date.h File Reference

Time and date handling routines. More...

#include <stdbool.h>
#include <stdint.h>
#include <time.h>
+ Include dependency graph for date.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Tz
 List of recognised Timezones. More...
 

Macros

#define TIME_T_MAX   ((((time_t) 1 << (sizeof(time_t) * 8 - 2)) - 1) * 2 + 1)
 
#define TIME_T_MIN   (-TIME_T_MAX - 1)
 
#define TM_YEAR_MAX    (1970 + (((((TIME_T_MAX - 59) / 60) - 59) / 60) - 23) / 24 / 366)
 
#define TM_YEAR_MIN   (1970 - (TM_YEAR_MAX - 1970) - 1)
 

Functions

time_t mutt_date_add_timeout (time_t now, time_t timeout)
 Safely add a timeout to a given time_t value. More...
 
int mutt_date_check_month (const char *s)
 Is the string a valid month name. More...
 
time_t mutt_date_now (void)
 Return the number of seconds since the Unix epoch. More...
 
uint64_t mutt_date_now_ms (void)
 Return the number of milliseconds since the Unix epoch. More...
 
struct tm mutt_date_gmtime (time_t t)
 Converts calendar time to a broken-down time structure expressed in UTC timezone. More...
 
size_t mutt_date_localtime_format (char *buf, size_t buflen, const char *format, time_t t)
 Format localtime. More...
 
struct tm mutt_date_localtime (time_t t)
 Converts calendar time to a broken-down time structure expressed in user timezone. More...
 
int mutt_date_local_tz (time_t t)
 Calculate the local timezone in seconds east of UTC. More...
 
void mutt_date_make_date (struct Buffer *buf, bool local)
 Write a date in RFC822 format to a buffer. More...
 
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. More...
 
time_t mutt_date_make_time (struct tm *t, bool local)
 Convert struct tm to time_t More...
 
int mutt_date_make_tls (char *buf, size_t buflen, time_t timestamp)
 Format date in TLS certificate verification style. More...
 
void mutt_date_normalize_time (struct tm *tm)
 Fix the contents of a struct tm. More...
 
time_t mutt_date_parse_date (const char *s, struct Tz *tz_out)
 Parse a date string in RFC822 format. More...
 
time_t mutt_date_parse_imap (const char *s)
 Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz. More...
 
void mutt_date_sleep_ms (size_t ms)
 Sleep for milliseconds. More...
 

Detailed Description

Time and date handling routines.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file date.h.

Macro Definition Documentation

◆ TIME_T_MAX

#define TIME_T_MAX   ((((time_t) 1 << (sizeof(time_t) * 8 - 2)) - 1) * 2 + 1)

Definition at line 33 of file date.h.

◆ TIME_T_MIN

#define TIME_T_MIN   (-TIME_T_MAX - 1)

Definition at line 34 of file date.h.

◆ TM_YEAR_MAX

#define TM_YEAR_MAX    (1970 + (((((TIME_T_MAX - 59) / 60) - 59) / 60) - 23) / 24 / 366)

Definition at line 35 of file date.h.

◆ TM_YEAR_MIN

#define TM_YEAR_MIN   (1970 - (TM_YEAR_MAX - 1970) - 1)

Definition at line 37 of file date.h.

Function Documentation

◆ mutt_date_add_timeout()

time_t mutt_date_add_timeout ( time_t  now,
time_t  timeout 
)

Safely add a timeout to a given time_t value.

Parameters
nowTime now
timeoutTimeout in seconds
Return values
numUnix time to timeout

This will truncate instead of overflowing.

Definition at line 863 of file date.c.

864{
865 if (timeout < 0)
866 return now;
867
868 if ((TIME_T_MAX - now) < timeout)
869 return TIME_T_MAX;
870
871 return now + timeout;
872}
#define TIME_T_MAX
Definition: date.h:33
+ Here is the caller graph for this function:

◆ mutt_date_check_month()

int mutt_date_check_month ( const char *  s)

Is the string a valid month name.

Parameters
sString to check (must be at least 3 bytes long)
Return values
numIndex into Months array (0-based)
-1Error
Note
Only the first three characters are checked
The comparison is case insensitive

Definition at line 422 of file date.c.

423{
424 if (!s)
425 return -1;
426
427 char buf[4] = { 0 };
428 memcpy(buf, s, 3);
429 uint32_t sv;
430 memcpy(&sv, buf, sizeof(sv));
431 for (int i = 0; i < mutt_array_size(Months); i++)
432 {
433 uint32_t mv;
434 memcpy(&mv, Months[i], sizeof(mv));
435 if (sv == mv)
436 return i;
437 }
438
439 return -1; /* error */
440}
#define mutt_array_size(x)
Definition: memory.h:36
static const char *const Months[]
Months of the year (abbreviated)
Definition: date.c:57
+ Here is the caller graph for this function:

◆ mutt_date_now()

time_t mutt_date_now ( void  )

Return the number of seconds since the Unix epoch.

Return values
numNumber of seconds since the Unix epoch, or 0 on failure

Definition at line 446 of file date.c.

447{
448 return mutt_date_now_ms() / 1000;
449}
uint64_t mutt_date_now_ms(void)
Return the number of milliseconds since the Unix epoch.
Definition: date.c:455
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_now_ms()

uint64_t mutt_date_now_ms ( void  )

Return the number of milliseconds since the Unix epoch.

Return values
numThe number of ms since the Unix epoch, or 0 on failure

Definition at line 455 of file date.c.

456{
457 struct timeval tv = { 0, 0 };
458 gettimeofday(&tv, NULL);
459 /* We assume that gettimeofday doesn't modify its first argument on failure.
460 * We also kind of assume that gettimeofday does not fail. */
461 return (uint64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
462}
+ Here is the caller graph for this function:

◆ mutt_date_gmtime()

struct tm mutt_date_gmtime ( time_t  t)

Converts calendar time to a broken-down time structure expressed in UTC timezone.

Parameters
tTime
Return values
objBroken-down time representation

Definition at line 900 of file date.c.

901{
902 struct tm tm = { 0 };
903
904 struct tm *ret = gmtime_r(&t, &tm);
905 if (!ret)
906 {
907 mutt_debug(LL_DEBUG1, "Could not convert time_t via gmtime_r() to struct tm: time_t = %jd\n",
908 (intmax_t) t);
909 struct tm default_tm = { 0 }; // 1970-01-01 00:00:00
910 mktime(&default_tm); // update derived fields making tm into a valid tm.
911 tm = default_tm;
912 }
913 return tm;
914}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
+ Here is the caller graph for this function:

◆ mutt_date_localtime_format()

size_t mutt_date_localtime_format ( char *  buf,
size_t  buflen,
const char *  format,
time_t  t 
)

Format localtime.

Parameters
bufBuffer to store formatted time
buflenBuffer size
formatFormat to apply
tTime to format
Return values
numNumber of Bytes added to buffer, excluding NUL byte

Definition at line 924 of file date.c.

925{
926 if (!buf || !format)
927 return 0;
928
929 struct tm tm = mutt_date_localtime(t);
930 return strftime(buf, buflen, format, &tm);
931}
struct tm mutt_date_localtime(time_t t)
Converts calendar time to a broken-down time structure expressed in user timezone.
Definition: date.c:879
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_localtime()

struct tm mutt_date_localtime ( time_t  t)

Converts calendar time to a broken-down time structure expressed in user timezone.

Parameters
tTime
Return values
objBroken-down time representation

Definition at line 879 of file date.c.

880{
881 struct tm tm = { 0 };
882
883 struct tm *ret = localtime_r(&t, &tm);
884 if (!ret)
885 {
886 mutt_debug(LL_DEBUG1, "Could not convert time_t via localtime_r() to struct tm: time_t = %jd\n",
887 (intmax_t) t);
888 struct tm default_tm = { 0 }; // 1970-01-01 00:00:00
889 mktime(&default_tm); // update derived fields making tm into a valid tm.
890 tm = default_tm;
891 }
892 return tm;
893}
+ Here is the caller graph for this function:

◆ mutt_date_local_tz()

int mutt_date_local_tz ( time_t  t)

Calculate the local timezone in seconds east of UTC.

Parameters
tTime to examine
Return values
numSeconds east of UTC

Returns the local timezone in seconds east of UTC for the time t, or for the current time if t is zero.

Definition at line 209 of file date.c.

210{
211 /* Check we haven't overflowed the time (on 32-bit arches) */
212 if ((t == TIME_T_MAX) || (t == TIME_T_MIN))
213 return 0;
214
215 if (t == 0)
216 t = mutt_date_now();
217
218 struct tm tm = mutt_date_gmtime(t);
219 return compute_tz(t, &tm);
220}
#define TIME_T_MIN
Definition: date.h:34
static int compute_tz(time_t g, struct tm *utc)
Calculate the number of seconds east of UTC.
Definition: date.c:130
struct tm mutt_date_gmtime(time_t t)
Converts calendar time to a broken-down time structure expressed in UTC timezone.
Definition: date.c:900
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_make_date()

void mutt_date_make_date ( struct Buffer buf,
bool  local 
)

Write a date in RFC822 format to a buffer.

Parameters
bufBuffer for result
localIf true, use the local timezone. Otherwise use UTC.

Appends the date to the passed in buffer. The buffer is not cleared because some callers prepend quotes.

Definition at line 387 of file date.c.

388{
389 if (!buf)
390 return;
391
392 struct tm tm;
393 int tz = 0;
394
395 time_t t = mutt_date_now();
396 if (local)
397 {
398 tm = mutt_date_localtime(t);
399 tz = mutt_date_local_tz(t);
400 }
401 else
402 {
403 tm = mutt_date_gmtime(t);
404 }
405
406 tz /= 60;
407
408 buf_add_printf(buf, "%s, %d %s %d %02d:%02d:%02d %+03d%02d", Weekdays[tm.tm_wday],
409 tm.tm_mday, Months[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour,
410 tm.tm_min, tm.tm_sec, tz / 60, abs(tz) % 60);
411}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:216
static const char *const Weekdays[]
Day of the week (abbreviated)
Definition: date.c:50
int mutt_date_local_tz(time_t t)
Calculate the local timezone in seconds east of UTC.
Definition: date.c:209
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_make_imap()

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.

Parameters
bufBuffer to store the results
buflenLength of buffer
timestampTime to format
Return values
numCharacters written to buf

Caller should provide a buffer of at least 27 bytes.

Definition at line 784 of file date.c.

785{
786 if (!buf)
787 return -1;
788
789 struct tm tm = mutt_date_localtime(timestamp);
791
792 tz /= 60;
793
794 return snprintf(buf, buflen, "%02d-%s-%d %02d:%02d:%02d %+03d%02d",
795 tm.tm_mday, Months[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour,
796 tm.tm_min, tm.tm_sec, tz / 60, abs(tz) % 60);
797}
static const char * timestamp(time_t stamp)
Create a YYYY-MM-DD HH:MM:SS timestamp.
Definition: logging.c:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_make_time()

time_t mutt_date_make_time ( struct tm *  t,
bool  local 
)

Convert struct tm to time_t

Parameters
tTime to convert
localShould the local timezone be considered
Return values
numTime in Unix format
TIME_T_MINError

Convert a struct tm to time_t, but don't take the local timezone into account unless "local" is nonzero

Definition at line 232 of file date.c.

233{
234 if (!t)
235 return TIME_T_MIN;
236
237 static const int AccumDaysPerMonth[mutt_array_size(Months)] = {
238 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
239 };
240
241 /* Prevent an integer overflow, with some arbitrary limits. */
242 if (t->tm_year > 10000)
243 return TIME_T_MAX;
244 if (t->tm_year < -10000)
245 return TIME_T_MIN;
246
247 if ((t->tm_mday < 1) || (t->tm_mday > 31))
248 return TIME_T_MIN;
249 if ((t->tm_hour < 0) || (t->tm_hour > 23) || (t->tm_min < 0) ||
250 (t->tm_min > 59) || (t->tm_sec < 0) || (t->tm_sec > 60))
251 {
252 return TIME_T_MIN;
253 }
254 if (t->tm_year > 9999)
255 return TIME_T_MAX;
256
257 /* Compute the number of days since January 1 in the same year */
258 int yday = AccumDaysPerMonth[t->tm_mon % mutt_array_size(Months)];
259
260 /* The leap years are 1972 and every 4. year until 2096,
261 * but this algorithm will fail after year 2099 */
262 yday += t->tm_mday;
263 if ((t->tm_year % 4) || (t->tm_mon < 2))
264 yday--;
265 t->tm_yday = yday;
266
267 time_t g = yday;
268
269 /* Compute the number of days since January 1, 1970 */
270 g += (t->tm_year - 70) * (time_t) 365;
271 g += (t->tm_year - 69) / 4;
272
273 /* Compute the number of hours */
274 g *= 24;
275 g += t->tm_hour;
276
277 /* Compute the number of minutes */
278 g *= 60;
279 g += t->tm_min;
280
281 /* Compute the number of seconds */
282 g *= 60;
283 g += t->tm_sec;
284
285 if (local)
286 g -= compute_tz(g, t);
287
288 return g;
289}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_make_tls()

int mutt_date_make_tls ( char *  buf,
size_t  buflen,
time_t  timestamp 
)

Format date in TLS certificate verification style.

Parameters
bufBuffer to store the results
buflenLength of buffer
timestampTime to format
Return values
numCharacters written to buf

e.g., Mar 17 16:40:46 2016 UTC. The time is always in UTC.

Caller should provide a buffer of at least 27 bytes.

Definition at line 810 of file date.c.

811{
812 if (!buf)
813 return -1;
814
815 struct tm tm = mutt_date_gmtime(timestamp);
816 return snprintf(buf, buflen, "%s, %d %s %d %02d:%02d:%02d UTC",
817 Weekdays[tm.tm_wday], tm.tm_mday, Months[tm.tm_mon],
818 tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
819}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_normalize_time()

void mutt_date_normalize_time ( struct tm *  tm)

Fix the contents of a struct tm.

Parameters
tmTime to correct

If values have been added/subtracted from a struct tm, it can lead to invalid dates, e.g. Adding 10 days to the 25th of a month.

This function will correct any over/under-flow.

Definition at line 300 of file date.c.

301{
302 if (!tm)
303 return;
304
305 static const char DaysPerMonth[mutt_array_size(Months)] = {
306 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
307 };
308 int leap;
309
310 while (tm->tm_sec < 0)
311 {
312 tm->tm_sec += 60;
313 tm->tm_min--;
314 }
315 while (tm->tm_sec >= 60)
316 {
317 tm->tm_sec -= 60;
318 tm->tm_min++;
319 }
320 while (tm->tm_min < 0)
321 {
322 tm->tm_min += 60;
323 tm->tm_hour--;
324 }
325 while (tm->tm_min >= 60)
326 {
327 tm->tm_min -= 60;
328 tm->tm_hour++;
329 }
330 while (tm->tm_hour < 0)
331 {
332 tm->tm_hour += 24;
333 tm->tm_mday--;
334 }
335 while (tm->tm_hour >= 24)
336 {
337 tm->tm_hour -= 24;
338 tm->tm_mday++;
339 }
340 /* use loops on NNNdwmy user input values? */
341 while (tm->tm_mon < 0)
342 {
343 tm->tm_mon += 12;
344 tm->tm_year--;
345 }
346 while (tm->tm_mon >= 12)
347 {
348 tm->tm_mon -= 12;
349 tm->tm_year++;
350 }
351 while (tm->tm_mday <= 0)
352 {
353 if (tm->tm_mon)
354 {
355 tm->tm_mon--;
356 }
357 else
358 {
359 tm->tm_mon = 11;
360 tm->tm_year--;
361 }
362 tm->tm_mday += DaysPerMonth[tm->tm_mon] + is_leap_year_feb(tm);
363 }
364 while (tm->tm_mday > (DaysPerMonth[tm->tm_mon] + (leap = is_leap_year_feb(tm))))
365 {
366 tm->tm_mday -= DaysPerMonth[tm->tm_mon] + leap;
367 if (tm->tm_mon < 11)
368 {
369 tm->tm_mon++;
370 }
371 else
372 {
373 tm->tm_mon = 0;
374 tm->tm_year++;
375 }
376 }
377}
static int is_leap_year_feb(struct tm *tm)
Is a given February in a leap year.
Definition: date.c:192
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_parse_date()

time_t mutt_date_parse_date ( const char *  s,
struct Tz tz_out 
)

Parse a date string in RFC822 format.

Parameters
[in]sString to parse
[out]tz_outPointer to timezone (optional)
Return values
numUnix time in seconds

Parse a date of the form: [ weekday , ] day-of-month month year hour:minute:second [ timezone ]

The 'timezone' field is optional; it defaults to +0000 if missing.

Definition at line 686 of file date.c.

687{
688 if (!s)
689 return -1;
690
691 const time_t strict_t = mutt_date_parse_rfc5322_strict(s, tz_out);
692 if (strict_t != -1)
693 return strict_t;
694
695 const regmatch_t *match = mutt_prex_capture(PREX_RFC5322_DATE_LAX, s);
696 if (!match)
697 {
698 mutt_debug(LL_DEBUG1, "Could not parse date: <%s>\n", s);
699 return -1;
700 }
701 mutt_debug(LL_DEBUG2, "Fallback regex for date: <%s>\n", s);
702
703 struct tm tm = { 0 };
704
705 // clang-format off
706 const regmatch_t *mday = &match[PREX_RFC5322_DATE_LAX_MATCH_DAY];
707 const regmatch_t *mmonth = &match[PREX_RFC5322_DATE_LAX_MATCH_MONTH];
708 const regmatch_t *myear = &match[PREX_RFC5322_DATE_LAX_MATCH_YEAR];
709 const regmatch_t *mhour = &match[PREX_RFC5322_DATE_LAX_MATCH_HOUR];
710 const regmatch_t *mminute = &match[PREX_RFC5322_DATE_LAX_MATCH_MINUTE];
711 const regmatch_t *msecond = &match[PREX_RFC5322_DATE_LAX_MATCH_SECOND];
712 const regmatch_t *mtz = &match[PREX_RFC5322_DATE_LAX_MATCH_TZ];
713 const regmatch_t *mtzobs = &match[PREX_RFC5322_DATE_LAX_MATCH_TZ_OBS];
714 // clang-format on
715
716 /* Day */
717 sscanf(s + mutt_regmatch_start(mday), "%d", &tm.tm_mday);
718 if (tm.tm_mday > 31)
719 return -1;
720
721 /* Month */
722 tm.tm_mon = mutt_date_check_month(s + mutt_regmatch_start(mmonth));
723
724 /* Year */
725 sscanf(s + mutt_regmatch_start(myear), "%d", &tm.tm_year);
726 if (tm.tm_year < 50)
727 tm.tm_year += 100;
728 else if (tm.tm_year >= 1900)
729 tm.tm_year -= 1900;
730
731 /* Time */
732 int hour, min, sec = 0;
733 sscanf(s + mutt_regmatch_start(mhour), "%d", &hour);
734 sscanf(s + mutt_regmatch_start(mminute), "%d", &min);
735 if (mutt_regmatch_start(msecond) != -1)
736 sscanf(s + mutt_regmatch_start(msecond), "%d", &sec);
737 if ((hour > 23) || (min > 59) || (sec > 60))
738 return -1;
739 tm.tm_hour = hour;
740 tm.tm_min = min;
741 tm.tm_sec = sec;
742
743 /* Time zone */
744 int zhours = 0;
745 int zminutes = 0;
746 bool zoccident = false;
747 if (mutt_regmatch_start(mtz) != -1)
748 {
749 char direction;
750 sscanf(s + mutt_regmatch_start(mtz), "%c%02d%02d", &direction, &zhours, &zminutes);
751 zoccident = (direction == '-');
752 }
753 else if (mutt_regmatch_start(mtzobs) != -1)
754 {
755 const struct Tz *tz = find_tz(s + mutt_regmatch_start(mtzobs),
756 mutt_regmatch_len(mtzobs));
757 if (tz)
758 {
759 zhours = tz->zhours;
760 zminutes = tz->zminutes;
761 zoccident = tz->zoccident;
762 }
763 }
764
765 if (tz_out)
766 {
767 tz_out->zhours = zhours;
768 tz_out->zminutes = zminutes;
769 tz_out->zoccident = zoccident;
770 }
771
773}
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:232
int mutt_date_check_month(const char *s)
Is the string a valid month name.
Definition: date.c:422
static const struct Tz * find_tz(const char *s, size_t len)
Look up a timezone.
Definition: date.c:177
static time_t mutt_date_parse_rfc5322_strict(const char *s, struct Tz *tz_out)
Parse a date string in RFC822 format.
Definition: date.c:507
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.
Definition: date.c:162
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
Definition: prex.c:289
@ PREX_RFC5322_DATE_LAX
[Mon, (Comment) 16 Mar 2020 15:09:35 -0700]
Definition: prex.h:37
@ PREX_RFC5322_DATE_LAX_MATCH_SECOND
Tue, 3 Mar 2020 14:32:[55] +0200
Definition: prex.h:145
@ PREX_RFC5322_DATE_LAX_MATCH_TZ
Tue, 3 Mar 2020 14:32:55 [+0200]
Definition: prex.h:148
@ PREX_RFC5322_DATE_LAX_MATCH_YEAR
Tue, 3 Mar [2020] 14:32:55 +0200
Definition: prex.h:137
@ PREX_RFC5322_DATE_LAX_MATCH_HOUR
Tue, 3 Mar 2020 [14]:32:55 +0200
Definition: prex.h:139
@ PREX_RFC5322_DATE_LAX_MATCH_MINUTE
Tue, 3 Mar 2020 14:[32]:55 +0200
Definition: prex.h:141
@ PREX_RFC5322_DATE_LAX_MATCH_TZ_OBS
Tue, 3 Mar 2020 14:32:55[UT]
Definition: prex.h:149
@ PREX_RFC5322_DATE_LAX_MATCH_MONTH
Tue, 3 [Jan] 2020 14:32:55 +0200
Definition: prex.h:135
@ PREX_RFC5322_DATE_LAX_MATCH_DAY
Tue, [3] Mar 2020 14:32:55 +0200
Definition: prex.h:133
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
Definition: regex3.h:80
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:60
List of recognised Timezones.
Definition: date.h:43
unsigned char zminutes
Minutes away from UTC.
Definition: date.h:46
bool zoccident
True if west of UTC, False if East.
Definition: date.h:47
unsigned char zhours
Hours away from UTC.
Definition: date.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_parse_imap()

time_t mutt_date_parse_imap ( const char *  s)

Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz.

Parameters
sDate in string form
Return values
numUnix time
0Error

Definition at line 827 of file date.c.

828{
829 const regmatch_t *match = mutt_prex_capture(PREX_IMAP_DATE, s);
830 if (!match)
831 return 0;
832
833 const regmatch_t *mday = &match[PREX_IMAP_DATE_MATCH_DAY];
834 const regmatch_t *mmonth = &match[PREX_IMAP_DATE_MATCH_MONTH];
835 const regmatch_t *myear = &match[PREX_IMAP_DATE_MATCH_YEAR];
836 const regmatch_t *mtime = &match[PREX_IMAP_DATE_MATCH_TIME];
837 const regmatch_t *mtz = &match[PREX_IMAP_DATE_MATCH_TZ];
838
839 struct tm tm;
840
841 sscanf(s + mutt_regmatch_start(mday), " %d", &tm.tm_mday);
842 tm.tm_mon = mutt_date_check_month(s + mutt_regmatch_start(mmonth));
843 sscanf(s + mutt_regmatch_start(myear), "%d", &tm.tm_year);
844 tm.tm_year -= 1900;
845 sscanf(s + mutt_regmatch_start(mtime), "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
846
847 char direction;
848 int zhours, zminutes;
849 sscanf(s + mutt_regmatch_start(mtz), "%c%02d%02d", &direction, &zhours, &zminutes);
850 bool zoccident = (direction == '-');
851
852 return add_tz_offset(mutt_date_make_time(&tm, false), zoccident, zhours, zminutes);
853}
@ PREX_IMAP_DATE_MATCH_TIME
15-MAR-2020 [15:09:35] -0700
Definition: prex.h:166
@ PREX_IMAP_DATE_MATCH_YEAR
15-MAR-[2020] 15:09:35 -0700
Definition: prex.h:165
@ PREX_IMAP_DATE_MATCH_DAY
[ 4]-MAR-2020 15:09:35 -0700
Definition: prex.h:161
@ PREX_IMAP_DATE_MATCH_TZ
15-MAR-2020 15:09:35 [-0700]
Definition: prex.h:167
@ PREX_IMAP_DATE_MATCH_MONTH
15-[MAR]-2020 15:09:35 -0700
Definition: prex.h:164
@ PREX_IMAP_DATE
[16-MAR-2020 15:09:35 -0700]
Definition: prex.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_date_sleep_ms()

void mutt_date_sleep_ms ( size_t  ms)

Sleep for milliseconds.

Parameters
msNumber of milliseconds to sleep

Definition at line 937 of file date.c.

938{
939 const struct timespec sleep = {
940 .tv_sec = ms / 1000,
941 .tv_nsec = (ms % 1000) * 1000000UL,
942 };
943 nanosleep(&sleep, NULL);
944}
Time value with nanosecond precision.
Definition: file.h:50
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:51
+ Here is the caller graph for this function: