Skip to content

Commit dff9713

Browse files
committed
Merge branch 'PHP-7.2'
2 parents 28fdc1f + a063d55 commit dff9713

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+28723
-3243
lines changed

ext/date/lib/LICENSE.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Derick Rethans
3+
Copyright (c) 2015-2017 Derick Rethans
4+
Copyright (c) 2017 MongoDB, Inc.
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

ext/date/lib/astro.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
| Schlyter, who wrote this in December 1992 |
2727
*/
2828

29+
#include "timelib.h"
2930
#include <stdio.h>
3031
#include <math.h>
31-
#include "timelib.h"
3232

3333
#define days_since_2000_Jan_0(y,m,d) \
3434
(367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
3535

3636
#ifndef PI
37-
#define PI 3.1415926535897932384
37+
# define PI 3.1415926535897932384
3838
#endif
3939

4040
#define RADEG ( 180.0 / PI )
@@ -230,7 +230,8 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
230230
t_loc->i = t_loc->s = 0;
231231
timelib_update_ts(t_loc, NULL);
232232

233-
/* Calculate TS belonging to UTC 00:00 of the current day */
233+
/* Calculate TS belonging to UTC 00:00 of the current day, for input into
234+
* the algorithm */
234235
t_utc = timelib_time_ctor();
235236
t_utc->y = t_loc->y;
236237
t_utc->m = t_loc->m;
@@ -239,8 +240,8 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
239240
timelib_update_ts(t_utc, NULL);
240241

241242
/* Compute d of 12h local mean solar time */
242-
timestamp = t_loc->sse;
243-
d = timelib_ts_to_juliandate(timestamp) - lon/360.0;
243+
timestamp = t_utc->sse;
244+
d = timelib_ts_to_j2000(timestamp) + 2 - lon/360.0;
244245

245246
/* Compute local sidereal time of this moment */
246247
sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon);
@@ -295,14 +296,18 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
295296
return rc;
296297
}
297298

298-
double timelib_ts_to_juliandate(timelib_sll ts)
299+
double timelib_ts_to_julianday(timelib_sll ts)
299300
{
300301
double tmp;
301302

302-
tmp = ts;
303-
tmp /= 86400;
304-
tmp += 2440587.5;
305-
tmp -= 2451543;
303+
tmp = (double) ts;
304+
tmp /= (double) 86400;
305+
tmp += (double) 2440587.5;
306306

307307
return tmp;
308308
}
309+
310+
double timelib_ts_to_j2000(timelib_sll ts)
311+
{
312+
return timelib_ts_to_julianday(ts) - 2451545;
313+
}

ext/date/lib/dow.c

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "timelib.h"
26+
#include "timelib_private.h"
2627

2728
static int m_table_common[13] = { -1, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
2829
static int m_table_leap[13] = { -1, 6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
@@ -137,17 +138,71 @@ void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, time
137138
}
138139
}
139140

140-
timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d)
141+
void timelib_isodate_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iy, timelib_sll *iw, timelib_sll *id)
142+
{
143+
timelib_isoweek_from_date(y, m, d, iw, iy);
144+
*id = timelib_day_of_week_ex(y, m, d, 1);
145+
}
146+
147+
static timelib_sll timelib_daynr_from_weeknr_ex(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y)
141148
{
142149
timelib_sll dow, day;
143150

144151
/* Figure out the dayofweek for y-1-1 */
145-
dow = timelib_day_of_week(y, 1, 1);
152+
dow = timelib_day_of_week(iy, 1, 1);
146153
/* then use that to figure out the offset for day 1 of week 1 */
147154
day = 0 - (dow > 4 ? dow - 7 : dow);
155+
/* and adjust the year to the natural year if we need to */
156+
*y = (iw == 1 && day < 0 && id < dow) ? iy - 1 : iy;
148157

149158
/* Add weeks and days */
150-
return day + ((w - 1) * 7) + d;
159+
return day + ((iw - 1) * 7) + id;
160+
}
161+
162+
timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id)
163+
{
164+
timelib_sll dummy_iso_year;
165+
166+
return timelib_daynr_from_weeknr_ex(iy, iw, id, &dummy_iso_year);
167+
}
168+
169+
void timelib_date_from_isodate(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y, timelib_sll *m, timelib_sll *d)
170+
{
171+
timelib_sll daynr = timelib_daynr_from_weeknr_ex(iy, iw, id, y) + 1;
172+
int *table;
173+
174+
*m = 0;
175+
176+
if (daynr <= 0) {
177+
*y += 1;
178+
}
179+
180+
if (timelib_is_leap(*y)) {
181+
table = ml_table_leap;
182+
if (daynr > 366) {
183+
*y += 1;
184+
daynr -= 366;
185+
}
186+
} else {
187+
table = ml_table_common;
188+
if (daynr > 365) {
189+
*y += 1;
190+
daynr -= 365;
191+
}
192+
}
193+
194+
do {
195+
daynr -= table[*m];
196+
(*m)++;
197+
} while (daynr > table[*m]);
198+
199+
if (daynr <= 0) {
200+
daynr += 31;
201+
*y -= 1;
202+
*m = 12;
203+
}
204+
205+
*d = daynr;
151206
}
152207

