static int m_table_common[13] = { -1, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
static int m_table_leap[13] = { -1, 6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
+static timelib_sll positive_mod(timelib_sll x, timelib_sll y)
+{
+ timelib_sll tmp;
+
+ tmp = x % y;
+ if (tmp < 0) {
+ tmp += y;
+ }
+
+ return tmp;
+}
+
static timelib_sll century_value(timelib_sll j)
{
- return 6 - (j % 4) * 2;
+ return 6 - positive_mod(j, 4) * 2;
}
static timelib_sll timelib_day_of_week_ex(timelib_sll y, timelib_sll m, timelib_sll d, int iso)
* Julian calendar. We just return the 'wrong' day of week to be
* consistent. */
c1 = century_value(y / 100);
- y1 = (y % 100);
+ y1 = positive_mod(y, 100);
m1 = timelib_is_leap(y) ? m_table_leap[m] : m_table_common[m];
- dow = (c1 + y1 + m1 + (y1 / 4) + d) % 7;
+ dow = positive_mod((c1 + y1 + m1 + (y1 / 4) + d), 7);
if (iso) {
if (dow == 0) {
dow = 7;
-- int -12345 --
object(DateTime)#%d (3) {
["date"]=>
- string(28) "-12345-02-15 08:34:10.000000"
+ string(28) "-12345-02-11 08:34:10.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
-- float -10.5 --
object(DateTime)#%d (3) {
["date"]=>
- string(27) "-0010-02-19 08:34:10.000000"
+ string(27) "-0010-02-14 08:34:10.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
$date->setDate(-2147483648, 1, 1);
var_dump($date->format('r'));
var_dump($date->format('c'));
+?>
--EXPECT--
-string(32) "Sat, 01 Jan -1500 00:00:00 +0000"
-string(42) "Unknown, 01 Jan -2147483648 00:00:00 +0000"
+string(32) "Fri, 01 Jan -1500 00:00:00 +0000"
+string(38) "Mon, 01 Jan -2147483648 00:00:00 +0000"
string(32) "-2147483648-01-01T00:00:00+00:00"
-- int -12345 --
object(DateTime)#%d (3) {
["date"]=>
- string(28) "-12345-02-15 08:34:10.000000"
+ string(28) "-12345-02-11 08:34:10.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
-- float -10.5 --
object(DateTime)#%d (3) {
["date"]=>
- string(27) "-0010-02-19 08:34:10.000000"
+ string(27) "-0010-02-14 08:34:10.000000"
["timezone_type"]=>
int(3)
["timezone"]=>