1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at https://curl.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24#include "test.h" 25 26#include "memdebug.h" 27 28struct dcheck { 29 const char *input; 30 time_t output; 31}; 32 33static const struct dcheck dates[] = { 34 {"Sun, 06 Nov 1994 08:49:37 GMT", 784111777 }, 35 {"Sunday, 06-Nov-94 08:49:37 GMT", 784111777 }, 36 {"Sun Nov 6 08:49:37 1994", 784111777 }, 37 {"Sun Nov 6 8:49:37 1994", 784111777 }, 38 {"Sun Nov 6 8:9:37 1994", 784109377 }, 39 {"Sun Nov 6 008:09:37 1994", -1 }, 40 {"Nov Sun 6 8:9:7 1994", 784109347 }, 41 {"06 Nov 1994 08:49:37 GMT", 784111777 }, 42 {"06-Nov-94 08:49:37 GMT", 784111777 }, 43 {"Nov 6 08:49:37 1994", 784111777 }, 44 {"06 Nov 1994 08:49:37", 784111777 }, 45 {"06-Nov-94 08:49:37", 784111777 }, 46 {"1994 Nov 6 08:49:37", 784111777 }, 47 {"GMT 08:49:37 06-Nov-94 Sunday", 784111777 }, 48 {"94 6 Nov 08:49:37", 784111777 }, 49 {"1994 Nov 6", 784080000 }, 50 {"06-Nov-94", 784080000 }, 51 {"Sun Nov 6 94", 784080000 }, 52 {"1994.Nov.6", 784080000 }, 53 {"Sun/Nov/6/94/GMT", 784080000 }, 54 {"Sun, 06 Nov 1994 08:49:37 CET", 784108177 }, 55 {"06 Nov 1994 08:49:37 EST", 784129777 }, 56 {"Sun, 06 Nov 1994 08:49:37 UT", 784111777 }, 57 {"Sun, 12 Sep 2004 15:05:58 -0700", 1095026758 }, 58 {"Sat, 11 Sep 2004 21:32:11 +0200", 1094931131 }, 59 {"20040912 15:05:58 -0700", 1095026758 }, 60 {"20040911 +0200", 1094853600 }, 61 {"Thu, 01-Jan-1970 00:59:59 GMT", 3599 }, 62 {"Thu, 01-Jan-1970 01:00:00 GMT", 3600 }, 63 {"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 }, 64 {"Thu, 19-Apr-2007 16:00:00 GMT", 1176998400 }, 65 {"Wed, 25 Apr 2007 21:02:13 GMT", 1177534933 }, 66 {"Thu, 19/Apr\\2007 16:00:00 GMT", 1176998400 }, 67 {"Fri, 1 Jan 2010 01:01:50 GMT", 1262307710 }, 68 {"Wednesday, 1-Jan-2003 00:00:00 GMT", 1041379200 }, 69 {", 1-Jan-2003 00:00:00 GMT", 1041379200 }, 70 {"1-Jan-2003 00:00:00 GMT", 1041379200 }, 71 {"1-Jan-2003 00:00:00 GMT", 1041379200 }, 72 {"Wed,18-Apr-07 22:50:12 GMT", 1176936612 }, 73 {"WillyWonka , 18-Apr-07 22:50:12 GMT", -1 }, 74 {"WillyWonka , 18-Apr-07 22:50:12", -1 }, 75 {"WillyWonka , 18-apr-07 22:50:12", -1 }, 76 {"Mon, 18-Apr-1977 22:50:13 GMT", 230251813 }, 77 {"Mon, 18-Apr-77 22:50:13 GMT", 230251813 }, 78 {"Sat, 15-Apr-17\"21:01:22\"GMT", 1492290082 }, 79 {"Partyday, 18- April-07 22:50:12", -1 }, 80 {"Partyday, 18 - Apri-07 22:50:12", -1 }, 81 {"Wednes, 1-Januar-2003 00:00:00 GMT", -1 }, 82 {"Sat, 15-Apr-17 21:01:22", 1492290082 }, 83 {"Sat, 15-Apr-17 21:01:22 GMT-2", 1492290082 }, 84 {"Sat, 15-Apr-17 21:01:22 GMT BLAH", 1492290082 }, 85 {"Sat, 15-Apr-17 21:01:22 GMT-0400", 1492290082 }, 86 {"Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT)", 1492290082 }, 87 {"Sat, 15-Apr-17 21:01:22 DST", -1 }, 88 {"Sat, 15-Apr-17 21:01:22 -0400", 1492304482 }, 89 {"Sat, 15-Apr-17 21:01:22 (hello there)", -1 }, 90 {"Sat, 15-Apr-17 21:01:22 11:22:33", -1 }, 91 {"Sat, 15-Apr-17 ::00 21:01:22", -1 }, 92 {"Sat, 15-Apr-17 boink:z 21:01:22", -1 }, 93 {"Sat, 15-Apr-17 91:22:33 21:01:22", -1 }, 94 {"Thu Apr 18 22:50:12 2007 GMT", 1176936612 }, 95 {"22:50:12 Thu Apr 18 2007 GMT", 1176936612 }, 96 {"Thu 22:50:12 Apr 18 2007 GMT", 1176936612 }, 97 {"Thu Apr 22:50:12 18 2007 GMT", 1176936612 }, 98 {"Thu Apr 18 22:50:12 2007 GMT", 1176936612 }, 99 {"Thu Apr 18 2007 22:50:12 GMT", 1176936612 }, 100 {"Thu Apr 18 2007 GMT 22:50:12", 1176936612 }, 101 {"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 }, 102 {"15-Sat, Apr-17 21:01:22 GMT", 1492290082 }, 103 {"15-Sat, Apr 21:01:22 GMT 17", 1492290082 }, 104 {"15-Sat, Apr 21:01:22 GMT 2017", 1492290082 }, 105 {"15 Apr 21:01:22 2017", 1492290082 }, 106 {"15 17 Apr 21:01:22", 1492290082 }, 107 {"Apr 15 17 21:01:22", 1492290082 }, 108 {"Apr 15 21:01:22 17", 1492290082 }, 109 {"2017 April 15 21:01:22", -1 }, 110 {"15 April 2017 21:01:22", -1 }, 111 {"98 April 17 21:01:22", -1 }, 112 {"Thu, 012-Aug-2008 20:49:07 GMT", 1218574147 }, 113 {"Thu, 999999999999-Aug-2007 20:49:07 GMT", -1 }, 114 {"Thu, 12-Aug-2007 20:61:99999999999 GMT", -1 }, 115 {"IAintNoDateFool", -1 }, 116 {"Thu Apr 18 22:50 2007 GMT", 1176936600 }, 117 {"20110623 12:34:56", 1308832496 }, 118 {"20110632 12:34:56", -1 }, 119 {"20110623 56:34:56", -1 }, 120 {"20111323 12:34:56", -1 }, 121 {"20110623 12:34:79", -1 }, 122 {"Wed, 31 Dec 2008 23:59:60 GMT", 1230768000 }, 123 {"Wed, 31 Dec 2008 23:59:61 GMT", -1 }, 124 {"Wed, 31 Dec 2008 24:00:00 GMT", -1 }, 125 {"Wed, 31 Dec 2008 23:60:59 GMT", -1 }, 126 {"20110623 12:3", 1308830580 }, 127 {"20110623 1:3", 1308790980 }, 128 {"20110623 1:30", 1308792600 }, 129 {"20110623 12:12:3", 1308831123 }, 130 {"20110623 01:12:3", 1308791523 }, 131 {"20110623 01:99:30", -1 }, 132 {"Thu, 01-Jan-1970 00:00:00 GMT", 0 }, 133 {"Thu, 31-Dec-1969 23:59:58 GMT", -2 }, 134 {"Thu, 31-Dec-1969 23:59:59 GMT", 0 }, /* avoids -1 ! */ 135#if SIZEOF_TIME_T > 4 136 {"Sun, 06 Nov 2044 08:49:37 GMT", (time_t) CURL_OFF_TU_C(2362034977) }, 137 {"Sun, 06 Nov 3144 08:49:37 GMT", 37074617377 }, 138#ifndef HAVE_TIME_T_UNSIGNED 139#if 0 140 /* causes warning on MSVC */ 141 {"Sun, 06 Nov 1900 08:49:37 GMT", -2182259423 }, 142#endif 143 {"Sun, 06 Nov 1800 08:49:37 GMT", -5337933023 }, 144 {"Thu, 01-Jan-1583 00:00:00 GMT", -12212553600 }, 145#endif 146 {"Thu, 01-Jan-1499 00:00:00 GMT", -1 }, 147#else 148 {"Sun, 06 Nov 2044 08:49:37 GMT", -1 }, 149#endif 150#ifndef HAVE_TIME_T_UNSIGNED 151 {"Sun, 06 Nov 1968 08:49:37 GMT", -36342623 }, 152#endif 153 { NULL, 0 } 154}; 155 156int test(char *URL) 157{ 158 int i; 159 int error = 0; 160 161 (void)URL; /* not used */ 162 163 for(i = 0; dates[i].input; i++) { 164 time_t out = curl_getdate(dates[i].input, NULL); 165 if(out != dates[i].output) { 166 printf("WRONGLY %s => %ld (instead of %ld)\n", 167 dates[i].input, (long)out, (long)dates[i].output); 168 error++; 169 } 170 } 171 172 return error; 173} 174