Time and date handling routines. More...
#include <locale.h>#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. | |
| int | mutt_date_check_month (const char *s) |
| Is the string a valid month name. | |
| time_t | mutt_date_now (void) |
| Return the number of seconds since the Unix epoch. | |
| uint64_t | mutt_date_now_ms (void) |
| Return the number of milliseconds since the Unix epoch. | |
| struct tm | mutt_date_gmtime (time_t t) |
| Converts calendar time to a broken-down time structure expressed in UTC timezone. | |
| size_t | mutt_date_localtime_format (char *buf, size_t buflen, const char *format, time_t t) |
| Format localtime. | |
| size_t | mutt_date_localtime_format_locale (char *buf, size_t buflen, const char *format, time_t t, locale_t loc) |
| Format localtime using a given locale. | |
| struct tm | mutt_date_localtime (time_t t) |
| Converts calendar time to a broken-down time structure expressed in user timezone. | |
| int | mutt_date_local_tz (time_t t) |
| Calculate the local timezone in seconds east of UTC. | |
| void | mutt_date_make_date (struct Buffer *buf, bool local) |
| Write a date in RFC822 format to a buffer. | |
| int | mutt_date_make_imap (struct Buffer *buf, time_t timestamp) |
| Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz. | |
| time_t | mutt_date_make_time (struct tm *t, bool local) |
Convert struct tm to time_t | |
| int | mutt_date_make_tls (char *buf, size_t buflen, time_t timestamp) |
| Format date in TLS certificate verification style. | |
| void | mutt_date_normalize_time (struct tm *tm) |
| Fix the contents of a struct tm. | |
| time_t | mutt_date_parse_date (const char *s, struct Tz *tz_out) |
| Parse a date string in RFC822 format. | |
| time_t | mutt_date_parse_imap (const char *s) |
| Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz. | |
| void | mutt_date_sleep_ms (size_t ms) |
| Sleep for milliseconds. | |
| void | mutt_time_now (struct timespec *tp) |
| Set the provided time field to the current time. | |
Time and date handling routines.
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.
| #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) |
| time_t mutt_date_add_timeout | ( | time_t | now, |
| time_t | timeout ) |
Safely add a timeout to a given time_t value.
| now | Time now |
| timeout | Timeout in seconds |
| num | Unix time to timeout |
This will truncate instead of overflowing.
Definition at line 890 of file date.c.
Here is the caller graph for this function:| int mutt_date_check_month | ( | const char * | s | ) |
Is the string a valid month name.
| s | String to check (must be at least 3 bytes long) |
| num | Index into Months array (0-based) |
| -1 | Error |
Definition at line 432 of file date.c.
Here is the caller graph for this function:| time_t mutt_date_now | ( | void | ) |
Return the number of seconds since the Unix epoch.
| num | Number of seconds since the Unix epoch, or 0 on failure |
Definition at line 456 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| uint64_t mutt_date_now_ms | ( | void | ) |
Return the number of milliseconds since the Unix epoch.
| num | The number of ms since the Unix epoch, or 0 on failure |
Definition at line 465 of file date.c.
Here is the caller graph for this function:| struct tm mutt_date_gmtime | ( | time_t | t | ) |
Converts calendar time to a broken-down time structure expressed in UTC timezone.
| t | Time |
| obj | Broken-down time representation |
Definition at line 927 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| size_t mutt_date_localtime_format | ( | char * | buf, |
| size_t | buflen, | ||
| const char * | format, | ||
| time_t | t ) |
Format localtime.
| buf | Buffer to store formatted time |
| buflen | Buffer size |
| format | Format to apply |
| t | Time to format |
| num | Number of Bytes added to buffer, excluding NUL byte |
Definition at line 951 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| size_t mutt_date_localtime_format_locale | ( | char * | buf, |
| size_t | buflen, | ||
| const char * | format, | ||
| time_t | t, | ||
| locale_t | loc ) |
Format localtime using a given locale.
| buf | Buffer to store formatted time |
| buflen | Buffer size |
| format | Format to apply |
| t | Time to format |
| loc | Locale to use |
| num | Number of Bytes added to buffer, excluding NUL byte |
Definition at line 969 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| struct tm mutt_date_localtime | ( | time_t | t | ) |
Converts calendar time to a broken-down time structure expressed in user timezone.
| t | Time |
| obj | Broken-down time representation |
Definition at line 906 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int mutt_date_local_tz | ( | time_t | t | ) |
Calculate the local timezone in seconds east of UTC.
| t | Time to examine |
| num | Seconds 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 219 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_date_make_date | ( | struct Buffer * | buf, |
| bool | local ) |
Write a date in RFC822 format to a buffer.
| buf | Buffer for result |
| local | If 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 397 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int mutt_date_make_imap | ( | struct Buffer * | buf, |
| time_t | timestamp ) |
Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz.
| buf | Buffer to store the results |
| timestamp | Time to format |
| num | Characters written to buf |
Definition at line 811 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| time_t mutt_date_make_time | ( | struct tm * | t, |
| bool | local ) |
Convert struct tm to time_t
| t | Time to convert |
| local | Should the local timezone be considered |
| num | Time in Unix format |
| TIME_T_MIN | Error |
Convert a struct tm to time_t, but don't take the local timezone into account unless "local" is nonzero
Definition at line 242 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int mutt_date_make_tls | ( | char * | buf, |
| size_t | buflen, | ||
| time_t | timestamp ) |
Format date in TLS certificate verification style.
| buf | Buffer to store the results |
| buflen | Length of buffer |
| timestamp | Time to format |
| num | Characters 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 837 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_date_normalize_time | ( | struct tm * | tm | ) |
Fix the contents of a struct tm.
| tm | Time 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 310 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| time_t mutt_date_parse_date | ( | const char * | s, |
| struct Tz * | tz_out ) |
Parse a date string in RFC822 format.
| [in] | s | String to parse |
| [out] | tz_out | Pointer to timezone (optional) |
| num | Unix time in seconds, or -1 on failure |
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 716 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| time_t mutt_date_parse_imap | ( | const char * | s | ) |
Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz.
| s | Date in string form |
| num | Unix time |
| 0 | Error |
Definition at line 854 of file date.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_date_sleep_ms | ( | size_t | ms | ) |
| void mutt_time_now | ( | struct timespec * | tp | ) |
Set the provided time field to the current time.
| [out] | tp | Field to set |
Uses nanosecond precision if available, if not we fallback to microseconds.
Definition at line 480 of file date.c.
Here is the caller graph for this function: