@@ -18,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
18
18
namespace time_utils {
19
19
20
20
// TODO: clean this up in a followup patch
21
- int64_t mktime_internal (const tm *tm_out) {
21
+ cpp::optional< time_t > mktime_internal (const tm *tm_out) {
22
22
// Unlike most C Library functions, mktime doesn't just die on bad input.
23
23
// TODO(rtenneti); Handle leap seconds.
24
24
int64_t tm_year_from_base = tm_out->tm_year + time_constants::TIME_YEAR_BASE;
@@ -27,20 +27,20 @@ int64_t mktime_internal(const tm *tm_out) {
27
27
if (sizeof (time_t ) == 4 &&
28
28
tm_year_from_base >= time_constants::END_OF32_BIT_EPOCH_YEAR) {
29
29
if (tm_year_from_base > time_constants::END_OF32_BIT_EPOCH_YEAR)
30
- return time_utils::out_of_range () ;
30
+ return cpp::nullopt ;
31
31
if (tm_out->tm_mon > 0 )
32
- return time_utils::out_of_range () ;
32
+ return cpp::nullopt ;
33
33
if (tm_out->tm_mday > 19 )
34
- return time_utils::out_of_range () ;
34
+ return cpp::nullopt ;
35
35
else if (tm_out->tm_mday == 19 ) {
36
36
if (tm_out->tm_hour > 3 )
37
- return time_utils::out_of_range () ;
37
+ return cpp::nullopt ;
38
38
else if (tm_out->tm_hour == 3 ) {
39
39
if (tm_out->tm_min > 14 )
40
- return time_utils::out_of_range () ;
40
+ return cpp::nullopt ;
41
41
else if (tm_out->tm_min == 14 ) {
42
42
if (tm_out->tm_sec > 7 )
43
- return time_utils::out_of_range () ;
43
+ return cpp::nullopt ;
44
44
}
45
45
}
46
46
}
@@ -102,10 +102,10 @@ int64_t mktime_internal(const tm *tm_out) {
102
102
103
103
// TODO: https://github.com/llvm/llvm-project/issues/121962
104
104
// Need to handle timezone and update of tm_isdst.
105
- int64_t seconds = tm_out->tm_sec +
106
- tm_out->tm_min * time_constants::SECONDS_PER_MIN +
107
- tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
108
- total_days * time_constants::SECONDS_PER_DAY;
105
+ time_t seconds = tm_out->tm_sec +
106
+ tm_out->tm_min * time_constants::SECONDS_PER_MIN +
107
+ tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
108
+ total_days * time_constants::SECONDS_PER_DAY;
109
109
return seconds;
110
110
}
111
111
@@ -136,7 +136,7 @@ static int64_t computeRemainingYears(int64_t daysPerYears,
136
136
//
137
137
// Compute the number of months from the remaining days. Finally, adjust years
138
138
// to be 1900 and months to be from January.
139
- int64_t update_from_seconds (int64_t total_seconds, tm *tm) {
139
+ int64_t update_from_seconds (time_t total_seconds, tm *tm) {
140
140
// Days in month starting from March in the year 2000.
141
141
static const char daysInMonth[] = {31 /* Mar */ , 30 , 31 , 30 , 31 , 31 ,
142
142
30 , 31 , 30 , 31 , 31 , 29 };
@@ -152,8 +152,7 @@ int64_t update_from_seconds(int64_t total_seconds, tm *tm) {
152
152
: INT_MAX * static_cast <int64_t >(
153
153
time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);
154
154
155
- time_t ts = static_cast <time_t >(total_seconds);
156
- if (ts < time_min || ts > time_max)
155
+ if (total_seconds < time_min || total_seconds > time_max)
157
156
return time_utils::out_of_range ();
158
157
159
158
int64_t seconds =
0 commit comments