mirror of
https://github.com/fluencelabs/musl
synced 2025-06-01 17:11:53 +00:00
this commit has two major user-visible parts: zoneinfo-format time zones are now supported, and overflow handling is intended to be complete in the sense that all functions return a correct result if and only if the result fits in the destination type, and otherwise return an error. also, some noticable bugs in the way DST detection and normalization worked have been fixed, and performance may be better than before, but it has not been tested.
25 lines
482 B
C
25 lines
482 B
C
#include "time_impl.h"
|
|
|
|
long long __tm_to_secs(const struct tm *tm)
|
|
{
|
|
int is_leap;
|
|
long long year = tm->tm_year;
|
|
int month = tm->tm_mon;
|
|
if (month >= 12 || month < 0) {
|
|
int adj = month / 12;
|
|
month %= 12;
|
|
if (month < 0) {
|
|
adj--;
|
|
month += 12;
|
|
}
|
|
year += adj;
|
|
}
|
|
long long t = __year_to_secs(year, &is_leap);
|
|
t += __month_to_secs(month, is_leap);
|
|
t += 86400LL * (tm->tm_mday-1);
|
|
t += 3600LL * tm->tm_hour;
|
|
t += 60LL * tm->tm_min;
|
|
t += tm->tm_sec;
|
|
return t;
|
|
}
|