mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
Import timelib version 2018.03
This commit is contained in:
parent
22ac57b064
commit
3725a446ba
@ -144,7 +144,7 @@ void timelib_isodate_from_date(timelib_sll y, timelib_sll m, timelib_sll d, time
|
||||
*id = timelib_day_of_week_ex(y, m, d, 1);
|
||||
}
|
||||
|
||||
static timelib_sll timelib_daynr_from_weeknr_ex(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y)
|
||||
timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id)
|
||||
{
|
||||
timelib_sll dow, day;
|
||||
|
||||
@ -152,54 +152,41 @@ static timelib_sll timelib_daynr_from_weeknr_ex(timelib_sll iy, timelib_sll iw,
|
||||
dow = timelib_day_of_week(iy, 1, 1);
|
||||
/* then use that to figure out the offset for day 1 of week 1 */
|
||||
day = 0 - (dow > 4 ? dow - 7 : dow);
|
||||
/* and adjust the year to the natural year if we need to */
|
||||
*y = (iw == 1 && day < 0 && id < dow) ? iy - 1 : iy;
|
||||
|
||||
/* Add weeks and days */
|
||||
return day + ((iw - 1) * 7) + id;
|
||||
}
|
||||
|
||||
timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id)
|
||||
{
|
||||
timelib_sll dummy_iso_year;
|
||||
|
||||
return timelib_daynr_from_weeknr_ex(iy, iw, id, &dummy_iso_year);
|
||||
}
|
||||
|
||||
void timelib_date_from_isodate(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y, timelib_sll *m, timelib_sll *d)
|
||||
{
|
||||
timelib_sll daynr = timelib_daynr_from_weeknr_ex(iy, iw, id, y) + 1;
|
||||
timelib_sll daynr = timelib_daynr_from_weeknr(iy, iw, id) + 1;
|
||||
int *table;
|
||||
bool is_leap_year;
|
||||
|
||||
*m = 0;
|
||||
// Invariant: is_leap_year == timelib_is_leap(*y)
|
||||
*y = iy;
|
||||
is_leap_year = timelib_is_leap(*y);
|
||||
|
||||
if (daynr <= 0) {
|
||||
*y += 1;
|
||||
}
|
||||
|
||||
if (timelib_is_leap(*y)) {
|
||||
table = ml_table_leap;
|
||||
if (daynr > 366) {
|
||||
*y += 1;
|
||||
daynr -= 366;
|
||||
}
|
||||
} else {
|
||||
table = ml_table_common;
|
||||
if (daynr > 365) {
|
||||
*y += 1;
|
||||
daynr -= 365;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
daynr -= table[*m];
|
||||
(*m)++;
|
||||
} while (daynr > table[*m]);
|
||||
|
||||
if (daynr <= 0) {
|
||||
daynr += 31;
|
||||
// Establish invariant that daynr >= 0
|
||||
while (daynr <= 0) {
|
||||
*y -= 1;
|
||||
*m = 12;
|
||||
daynr += (is_leap_year = timelib_is_leap(*y)) ? 366 : 365;
|
||||
}
|
||||
|
||||
// Establish invariant that daynr <= number of days in *yr
|
||||
while (daynr > (is_leap_year ? 366 : 365)) {
|
||||
daynr -= is_leap_year ? 366 : 365;
|
||||
*y += 1;
|
||||
is_leap_year = timelib_is_leap(*y);
|
||||
}
|
||||
|
||||
table = is_leap_year ? ml_table_leap : ml_table_common;
|
||||
|
||||
// Establish invariant that daynr <= number of days in *m
|
||||
*m = 1;
|
||||
while (daynr > table[*m]) {
|
||||
daynr -= table[*m];
|
||||
*m += 1;
|
||||
}
|
||||
|
||||
*d = daynr;
|
||||
|
@ -322,9 +322,9 @@ typedef struct _timelib_tzdb {
|
||||
# define timelib_free free
|
||||
#endif
|
||||
|
||||
#define TIMELIB_VERSION 201802
|
||||
#define TIMELIB_EXTENDED_VERSION 20180201
|
||||
#define TIMELIB_ASCII_VERSION "2018.02"
|
||||
#define TIMELIB_VERSION 201803
|
||||
#define TIMELIB_EXTENDED_VERSION 20180301
|
||||
#define TIMELIB_ASCII_VERSION "2018.03"
|
||||
|
||||
#define TIMELIB_NONE 0x00
|
||||
#define TIMELIB_OVERRIDE_TIME 0x01
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,18 +33,6 @@ static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 24
|
||||
static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
static void do_range_limit_fraction(timelib_sll *fraction, timelib_sll *seconds)
|
||||
{
|
||||
if (*fraction < 0) {
|
||||
*fraction += 1000000;
|
||||
*seconds -= 1;
|
||||
}
|
||||
if (*fraction >= 1000000) {
|
||||
*fraction -= 1000000;
|
||||
*seconds += 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b)
|
||||
{
|
||||
if (*a < start) {
|
||||
@ -194,7 +182,7 @@ static void do_adjust_for_weekday(timelib_time* time)
|
||||
|
||||
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
|
||||
{
|
||||
do_range_limit_fraction(&rt->us, &rt->s);
|
||||
do_range_limit(0, 1000000, 1000000, &rt->us, &rt->s);
|
||||
do_range_limit(0, 60, 60, &rt->s, &rt->i);
|
||||
do_range_limit(0, 60, 60, &rt->i, &rt->h);
|
||||
do_range_limit(0, 24, 24, &rt->h, &rt->d);
|
||||
@ -234,7 +222,7 @@ static void magic_date_calc(timelib_time *time)
|
||||
|
||||
void timelib_do_normalize(timelib_time* time)
|
||||
{
|
||||
if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);
|
||||
if (time->us != TIMELIB_UNSET) do_range_limit(0, 1000000, 1000000, &time->us, &time->s);
|
||||
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
|
||||
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
|
||||
if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d);
|
||||
|
Loading…
Reference in New Issue
Block a user