114 struct tm *tm = gmtime(&t);
116 snprintf(ret,
sizeof ret,
"%s, %02d %s %d %02d:%02d:%02d GMT",
118 months[tm->tm_mon], tm->tm_year + 1900,
119 tm->tm_hour, tm->tm_min, tm->tm_sec);
130 val = (
long long)*timep;
132 return snprintf(str, size,
"%lld", val);
136 ltm = localtime(timep);
141 return strftime(str, size,
"%s", ltm);
159 time_out = (time_t)
strtoll(str, &rstr, 10);
162 if ((errno != 0) || (rstr == str)) {
173 if (strptime(str,
"%s", <m) == NULL) {
177 time_out = mktime(<m);
578 return (flags & mask) == mask;
597 const char *
const *names = (len == 3) ?
713 count = sscanf(str,
"%02d:%02d:%02d", &h, &m, &s);
724 count = sscanf(str,
"%02d:%02d", &h, &m);
772 ctx->
years = value / 10000;
773 ctx->
month = (value % 10000) / 100 - 1;
774 ctx->
day = value % 100 - 1;
786 if (ctx->
prev ==
'+') {
803 value > 0 && value <= 31) {
804 ctx->
day = value - 1;
809 ctx->
years = (value > 70) ?
832 return (year / 4) - (year / 100) + (year / 400);
850 NSC_MONTH_DAYS_JAN = 31,
851 NSC_MONTH_DAYS_FEB = 28,
852 NSC_MONTH_DAYS_MAR = 31,
853 NSC_MONTH_DAYS_APR = 30,
854 NSC_MONTH_DAYS_MAY = 31,
855 NSC_MONTH_DAYS_JUN = 30,
856 NSC_MONTH_DAYS_JUL = 31,
857 NSC_MONTH_DAYS_AUG = 31,
858 NSC_MONTH_DAYS_SEP = 30,
859 NSC_MONTH_DAYS_OCT = 31,
860 NSC_MONTH_DAYS_NOV = 30,
861 NSC_MONTH_DAYS_DEC = 31
864 NSC_MONTH_OFF_JAN = 0,
865 NSC_MONTH_OFF_FEB = NSC_MONTH_OFF_JAN + NSC_MONTH_DAYS_JAN,
866 NSC_MONTH_OFF_MAR = NSC_MONTH_OFF_FEB + NSC_MONTH_DAYS_FEB,
867 NSC_MONTH_OFF_APR = NSC_MONTH_OFF_MAR + NSC_MONTH_DAYS_MAR,
868 NSC_MONTH_OFF_MAY = NSC_MONTH_OFF_APR + NSC_MONTH_DAYS_APR,
869 NSC_MONTH_OFF_JUN = NSC_MONTH_OFF_MAY + NSC_MONTH_DAYS_MAY,
870 NSC_MONTH_OFF_JUL = NSC_MONTH_OFF_JUN + NSC_MONTH_DAYS_JUN,
871 NSC_MONTH_OFF_AUG = NSC_MONTH_OFF_JUL + NSC_MONTH_DAYS_JUL,
872 NSC_MONTH_OFF_SEP = NSC_MONTH_OFF_AUG + NSC_MONTH_DAYS_AUG,
873 NSC_MONTH_OFF_OCT = NSC_MONTH_OFF_SEP + NSC_MONTH_DAYS_SEP,
874 NSC_MONTH_OFF_NOV = NSC_MONTH_OFF_OCT + NSC_MONTH_DAYS_OCT,
875 NSC_MONTH_OFF_DEC = NSC_MONTH_OFF_NOV + NSC_MONTH_DAYS_NOV
891 int year_days = (ctx->
years - 1970) * 365;
892 int month_days = month_offsets[ctx->
month];
896 int total_days = year_days + month_days + ctx->
day + leap_days;
900 *time = (((((time_t)(total_days)) * 24) +
928 .timezone_offset_mins = 0
931 if (str == NULL || time == NULL) {
936 while (*str !=
'\0' &&
992 if (str == NULL || timep == NULL) {
996 result = curl_getdate(str, NULL);
Helpers for ASCII string handling.
static size_t ascii_count_alpha(const char *str)
Count consecutive alphabetical characters in string (upper or lower case).
static size_t ascii_string_to_int(const char *str, int *res)
Parse an int out of a string.
static size_t ascii_count_digit_or_colon(const char *str)
Count consecutive characters either decimal digit or colon in string.
static bool ascii_is_sign(char c)
Test whether a character is a positive/negative numerical sign.
static size_t ascii_count_digit(const char *str)
Count consecutive decial digit characters in string.
static bool ascii_is_alpha(char c)
Test whether a character is alphabetical (upper or lower case).
static bool ascii_is_digit(char c)
Test whether a character is a decimal digit.
static size_t ascii_strings_count_equal_caseless(const char *s1, const char *s2)
Count consecutive equal ascii characters (case insensitive).
static uint32_t count(const http_directive *list, lwc_string *key)
nserror
Enumeration of error codes.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_INVALID
Invalid data.
long long int strtoll(const char *nptr, char **endptr, int base)
Context for date parsing.
char prev
Used for handling neumenrical timezone.
int16_t timezone_offset_mins
static bool time__parse_hh_mm_ss(const char *str, size_t *len, enum nsc_date_component_flags *flags, struct nsc_date_parse_ctx *ctx)
Attempt to parse an "hh:mm:ss" time from a string.
static bool time__parse_timezone(const char *str, size_t len, enum nsc_date_component_flags *flags, struct nsc_date_parse_ctx *ctx)
Attempt to parse a timezone name in a string (case insensitive).
nsc_date_component_flags
Flags for tracking the components of a date that have been parsed.
@ NSC_COMPONENT_FLAGS_HAVE_HOURS
@ NSC_COMPONENT_FLAGS_HAVE_SECS
@ NSC_COMPONENT_FLAGS_HAVE_MONTHS
@ NSC_COMPONENT_FLAGS__HAVE_HHMMSS
@ NSC_COMPONENT_FLAGS_HAVE_TIMEZONE
@ NSC_COMPONENT_FLAGS_HAVE_DAYS
@ NSC_COMPONENT_FLAGS_HAVE_WEEKDAY
@ NSC_COMPONENT_FLAGS_HAVE_MINS
@ NSC_COMPONENT_FLAGS__HAVE_YYYYMMDD
@ NSC_COMPONENT_FLAGS__HAVE_ALL
@ NSC_COMPONENT_FLAGS_NONE
@ NSC_COMPONENT_FLAGS_HAVE_YEARS
static int time__get_leap_days(int year)
Get number of leap days up until end of given year.
static bool time__parse_weekday(const char *str, size_t len, enum nsc_date_component_flags *flags)
Test for a weekday name in a string (case insensitive).
nsc_time_weekdays
Weekdays.
@ NSC_TIME_WEEKDAY__COUNT
static bool time__parse_number(const char *str, size_t len, enum nsc_date_component_flags *flags, struct nsc_date_parse_ctx *ctx)
Attempt to parse a number from a date string.
int nsc_sntimet(char *str, size_t size, time_t *timep)
Write the time in seconds since epoch to a buffer.
nserror nsc_strntimet(const char *str, size_t size, time_t *timep)
Converts a date string to a number of seconds since epoch.
nserror nsc_snptimet(const char *str, size_t size, time_t *timep)
Parse time in seconds since epoc.
const char * rfc1123_date(time_t t)
Create an RFC 1123 compliant date string from a Unix timestamp.
static bool time__parse_month(const char *str, size_t len, enum nsc_date_component_flags *flags, struct nsc_date_parse_ctx *ctx)
Attempt to parse a month name in a string (case insensitive).
static const char *const weekdays_long[NSC_TIME_WEEKDAY__COUNT]
Array of long weekday names.
static const char *const timezones[NSC_TIME_ZONE__COUNT]
Array of timezone names.
static bool flags_chk_all(enum nsc_date_component_flags flags, enum nsc_date_component_flags mask)
Helper for testing whether all of the flags in mask are set.
static const char *const weekdays_short[NSC_TIME_WEEKDAY__COUNT]
Array of short weekday names.
static bool flags_chk(enum nsc_date_component_flags flags, enum nsc_date_component_flags mask)
Helper for testing whether any of the flags in mask are set.
static nserror time__get_date(const char *str, time_t *time)
Parse a date string to a time_t.
nsc_time_zones
List of timezones.
@ NSC_TIME_ZONE_GMT
"GMT" first since its the only one I've seen in the wild.
static const char *const months[NSC_TIME_MONTH__COUNT]
Array of month names.
nsc_time_zone_offsets
Timezone offsets in mins.
@ NSC_TIME_ZONE_OFFSET_HDT
@ NSC_TIME_ZONE_OFFSET_ADT
@ NSC_TIME_ZONE_OFFSET_MEST
@ NSC_TIME_ZONE_OFFSET_EADT
@ NSC_TIME_ZONE_OFFSET_AST
@ NSC_TIME_ZONE_OFFSET_AHST
@ NSC_TIME_ZONE_OFFSET_WAT
@ NSC_TIME_ZONE_OFFSET_PST
@ NSC_TIME_ZONE_OFFSET_GMT
@ NSC_TIME_ZONE_OFFSET_YST
@ NSC_TIME_ZONE_OFFSET_MEWT
@ NSC_TIME_ZONE_OFFSET_EST
@ NSC_TIME_ZONE_OFFSET_PDT
@ NSC_TIME_ZONE_OFFSET_WET
@ NSC_TIME_ZONE_OFFSET_WADT
@ NSC_TIME_ZONE_OFFSET_NZT
@ NSC_TIME_ZONE_OFFSET_EDT
@ NSC_TIME_ZONE_OFFSET_GST
@ NSC_TIME_ZONE_OFFSET_MET
@ NSC_TIME_ZONE_OFFSET_CET
@ NSC_TIME_ZONE_OFFSET_MESZ
@ NSC_TIME_ZONE_OFFSET_WAST
@ NSC_TIME_ZONE_OFFSET_YDT
@ NSC_TIME_ZONE_OFFSET_EAST
@ NSC_TIME_ZONE_OFFSET_IDLE
@ NSC_TIME_ZONE_OFFSET_MST
@ NSC_TIME_ZONE_OFFSET_NZST
@ NSC_TIME_ZONE_OFFSET_CCT
@ NSC_TIME_ZONE_OFFSET_UTC
@ NSC_TIME_ZONE_OFFSET_IDLW
@ NSC_TIME_ZONE_OFFSET_JST
@ NSC_TIME_ZONE_OFFSET_NZDT
@ NSC_TIME_ZONE_OFFSET_EET
@ NSC_TIME_ZONE_OFFSET_HST
@ NSC_TIME_ZONE_OFFSET_MDT
@ NSC_TIME_ZONE_OFFSET_CAT
@ NSC_TIME_ZONE_OFFSET_CST
@ NSC_TIME_ZONE_OFFSET_CEST
@ NSC_TIME_ZONE_OFFSET_BST
@ NSC_TIME_ZONE_OFFSET_FWT
@ NSC_TIME_ZONE_OFFSET_FST
@ NSC_TIME_ZONE_OFFSET_CDT
static const int16_t timezone_mins[NSC_TIME_ZONE__COUNT]
Array of minute offsets for timezones.
static nserror time__ctx_to_time_t(const struct nsc_date_parse_ctx *ctx, enum nsc_date_component_flags flags, time_t *time)
Helper to convert a date string context to a time_t.
Interface to time operations.