@@ -18,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
1818namespace time_utils {
1919
2020// 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) {
2222 // Unlike most C Library functions, mktime doesn't just die on bad input.
2323 // TODO(rtenneti); Handle leap seconds.
2424 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) {
2727 if (sizeof (time_t ) == 4 &&
2828 tm_year_from_base >= time_constants::END_OF32_BIT_EPOCH_YEAR) {
2929 if (tm_year_from_base > time_constants::END_OF32_BIT_EPOCH_YEAR)
30- return time_utils::out_of_range () ;
30+ return cpp:: nullopt ;
3131 if (tm_out->tm_mon > 0 )
32- return time_utils::out_of_range () ;
32+ return cpp:: nullopt ;
3333 if (tm_out->tm_mday > 19 )
34- return time_utils::out_of_range () ;
34+ return cpp:: nullopt ;
3535 else if (tm_out->tm_mday == 19 ) {
3636 if (tm_out->tm_hour > 3 )
37- return time_utils::out_of_range () ;
37+ return cpp:: nullopt ;
3838 else if (tm_out->tm_hour == 3 ) {
3939 if (tm_out->tm_min > 14 )
40- return time_utils::out_of_range () ;
40+ return cpp:: nullopt ;
4141 else if (tm_out->tm_min == 14 ) {
4242 if (tm_out->tm_sec > 7 )
43- return time_utils::out_of_range () ;
43+ return cpp:: nullopt ;
4444 }
4545 }
4646 }
@@ -102,10 +102,10 @@ int64_t mktime_internal(const tm *tm_out) {
102102
103103 // TODO: https://github.com/llvm/llvm-project/issues/121962
104104 // 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;
109109 return seconds;
110110}
111111
@@ -136,7 +136,7 @@ static int64_t computeRemainingYears(int64_t daysPerYears,
136136//
137137// Compute the number of months from the remaining days. Finally, adjust years
138138// 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) {
140140 // Days in month starting from March in the year 2000.
141141 static const char daysInMonth[] = {31 /* Mar */ , 30 , 31 , 30 , 31 , 31 ,
142142 30 , 31 , 30 , 31 , 31 , 29 };
@@ -152,8 +152,7 @@ int64_t update_from_seconds(int64_t total_seconds, tm *tm) {
152152 : INT_MAX * static_cast <int64_t >(
153153 time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);
154154
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)
157156 return time_utils::out_of_range ();
158157
159158 int64_t seconds =
0 commit comments