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