39
"Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"
40
};
41
42
-static time_t gm_time_t(unsigned long time, int tz)
42
+static time_t gm_time_t(timestamp_t time, int tz)
43
{
44
int minutes;
45
54
* thing, which means that tz -0100 is passed in as the integer -100,
55
* even though it means "sixty minutes off"
56
*/
57
-static struct tm *time_to_tm(unsigned long time, int tz)
57
+static struct tm *time_to_tm(timestamp_t time, int tz)
58
{
59
time_t t = gm_time_t(time, tz);
60
return gmtime(&t);
64
* What value of "tz" was in effect back then at "time" in the
65
* local timezone?
66
*/
67
-static int local_tzoffset(unsigned long time)
67
+static int local_tzoffset(timestamp_t time)
68
{
69
time_t t, t_local;
70
struct tm tm;
88
return offset * eastwest;
89
}
90
91
-void show_date_relative(unsigned long time, int tz,
91
+void show_date_relative(timestamp_t time, int tz,
92
const struct timeval *now,
93
struct strbuf *timebuf)
94
{
95
- unsigned long diff;
95
+ timestamp_t diff;
96
if (now->tv_sec < time) {
97
strbuf_addstr(timebuf, _("in the future"));
98
return;
140
}
141
/* Give years and months for 5 years or so */
142
if (diff < 1825) {
143
- unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
144
- unsigned long years = totalmonths / 12;
145
- unsigned long months = totalmonths % 12;
143
+ timestamp_t totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
144
+ timestamp_t years = totalmonths / 12;
145
+ timestamp_t months = totalmonths % 12;
146
if (months) {
147
struct strbuf sb = STRBUF_INIT;
148
strbuf_addf(&sb, Q_("%"PRItime" year", "%"PRItime" years", years), years);
172
return &mode;
173
}
174
175
-const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
175
+const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
176
{
177
struct tm *tm;
178
static struct strbuf timebuf = STRBUF_INIT;
425
return 0;
426
}
427
428
-static int match_multi_number(unsigned long num, char c, const char *date,
428
+static int match_multi_number(timestamp_t num, char c, const char *date,
429
char *end, struct tm *tm, time_t now)
430
{
431
struct tm now_tm;
508
{
509
int n;
510
char *end;
511
- unsigned long num;
511
+ timestamp_t num;
512
513
num = parse_timestamp(date, &end, 10);
514
635
return end - date;
636
}
637
638
-static void date_string(unsigned long date, int offset, struct strbuf *buf)
638
+static void date_string(timestamp_t date, int offset, struct strbuf *buf)
639
{
640
int sign = '+';
641
650
* Parse a string like "0 +0000" as ancient timestamp near epoch, but
651
* only when it appears not as part of any other string.
652
*/
653
-static int match_object_header_date(const char *date, unsigned long *timestamp, int *offset)
653
+static int match_object_header_date(const char *date, timestamp_t *timestamp, int *offset)
654
{
655
char *end;
656
- unsigned long stamp;
656
+ timestamp_t stamp;
657
int ofs;
658
659
if (*date < '0' || '9' < *date)
660
return -1;
661
stamp = parse_timestamp(date, &end, 10);
662
- if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
662
+ if (*end != ' ' || stamp == TIME_MAX || (end[1] != '+' && end[1] != '-'))
663
return -1;
664
date = end + 2;
665
ofs = strtol(date, &end, 10);
675
676
/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
677
(i.e. English) day/month names, and it doesn't work correctly with %z. */
678
-int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
678
+int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset)
679
{
680
struct tm tm;
681
int tm_gmt;
682
- unsigned long dummy_timestamp;
682
+ timestamp_t dummy_timestamp;
683
int dummy_offset;
684
685
if (!timestamp)
747
return 0; /* success */
748
}
749
750
-int parse_expiry_date(const char *date, unsigned long *timestamp)
750
+int parse_expiry_date(const char *date, timestamp_t *timestamp)
751
{
752
int errors = 0;
753
762
* of the past, and there is nothing from the future
763
* to be kept.
764
*/
765
- *timestamp = ULONG_MAX;
765
+ *timestamp = TIME_MAX;
766
else
767
*timestamp = approxidate_careful(date, &errors);
768
771
772
int parse_date(const char *date, struct strbuf *result)
773
{
774
- unsigned long timestamp;
774
+ timestamp_t timestamp;
775
int offset;
776
if (parse_date_basic(date, ×tamp, &offset))
777
return -1;
845
* Relative time update (eg "2 days ago"). If we haven't set the time
846
* yet, we need to set it from current time.
847
*/
848
-static unsigned long update_tm(struct tm *tm, struct tm *now, unsigned long sec)
848
+static time_t update_tm(struct tm *tm, struct tm *now, time_t sec)
849
{
850
time_t n;
851
1066
time_t now)
1067
{
1068
char *end;
1069
- unsigned long number = parse_timestamp(date, &end, 10);
1069
+ timestamp_t number = parse_timestamp(date, &end, 10);
1070
1071
switch (*end) {
1072
case ':':
1114
}
1115
}
1116
1117
-static unsigned long approxidate_str(const char *date,
1118
- const struct timeval *tv,
1119
- int *error_ret)
1117
+static timestamp_t approxidate_str(const char *date,
1118
+ const struct timeval *tv,
1119
+ int *error_ret)
1120
{
1121
int number = 0;
1122
int touched = 0;
1148
pending_number(&tm, &number);
1149
if (!touched)
1150
*error_ret = 1;
1151
- return update_tm(&tm, &now, 0);
1151
+ return (timestamp_t)update_tm(&tm, &now, 0);
1152
}
1153
1154
-unsigned long approxidate_relative(const char *date, const struct timeval *tv)
1154
+timestamp_t approxidate_relative(const char *date, const struct timeval *tv)
1155
{
1156
- unsigned long timestamp;
1156
+ timestamp_t timestamp;
1157
int offset;
1158
int errors = 0;
1159
1162
return approxidate_str(date, tv, &errors);
1163
}
1164
1165
-unsigned long approxidate_careful(const char *date, int *error_ret)
1165
+timestamp_t approxidate_careful(const char *date, int *error_ret)
1166
{
1167
struct timeval tv;
1168
- unsigned long timestamp;
1168
+ timestamp_t timestamp;
1169
int offset;
1170
int dummy = 0;
1171
if (!error_ret)
1180
return approxidate_str(date, &tv, error_ret);
1181
}
1182
1183
-int date_overflows(unsigned long t)
1183
+int date_overflows(timestamp_t t)
1184
{
1185
time_t sys;
1186
1187
- /* If we overflowed our unsigned long, that's bad... */
1188
- if (t == ULONG_MAX)
1187
+ /* If we overflowed our timestamp data type, that's bad... */
1188
+ if ((uintmax_t)t >= TIME_MAX)
1189
return 1;
1190
1191
/*