1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_getdate 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_TIMECONDITION (3) 9 - CURLOPT_TIMEVALUE (3) 10 - curl_easy_escape (3) 11 - curl_easy_unescape (3) 12Protocol: 13 - All 14--- 15 16# NAME 17 18curl_getdate - Convert a date string to number of seconds 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25time_t curl_getdate(const char *datestring, const time_t *now); 26~~~ 27 28# DESCRIPTION 29 30curl_getdate(3) returns the number of seconds since the Epoch, January 311st 1970 00:00:00 in the UTC time zone, for the date and time that the 32*datestring* parameter specifies. The *now* parameter is not used, 33pass a NULL there. 34 35This function works with valid dates and does not always detect and reject 36wrong dates, such as February 30. 37 38# PARSING DATES AND TIMES 39 40A "date" is a string containing several items separated by whitespace. The 41order of the items is immaterial. A date string may contain many flavors of 42items: 43 44## calendar date items 45 46Can be specified several ways. Month names can only be three-letter English 47abbreviations, numbers can be zero-prefixed and the year may use 2 or 4 48digits. Examples: 06 Nov 1994, 06-Nov-94 and Nov-94 6. 49 50## time of the day items 51 52This string specifies the time on a given day. You must specify it with 6 53digits with two colons: HH:MM:SS. If there is no time given in a provided date 54string, 00:00:00 is assumed. Example: 18:19:21. 55 56## time zone items 57 58Specifies international time zone. There are a few acronyms supported, but in 59general you should instead use the specific relative time compared to 60UTC. Supported formats include: -1200, MST, +0100. 61 62## day of the week items 63 64Specifies a day of the week. Days of the week may be spelled out in full 65(using English): `Sunday', `Monday', etc or they may be abbreviated to their 66first three letters. This is usually not info that adds anything. 67 68## pure numbers 69 70If a decimal number of the form YYYYMMDD appears, then YYYY is read as the 71year, MM as the month number and DD as the day of the month, for the specified 72calendar date. 73 74# EXAMPLE 75 76~~~c 77int main(void) 78{ 79 time_t t; 80 t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL); 81 t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL); 82 t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL); 83 t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL); 84 t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL); 85 t = curl_getdate("Nov 6 08:49:37 1994", NULL); 86 t = curl_getdate("06 Nov 1994 08:49:37", NULL); 87 t = curl_getdate("06-Nov-94 08:49:37", NULL); 88 t = curl_getdate("1994 Nov 6 08:49:37", NULL); 89 t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL); 90 t = curl_getdate("94 6 Nov 08:49:37", NULL); 91 t = curl_getdate("1994 Nov 6", NULL); 92 t = curl_getdate("06-Nov-94", NULL); 93 t = curl_getdate("Sun Nov 6 94", NULL); 94 t = curl_getdate("1994.Nov.6", NULL); 95 t = curl_getdate("Sun/Nov/6/94/GMT", NULL); 96 t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL); 97 t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL); 98 t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL); 99 t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL); 100 t = curl_getdate("20040912 15:05:58 -0700", NULL); 101 t = curl_getdate("20040911 +0200", NULL); 102} 103~~~ 104 105# STANDARDS 106 107This parser handles date formats specified in RFC 822 (including the update in 108RFC 1123) using time zone name or time zone delta and RFC 850 (obsoleted by 109RFC 1036) and ANSI C's *asctime()* format. 110 111These formats are the only ones RFC 7231 says HTTP applications may use. 112 113# AVAILABILITY 114 115Always 116 117# RETURN VALUE 118 119This function returns -1 when it fails to parse the date string. Otherwise it 120returns the number of seconds as described. 121 122On systems with a signed 32 bit time_t: if the year is larger than 2037 or 123less than 1903, this function returns -1. 124 125On systems with an unsigned 32 bit time_t: if the year is larger than 2106 or 126less than 1970, this function returns -1. 127 128On systems with 64 bit time_t: if the year is less than 1583, this function 129returns -1. (The Gregorian calendar was first introduced 1582 so no "real" 130dates in this way of doing dates existed before then.) 131