153208
int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s)

ext/date/lib/fallbackmap.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
{ "sst", 0, -660, "Pacific/Apia" },
2-
{ "hst", 0, -600, "Pacific/Honolulu" },
3-
{ "akst", 0, -540, "America/Anchorage" },
4-
{ "akdt", 1, -480, "America/Anchorage" },
5-
{ "pst", 0, -480, "America/Los_Angeles" },
6-
{ "pdt", 1, -420, "America/Los_Angeles" },
7-
{ "mst", 0, -420, "America/Denver" },
8-
{ "mdt", 1, -360, "America/Denver" },
9-
{ "cst", 0, -360, "America/Chicago" },
10-
{ "cdt", 1, -300, "America/Chicago" },
11-
{ "est", 0, -300, "America/New_York" },
12-
{ "vet", 0, -270, "America/Caracas" },
13-
{ "edt", 1, -240, "America/New_York" },
14-
{ "ast", 0, -240, "America/Halifax" },
15-
{ "adt", 1, -180, "America/Halifax" },
16-
{ "brt", 0, -180, "America/Sao_Paulo" },
17-
{ "brst", 1, -120, "America/Sao_Paulo" },
18-
{ "azost", 0, -60, "Atlantic/Azores" },
19-
{ "azodt", 1, 0, "Atlantic/Azores" },
20-
{ "gmt", 0, 0, "Europe/London" },
21-
{ "bst", 1, 60, "Europe/London" },
22-
{ "cet", 0, 60, "Europe/Paris" },
23-
{ "cest", 1, 120, "Europe/Paris" },
24-
{ "eet", 0, 120, "Europe/Helsinki" },
25-
{ "eest", 1, 180, "Europe/Helsinki" },
26-
{ "msk", 0, 180, "Europe/Moscow" },
27-
{ "msd", 1, 240, "Europe/Moscow" },
28-
{ "gst", 0, 240, "Asia/Dubai" },
29-
{ "pkt", 0, 300, "Asia/Karachi" },
30-
{ "ist", 0, 330, "Asia/Kolkata" },
31-
{ "npt", 0, 345, "Asia/Katmandu" },
32-
{ "yekt", 1, 360, "Asia/Yekaterinburg" },
33-
{ "novst", 1, 420, "Asia/Novosibirsk" },
34-
{ "krat", 0, 420, "Asia/Krasnoyarsk" },
35-
{ "cst", 0, 480, "Asia/Shanghai" },
36-
{ "krast", 1, 480, "Asia/Krasnoyarsk" },
37-
{ "jst", 0, 540, "Asia/Tokyo" },
38-
{ "est", 0, 600, "Australia/Melbourne" },
39-
{ "cst", 1, 630, "Australia/Adelaide" },
40-
{ "est", 1, 660, "Australia/Melbourne" },
41-
{ "nzst", 0, 720, "Pacific/Auckland" },
42-
{ "nzdt", 1, 780, "Pacific/Auckland" },
1+
{ "sst", 0, -660 * 60, "Pacific/Apia" },
2+
{ "hst", 0, -600 * 60, "Pacific/Honolulu" },
3+
{ "akst", 0, -540 * 60, "America/Anchorage" },
4+
{ "akdt", 1, -480 * 60, "America/Anchorage" },
5+
{ "pst", 0, -480 * 60, "America/Los_Angeles" },
6+
{ "pdt", 1, -420 * 60, "America/Los_Angeles" },
7+
{ "mst", 0, -420 * 60, "America/Denver" },
8+
{ "mdt", 1, -360 * 60, "America/Denver" },
9+
{ "cst", 0, -360 * 60, "America/Chicago" },
10+
{ "cdt", 1, -300 * 60, "America/Chicago" },
11+
{ "est", 0, -300 * 60, "America/New_York" },
12+
{ "vet", 0, -270 * 60, "America/Caracas" },
13+
{ "edt", 1, -240 * 60, "America/New_York" },
14+
{ "ast", 0, -240 * 60, "America/Halifax" },
15+
{ "adt", 1, -180 * 60, "America/Halifax" },
16+
{ "brt", 0, -180 * 60, "America/Sao_Paulo" },
17+
{ "brst", 1, -120 * 60, "America/Sao_Paulo" },
18+
{ "azost", 0, -60 * 60, "Atlantic/Azores" },
19+
{ "azodt", 1, 0 * 60, "Atlantic/Azores" },
20+
{ "gmt", 0, 0 * 60, "Europe/London" },
21+
{ "bst", 1, 60 * 60, "Europe/London" },
22+
{ "cet", 0, 60 * 60, "Europe/Paris" },
23+
{ "cest", 1, 120 * 60, "Europe/Paris" },
24+
{ "eet", 0, 120 * 60, "Europe/Helsinki" },
25+
{ "eest", 1, 180 * 60, "Europe/Helsinki" },
26+
{ "msk", 0, 180 * 60, "Europe/Moscow" },
27+
{ "msd", 1, 240 * 60, "Europe/Moscow" },
28+
{ "gst", 0, 240 * 60, "Asia/Dubai" },
29+
{ "pkt", 0, 300 * 60, "Asia/Karachi" },
30+
{ "ist", 0, 330 * 60, "Asia/Kolkata" },
31+
{ "npt", 0, 345 * 60, "Asia/Katmandu" },
32+
{ "yekt", 1, 360 * 60, "Asia/Yekaterinburg" },
33+
{ "novst", 1, 420 * 60, "Asia/Novosibirsk" },
34+
{ "krat", 0, 420 * 60, "Asia/Krasnoyarsk" },
35+
{ "cst", 0, 480 * 60, "Asia/Shanghai" },
36+
{ "krast", 1, 480 * 60, "Asia/Krasnoyarsk" },
37+
{ "jst", 0, 540 * 60, "Asia/Tokyo" },
38+
{ "est", 0, 600 * 60, "Australia/Melbourne" },
39+
{ "cst", 1, 630 * 60, "Australia/Adelaide" },
40+
{ "est", 1, 660 * 60, "Australia/Melbourne" },
41+
{ "nzst", 0, 720 * 60, "Pacific/Auckland" },
42+
{ "nzdt", 1, 780 * 60, "Pacific/Auckland" },

