2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
10 * This is like mktime, but without normalization of tm_wday and tm_yday.
12 static time_t tm_to_time_t(const struct tm
*tm
)
14 static const int mdays
[] = {
15 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
17 int year
= tm
->tm_year
- 70;
18 int month
= tm
->tm_mon
;
19 int day
= tm
->tm_mday
;
21 if (year
< 0 || year
> 129) /* algo only works for 1970-2099 */
23 if (month
< 0 || month
> 11) /* array bounds */
25 if (month
< 2 || (year
+ 2) % 4)
27 if (tm
->tm_hour
< 0 || tm
->tm_min
< 0 || tm
->tm_sec
< 0)
29 return (year
* 365 + (year
+ 1) / 4 + mdays
[month
] + day
) * 24*60*60UL +
30 tm
->tm_hour
* 60*60 + tm
->tm_min
* 60 + tm
->tm_sec
;
33 static const char *month_names
[] = {
34 "January", "February", "March", "April", "May", "June",
35 "July", "August", "September", "October", "November", "December"
38 static const char *weekday_names
[] = {
39 "Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"
42 static time_t gm_time_t(unsigned long time
, int tz
)
46 minutes
= tz
< 0 ? -tz
: tz
;
47 minutes
= (minutes
/ 100)*60 + (minutes
% 100);
48 minutes
= tz
< 0 ? -minutes
: minutes
;
49 return time
+ minutes
* 60;
53 * The "tz" thing is passed in as this strange "decimal parse of tz"
54 * thing, which means that tz -0100 is passed in as the integer -100,
55 * even though it means "sixty minutes off"
57 static struct tm
*time_to_tm(unsigned long time
, int tz
)
59 time_t t
= gm_time_t(time
, tz
);
64 * What value of "tz" was in effect back then at "time" in the
67 static int local_tzoffset(unsigned long time
)
75 t_local
= tm_to_time_t(&tm
);
84 offset
/= 60; /* in minutes */
85 offset
= (offset
% 60) + ((offset
/ 60) * 100);
86 return offset
* eastwest
;
89 void show_date_relative(unsigned long time
, int tz
,
90 const struct timeval
*now
,
91 struct strbuf
*timebuf
)
94 if (now
->tv_sec
< time
) {
95 strbuf_addstr(timebuf
, _("in the future"));
98 diff
= now
->tv_sec
- time
;
101 Q_("%lu second ago", "%lu seconds ago", diff
), diff
);
104 /* Turn it into minutes */
105 diff
= (diff
+ 30) / 60;
108 Q_("%lu minute ago", "%lu minutes ago", diff
), diff
);
111 /* Turn it into hours */
112 diff
= (diff
+ 30) / 60;
115 Q_("%lu hour ago", "%lu hours ago", diff
), diff
);
118 /* We deal with number of days from here on */
119 diff
= (diff
+ 12) / 24;
122 Q_("%lu day ago", "%lu days ago", diff
), diff
);
125 /* Say weeks for the past 10 weeks or so */
128 Q_("%lu week ago", "%lu weeks ago", (diff
+ 3) / 7),
132 /* Say months for the past 12 months or so */
135 Q_("%lu month ago", "%lu months ago", (diff
+ 15) / 30),
139 /* Give years and months for 5 years or so */
141 unsigned long totalmonths
= (diff
* 12 * 2 + 365) / (365 * 2);
142 unsigned long years
= totalmonths
/ 12;
143 unsigned long months
= totalmonths
% 12;
145 struct strbuf sb
= STRBUF_INIT
;
146 strbuf_addf(&sb
, Q_("%lu year", "%lu years", years
), years
);
148 /* TRANSLATORS: "%s" is "<n> years" */
149 Q_("%s, %lu month ago", "%s, %lu months ago", months
),
154 Q_("%lu year ago", "%lu years ago", years
), years
);
157 /* Otherwise, just years. Centuries is probably overkill. */
159 Q_("%lu year ago", "%lu years ago", (diff
+ 183) / 365),
163 const char *show_date(unsigned long time
, int tz
, enum date_mode mode
)
166 static struct strbuf timebuf
= STRBUF_INIT
;
168 if (mode
== DATE_RAW
) {
169 strbuf_reset(&timebuf
);
170 strbuf_addf(&timebuf
, "%lu %+05d", time
, tz
);
174 if (mode
== DATE_RELATIVE
) {
177 strbuf_reset(&timebuf
);
178 gettimeofday(&now
, NULL
);
179 show_date_relative(time
, tz
, &now
, &timebuf
);
183 if (mode
== DATE_LOCAL
)
184 tz
= local_tzoffset(time
);
186 tm
= time_to_tm(time
, tz
);
188 tm
= time_to_tm(0, 0);
192 strbuf_reset(&timebuf
);
193 if (mode
== DATE_SHORT
)
194 strbuf_addf(&timebuf
, "%04d-%02d-%02d", tm
->tm_year
+ 1900,
195 tm
->tm_mon
+ 1, tm
->tm_mday
);
196 else if (mode
== DATE_ISO8601
)
197 strbuf_addf(&timebuf
, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
201 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
203 else if (mode
== DATE_ISO8601_STRICT
) {
204 char sign
= (tz
>= 0) ? '+' : '-';
206 strbuf_addf(&timebuf
, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
210 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
211 sign
, tz
/ 100, tz
% 100);
212 } else if (mode
== DATE_RFC2822
)
213 strbuf_addf(&timebuf
, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
214 weekday_names
[tm
->tm_wday
], tm
->tm_mday
,
215 month_names
[tm
->tm_mon
], tm
->tm_year
+ 1900,
216 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
, tz
);
218 strbuf_addf(&timebuf
, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
219 weekday_names
[tm
->tm_wday
],
220 month_names
[tm
->tm_mon
],
222 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
224 (mode
== DATE_LOCAL
) ? 0 : ' ',
230 * Check these. And note how it doesn't do the summer-time conversion.
232 * In my world, it's always summer, and things are probably a bit off
235 static const struct {
239 } timezone_names
[] = {
240 { "IDLW", -12, 0, }, /* International Date Line West */
241 { "NT", -11, 0, }, /* Nome */
242 { "CAT", -10, 0, }, /* Central Alaska */
243 { "HST", -10, 0, }, /* Hawaii Standard */
244 { "HDT", -10, 1, }, /* Hawaii Daylight */
245 { "YST", -9, 0, }, /* Yukon Standard */
246 { "YDT", -9, 1, }, /* Yukon Daylight */
247 { "PST", -8, 0, }, /* Pacific Standard */
248 { "PDT", -8, 1, }, /* Pacific Daylight */
249 { "MST", -7, 0, }, /* Mountain Standard */
250 { "MDT", -7, 1, }, /* Mountain Daylight */
251 { "CST", -6, 0, }, /* Central Standard */
252 { "CDT", -6, 1, }, /* Central Daylight */
253 { "EST", -5, 0, }, /* Eastern Standard */
254 { "EDT", -5, 1, }, /* Eastern Daylight */
255 { "AST", -3, 0, }, /* Atlantic Standard */
256 { "ADT", -3, 1, }, /* Atlantic Daylight */
257 { "WAT", -1, 0, }, /* West Africa */
259 { "GMT", 0, 0, }, /* Greenwich Mean */
260 { "UTC", 0, 0, }, /* Universal (Coordinated) */
261 { "Z", 0, 0, }, /* Zulu, alias for UTC */
263 { "WET", 0, 0, }, /* Western European */
264 { "BST", 0, 1, }, /* British Summer */
265 { "CET", +1, 0, }, /* Central European */
266 { "MET", +1, 0, }, /* Middle European */
267 { "MEWT", +1, 0, }, /* Middle European Winter */
268 { "MEST", +1, 1, }, /* Middle European Summer */
269 { "CEST", +1, 1, }, /* Central European Summer */
270 { "MESZ", +1, 1, }, /* Middle European Summer */
271 { "FWT", +1, 0, }, /* French Winter */
272 { "FST", +1, 1, }, /* French Summer */
273 { "EET", +2, 0, }, /* Eastern Europe, USSR Zone 1 */
274 { "EEST", +2, 1, }, /* Eastern European Daylight */
275 { "WAST", +7, 0, }, /* West Australian Standard */
276 { "WADT", +7, 1, }, /* West Australian Daylight */
277 { "CCT", +8, 0, }, /* China Coast, USSR Zone 7 */
278 { "JST", +9, 0, }, /* Japan Standard, USSR Zone 8 */
279 { "EAST", +10, 0, }, /* Eastern Australian Standard */
280 { "EADT", +10, 1, }, /* Eastern Australian Daylight */
281 { "GST", +10, 0, }, /* Guam Standard, USSR Zone 9 */
282 { "NZT", +12, 0, }, /* New Zealand */
283 { "NZST", +12, 0, }, /* New Zealand Standard */
284 { "NZDT", +12, 1, }, /* New Zealand Daylight */
285 { "IDLE", +12, 0, }, /* International Date Line East */
288 static int match_string(const char *date
, const char *str
)
292 for (i
= 0; *date
; date
++, str
++, i
++) {
295 if (toupper(*date
) == toupper(*str
))
304 static int skip_alpha(const char *date
)
309 } while (isalpha(date
[i
]));
314 * Parse month, weekday, or timezone name
316 static int match_alpha(const char *date
, struct tm
*tm
, int *offset
)
320 for (i
= 0; i
< 12; i
++) {
321 int match
= match_string(date
, month_names
[i
]);
328 for (i
= 0; i
< 7; i
++) {
329 int match
= match_string(date
, weekday_names
[i
]);
336 for (i
= 0; i
< ARRAY_SIZE(timezone_names
); i
++) {
337 int match
= match_string(date
, timezone_names
[i
].name
);
338 if (match
>= 3 || match
== strlen(timezone_names
[i
].name
)) {
339 int off
= timezone_names
[i
].offset
;
341 /* This is bogus, but we like summer */
342 off
+= timezone_names
[i
].dst
;
344 /* Only use the tz name offset if we don't have anything better */
352 if (match_string(date
, "PM") == 2) {
353 tm
->tm_hour
= (tm
->tm_hour
% 12) + 12;
357 if (match_string(date
, "AM") == 2) {
358 tm
->tm_hour
= (tm
->tm_hour
% 12) + 0;
363 return skip_alpha(date
);
366 static int is_date(int year
, int month
, int day
, struct tm
*now_tm
, time_t now
, struct tm
*tm
)
368 if (month
> 0 && month
< 13 && day
> 0 && day
< 32) {
369 struct tm check
= *tm
;
370 struct tm
*r
= (now_tm
? &check
: tm
);
373 r
->tm_mon
= month
- 1;
378 r
->tm_year
= now_tm
->tm_year
;
380 else if (year
>= 1970 && year
< 2100)
381 r
->tm_year
= year
- 1900;
382 else if (year
> 70 && year
< 100)
385 r
->tm_year
= year
+ 100;
391 specified
= tm_to_time_t(r
);
393 /* Be it commit time or author time, it does not make
394 * sense to specify timestamp way into the future. Make
395 * sure it is not later than ten days from now...
397 if ((specified
!= -1) && (now
+ 10*24*3600 < specified
))
399 tm
->tm_mon
= r
->tm_mon
;
400 tm
->tm_mday
= r
->tm_mday
;
402 tm
->tm_year
= r
->tm_year
;
408 static int match_multi_number(unsigned long num
, char c
, const char *date
, char *end
, struct tm
*tm
)
412 struct tm
*refuse_future
;
415 num2
= strtol(end
+1, &end
, 10);
417 if (*end
== c
&& isdigit(end
[1]))
418 num3
= strtol(end
+1, &end
, 10);
425 if (num
< 25 && num2
>= 0 && num2
< 60 && num3
>= 0 && num3
<= 60) {
437 refuse_future
= NULL
;
438 if (gmtime_r(&now
, &now_tm
))
439 refuse_future
= &now_tm
;
443 if (is_date(num
, num2
, num3
, refuse_future
, now
, tm
))
446 if (is_date(num
, num3
, num2
, refuse_future
, now
, tm
))
449 /* Our eastern European friends say dd.mm.yy[yy]
450 * is the norm there, so giving precedence to
451 * mm/dd/yy[yy] form only when separator is not '.'
454 is_date(num3
, num
, num2
, refuse_future
, now
, tm
))
456 /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */
457 if (is_date(num3
, num2
, num
, refuse_future
, now
, tm
))
459 /* Funny European mm.dd.yy */
461 is_date(num3
, num
, num2
, refuse_future
, now
, tm
))
469 * Have we filled in any part of the time/date yet?
470 * We just do a binary 'and' to see if the sign bit
471 * is set in all the values.
473 static inline int nodate(struct tm
*tm
)
475 return (tm
->tm_year
&
484 * We've seen a digit. Time? Year? Date?
486 static int match_digit(const char *date
, struct tm
*tm
, int *offset
, int *tm_gmt
)
492 num
= strtoul(date
, &end
, 10);
495 * Seconds since 1970? We trigger on that for any numbers with
496 * more than 8 digits. This is because we don't want to rule out
497 * numbers like 20070606 as a YYYYMMDD date.
499 if (num
>= 100000000 && nodate(tm
)) {
501 if (gmtime_r(&time
, tm
)) {
508 * Check for special formats: num[-.:/]num[same]num
515 if (isdigit(end
[1])) {
516 int match
= match_multi_number(num
, *end
, date
, end
, tm
);
523 * None of the special formats? Try to guess what
524 * the number meant. We use the number of digits
525 * to make a more educated guess..
530 } while (isdigit(date
[n
]));
532 /* Four-digit year or a timezone? */
534 if (num
<= 1400 && *offset
== -1) {
535 unsigned int minutes
= num
% 100;
536 unsigned int hours
= num
/ 100;
537 *offset
= hours
*60 + minutes
;
538 } else if (num
> 1900 && num
< 2100)
539 tm
->tm_year
= num
- 1900;
544 * Ignore lots of numerals. We took care of 4-digit years above.
545 * Days or months must be one or two digits.
551 * NOTE! We will give precedence to day-of-month over month or
552 * year numbers in the 1-12 range. So 05 is always "mday 5",
553 * unless we already have a mday..
555 * IOW, 01 Apr 05 parses as "April 1st, 2005".
557 if (num
> 0 && num
< 32 && tm
->tm_mday
< 0) {
562 /* Two-digit year? */
563 if (n
== 2 && tm
->tm_year
< 0) {
564 if (num
< 10 && tm
->tm_mday
>= 0) {
565 tm
->tm_year
= num
+ 100;
574 if (num
> 0 && num
< 13 && tm
->tm_mon
< 0)
580 static int match_tz(const char *date
, int *offp
)
583 int hour
= strtoul(date
+ 1, &end
, 10);
584 int n
= end
- (date
+ 1);
592 min
= 99; /* random crap */
593 } else if (*end
== ':') {
595 min
= strtoul(end
+ 1, &end
, 10);
596 if (end
- (date
+ 1) != 5)
597 min
= 99; /* random crap */
598 } /* otherwise we parsed "hh" */
601 * Don't accept any random crap. Even though some places have
602 * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
603 * UTC+14), there is something wrong if hour part is much
604 * larger than that. We might also want to check that the
605 * minutes are divisible by 15 or something too. (Offset of
606 * Kathmandu, Nepal is UTC+5:45)
608 if (min
< 60 && hour
< 24) {
609 int offset
= hour
* 60 + min
;
617 static void date_string(unsigned long date
, int offset
, struct strbuf
*buf
)
625 strbuf_addf(buf
, "%lu %c%02d%02d", date
, sign
, offset
/ 60, offset
% 60);
629 * Parse a string like "0 +0000" as ancient timestamp near epoch, but
630 * only when it appears not as part of any other string.
632 static int match_object_header_date(const char *date
, unsigned long *timestamp
, int *offset
)
638 if (*date
< '0' || '9' < *date
)
640 stamp
= strtoul(date
, &end
, 10);
641 if (*end
!= ' ' || stamp
== ULONG_MAX
|| (end
[1] != '+' && end
[1] != '-'))
644 ofs
= strtol(date
, &end
, 10);
645 if ((*end
!= '\0' && (*end
!= '\n')) || end
!= date
+ 4)
647 ofs
= (ofs
/ 100) * 60 + (ofs
% 100);
655 /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
656 (i.e. English) day/month names, and it doesn't work correctly with %z. */
657 int parse_date_basic(const char *date
, unsigned long *timestamp
, int *offset
)
661 unsigned long dummy_timestamp
;
665 timestamp
= &dummy_timestamp
;
667 offset
= &dummy_offset
;
669 memset(&tm
, 0, sizeof(tm
));
681 !match_object_header_date(date
+ 1, timestamp
, offset
))
682 return 0; /* success */
685 unsigned char c
= *date
;
687 /* Stop at end of string or newline */
692 match
= match_alpha(date
, &tm
, offset
);
694 match
= match_digit(date
, &tm
, offset
, &tm_gmt
);
695 else if ((c
== '-' || c
== '+') && isdigit(date
[1]))
696 match
= match_tz(date
, offset
);
706 /* mktime uses local timezone */
707 *timestamp
= tm_to_time_t(&tm
);
709 time_t temp_time
= mktime(&tm
);
710 if ((time_t)*timestamp
> temp_time
) {
711 *offset
= ((time_t)*timestamp
- temp_time
) / 60;
713 *offset
= -(int)((temp_time
- (time_t)*timestamp
) / 60);
717 if (*timestamp
== -1)
721 *timestamp
-= *offset
* 60;
722 return 0; /* success */
725 int parse_expiry_date(const char *date
, unsigned long *timestamp
)
729 if (!strcmp(date
, "never") || !strcmp(date
, "false"))
731 else if (!strcmp(date
, "all") || !strcmp(date
, "now"))
733 * We take over "now" here, which usually translates
734 * to the current timestamp. This is because the user
735 * really means to expire everything she has done in
736 * the past, and by definition reflogs are the record
737 * of the past, and there is nothing from the future
740 *timestamp
= ULONG_MAX
;
742 *timestamp
= approxidate_careful(date
, &errors
);
747 int parse_date(const char *date
, struct strbuf
*result
)
749 unsigned long timestamp
;
751 if (parse_date_basic(date
, ×tamp
, &offset
))
753 date_string(timestamp
, offset
, result
);
757 enum date_mode
parse_date_format(const char *format
)
759 if (!strcmp(format
, "relative"))
760 return DATE_RELATIVE
;
761 else if (!strcmp(format
, "iso8601") ||
762 !strcmp(format
, "iso"))
764 else if (!strcmp(format
, "iso8601-strict") ||
765 !strcmp(format
, "iso-strict"))
766 return DATE_ISO8601_STRICT
;
767 else if (!strcmp(format
, "rfc2822") ||
768 !strcmp(format
, "rfc"))
770 else if (!strcmp(format
, "short"))
772 else if (!strcmp(format
, "local"))
774 else if (!strcmp(format
, "default"))
776 else if (!strcmp(format
, "raw"))
779 die("unknown date format %s", format
);
782 void datestamp(struct strbuf
*out
)
789 offset
= tm_to_time_t(localtime(&now
)) - now
;
792 date_string(now
, offset
, out
);
796 * Relative time update (eg "2 days ago"). If we haven't set the time
797 * yet, we need to set it from current time.
799 static unsigned long update_tm(struct tm
*tm
, struct tm
*now
, unsigned long sec
)
804 tm
->tm_mday
= now
->tm_mday
;
806 tm
->tm_mon
= now
->tm_mon
;
807 if (tm
->tm_year
< 0) {
808 tm
->tm_year
= now
->tm_year
;
809 if (tm
->tm_mon
> now
->tm_mon
)
813 n
= mktime(tm
) - sec
;
818 static void date_now(struct tm
*tm
, struct tm
*now
, int *num
)
820 update_tm(tm
, now
, 0);
823 static void date_yesterday(struct tm
*tm
, struct tm
*now
, int *num
)
825 update_tm(tm
, now
, 24*60*60);
828 static void date_time(struct tm
*tm
, struct tm
*now
, int hour
)
830 if (tm
->tm_hour
< hour
)
831 date_yesterday(tm
, now
, NULL
);
837 static void date_midnight(struct tm
*tm
, struct tm
*now
, int *num
)
839 date_time(tm
, now
, 0);
842 static void date_noon(struct tm
*tm
, struct tm
*now
, int *num
)
844 date_time(tm
, now
, 12);
847 static void date_tea(struct tm
*tm
, struct tm
*now
, int *num
)
849 date_time(tm
, now
, 17);
852 static void date_pm(struct tm
*tm
, struct tm
*now
, int *num
)
863 tm
->tm_hour
= (hour
% 12) + 12;
866 static void date_am(struct tm
*tm
, struct tm
*now
, int *num
)
877 tm
->tm_hour
= (hour
% 12);
880 static void date_never(struct tm
*tm
, struct tm
*now
, int *num
)
886 static const struct special
{
888 void (*fn
)(struct tm
*, struct tm
*, int *);
890 { "yesterday", date_yesterday
},
891 { "noon", date_noon
},
892 { "midnight", date_midnight
},
896 { "never", date_never
},
901 static const char *number_name
[] = {
902 "zero", "one", "two", "three", "four",
903 "five", "six", "seven", "eight", "nine", "ten",
906 static const struct typelen
{
913 { "days", 24*60*60 },
914 { "weeks", 7*24*60*60 },
918 static const char *approxidate_alpha(const char *date
, struct tm
*tm
, struct tm
*now
, int *num
, int *touched
)
920 const struct typelen
*tl
;
921 const struct special
*s
;
922 const char *end
= date
;
925 while (isalpha(*++end
))
928 for (i
= 0; i
< 12; i
++) {
929 int match
= match_string(date
, month_names
[i
]);
937 for (s
= special
; s
->name
; s
++) {
938 int len
= strlen(s
->name
);
939 if (match_string(date
, s
->name
) == len
) {
947 for (i
= 1; i
< 11; i
++) {
948 int len
= strlen(number_name
[i
]);
949 if (match_string(date
, number_name
[i
]) == len
) {
955 if (match_string(date
, "last") == 4) {
964 int len
= strlen(tl
->type
);
965 if (match_string(date
, tl
->type
) >= len
-1) {
966 update_tm(tm
, now
, tl
->length
* *num
);
974 for (i
= 0; i
< 7; i
++) {
975 int match
= match_string(date
, weekday_names
[i
]);
977 int diff
, n
= *num
-1;
980 diff
= tm
->tm_wday
- i
;
985 update_tm(tm
, now
, diff
* 24 * 60 * 60);
991 if (match_string(date
, "months") >= 5) {
993 update_tm(tm
, now
, 0); /* fill in date fields if needed */
994 n
= tm
->tm_mon
- *num
;
1005 if (match_string(date
, "years") >= 4) {
1006 update_tm(tm
, now
, 0); /* fill in date fields if needed */
1007 tm
->tm_year
-= *num
;
1016 static const char *approxidate_digit(const char *date
, struct tm
*tm
, int *num
)
1019 unsigned long number
= strtoul(date
, &end
, 10);
1026 if (isdigit(end
[1])) {
1027 int match
= match_multi_number(number
, *end
, date
, end
, tm
);
1029 return date
+ match
;
1033 /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */
1034 if (date
[0] != '0' || end
- date
<= 2)
1040 * Do we have a pending number at the end, or when
1041 * we see a new one? Let's assume it's a month day,
1042 * as in "Dec 6, 1992"
1044 static void pending_number(struct tm
*tm
, int *num
)
1050 if (tm
->tm_mday
< 0 && number
< 32)
1051 tm
->tm_mday
= number
;
1052 else if (tm
->tm_mon
< 0 && number
< 13)
1053 tm
->tm_mon
= number
-1;
1054 else if (tm
->tm_year
< 0) {
1055 if (number
> 1969 && number
< 2100)
1056 tm
->tm_year
= number
- 1900;
1057 else if (number
> 69 && number
< 100)
1058 tm
->tm_year
= number
;
1059 else if (number
< 38)
1060 tm
->tm_year
= 100 + number
;
1061 /* We screw up for number = 00 ? */
1066 static unsigned long approxidate_str(const char *date
,
1067 const struct timeval
*tv
,
1075 time_sec
= tv
->tv_sec
;
1076 localtime_r(&time_sec
, &tm
);
1084 unsigned char c
= *date
;
1089 pending_number(&tm
, &number
);
1090 date
= approxidate_digit(date
-1, &tm
, &number
);
1095 date
= approxidate_alpha(date
-1, &tm
, &now
, &number
, &touched
);
1097 pending_number(&tm
, &number
);
1100 return update_tm(&tm
, &now
, 0);
1103 unsigned long approxidate_relative(const char *date
, const struct timeval
*tv
)
1105 unsigned long timestamp
;
1109 if (!parse_date_basic(date
, ×tamp
, &offset
))
1111 return approxidate_str(date
, tv
, &errors
);
1114 unsigned long approxidate_careful(const char *date
, int *error_ret
)
1117 unsigned long timestamp
;
1123 if (!parse_date_basic(date
, ×tamp
, &offset
)) {
1128 gettimeofday(&tv
, NULL
);
1129 return approxidate_str(date
, &tv
, error_ret
);
1132 int date_overflows(unsigned long t
)
1136 /* If we overflowed our unsigned long, that's bad... */
1141 * ...but we also are going to feed the result to system
1142 * functions that expect time_t, which is often "signed long".
1143 * Make sure that we fit into time_t, as well.
1146 return t
!= sys
|| (t
< 1) != (sys
< 1);