Skip to content

Commit 2220e79

Browse files
committed
Fix ext/calendar
1 parent 3a91455 commit 2220e79

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

ext/calendar/easter.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "php.h"
2121
#include "php_calendar.h"
2222
#include "sdncal.h"
23+
#include "../date/lib/timelib.h"
2324
#include <time.h>
2425

2526
/**
@@ -30,7 +31,7 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm)
3031
{
3132
/* based on code by Simon Kershaw, <[email protected]> */
3233

33-
struct tm te;
34+
timelib_time *t;
3435
zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result;
3536
zend_long method = CAL_EASTER_DEFAULT;
3637
const zend_long max_year = (zend_long)(ZEND_LONG_MAX / 5) * 4;
@@ -59,7 +60,7 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm)
5960
RETURN_THROWS();
6061
}
6162

62-
#ifdef ZEND_ENABLE_ZVAL_LONG64
63+
#ifdef ZEND_ENABLE_ZVAL_LONG64
6364
/* Compiling for 64bit, allow years between 1970 and 2.000.000.000 */
6465
if (gm && year < 1970) {
6566
/* timestamps only start after 1970 */
@@ -72,13 +73,13 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm)
7273
zend_argument_value_error(1, "must be a year before 2.000.000.000 (inclusive)");
7374
RETURN_THROWS();
7475
}
75-
#else
76+
#else
7677
/* Compiling for 32bit, allow years between 1970 and 2037 */
7778
if (gm && (year < 1970 || year > 2037)) {
7879
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
7980
RETURN_THROWS();
8081
}
81-
#endif
82+
#endif
8283

8384

8485
golden = (year % 19) + 1; /* the Golden number */
@@ -123,20 +124,26 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm)
123124
easter = pfm + tmp + 1; /* Easter as the number of days after 21st March */
124125

125126
if (gm) { /* return a timestamp */
126-
te.tm_isdst = -1;
127-
te.tm_year = year-1900;
128-
te.tm_sec = 0;
129-
te.tm_min = 0;
130-
te.tm_hour = 0;
127+
t = timelib_time_ctor();
128+
t->us = 0;
129+
t->s = 0;
130+
t->i = 0;
131+
t->h = 0;
132+
t->y = year;
133+
t->z = 0;
134+
t->dst = -1;
131135

132136
if (easter < 11) {
133-
te.tm_mon = 2; /* March */
134-
te.tm_mday = easter+21;
137+
t->m = 3;
138+
t->d = easter+21;
135139
} else {
136-
te.tm_mon = 3; /* April */
137-
te.tm_mday = easter-10;
140+
t->m = 4;
141+
t->d = easter-10;
138142
}
139-
result = mktime(&te);
143+
144+
timelib_update_ts(t, NULL);
145+
result = t->sse;
146+
timelib_time_dtor(t);
140147
} else { /* return the days after March 21 */
141148
result = easter;
142149
}

0 commit comments

Comments
 (0)