ext/date/lib/interval.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "timelib.h"
26+
#include "timelib_private.h"
2627
#include <math.h>
2728

2829
timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
@@ -65,7 +66,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
6566
rt->h = two->h - one->h;
6667
rt->i = two->i - one->i;
6768
rt->s = two->s - one->s;
68-
rt->f = two->f - one->f;
69+
rt->us = two->us - one->us;
6970
if (one_backup.dst == 0 && two_backup.dst == 1 && two->sse >= one->sse + 86400 - dst_corr) {
7071
rt->h += dst_h_corr;
7172
rt->i += dst_m_corr;
@@ -111,7 +112,7 @@ timelib_time *timelib_add(timelib_time *old_time, timelib_rel_time *interval)
111112
t->relative.h = interval->h * bias;
112113
t->relative.i = interval->i * bias;
113114
t->relative.s = interval->s * bias;
114-
t->relative.f = interval->f * bias;
115+
t->relative.us = interval->us * bias;
115116
}
116117
t->have_relative = 1;
117118
t->sse_uptodate = 0;
@@ -147,7 +148,7 @@ timelib_time *timelib_sub(timelib_time *old_time, timelib_rel_time *interval)
147148
t->relative.h = 0 - (interval->h * bias);
148149
t->relative.i = 0 - (interval->i * bias);
149150
t->relative.s = 0 - (interval->s * bias);
150-
t->relative.f = 0 - (interval->f * bias);
151+
t->relative.us = 0 - (interval->us * bias);
151152
t->have_relative = 1;
152153
t->sse_uptodate = 0;
153154

0 commit comments

Comments
 (0)