Re: com php-src: Fixed day_of_week function as it could sometimes return negative values internally.: ext/date/lib/dow.c
ext/date/tests/DateTime_setISODate_variation1.phpt ext/date/tests/bug49585.phpt ext/date/tests/date_isodate_set_variation2.phpt
ext/date/tests/getdate_variation7.phpt ext/date/tests/localtime_variation3.phpt

From: Date: Tue, 09 Dec 2014 12:11:44 +0000
Subject: Re: com php-src: Fixed day_of_week function as it could sometimes return negative values internally.: ext/date/lib/dow.c
ext/date/tests/DateTime_setISODate_variation1.phpt ext/date/tests/bug49585.phpt ext/date/tests/date_isodate_set_variation2.phpt
ext/date/tests/getdate_variation7.phpt ext/date/tests/localtime_variation3.phpt
References: 1 2  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-83574@lists.php.net to get a copy of this message
On Tue, 9 Dec 2014, Dmitry Stogov wrote: > Hi Derick, > > Interesting, but the following two tests started to fail for me. Hmm, I thought I fixed them all. Which branches is this on? cheers, Derick > > Thanks. Dmitry. > > > Test getdate() function : usage variation - Passing high positive and > negative float values to timestamp. [ext/date/tests/getdate_variation7.phpt] > > Test localtime() function : usage variation - Passing higher positive and > negetive float values to timestamp. > [ext/date/tests/localtime_variation3.phpt] > > $ cat ../ext/date/tests/getdate_variation7.diff > 040+ int(6) > 040- int\(0\) > 048+ string(8) "Saturday" > 048- string\(6\) "Sunday" > > $ cat ../ext/date/tests/localtime_variation3.diff > 060+ int(5) > 060- int\(6\) > 080+ int(5) > 080- int\(6\) > > > > On Mon, Dec 8, 2014 at 2:06 PM, Derick Rethans <derick@php.net> wrote: > > > Commit: 5f9a68d3efe7b76b5cf957285519a9b043fa956c > > Author: Derick Rethans <github@derickrethans.nl> Mon, 8 Dec > > 2014 11:06:12 +0000 > > Parents: e6ad29ae96caec9353e42d528895bf2bec02a125 > > Branches: PHP-5.5 PHP-5.6 master > > > > Link: > > > > http://git.php.net/?p=php-src.git;a=commitdiff;h=5f9a68d3efe7b76b5cf957285519a9b043fa956c > > > > Log: > > Fixed day_of_week function as it could sometimes return negative values > > internally. > > > > Changed paths: > > M ext/date/lib/dow.c > > M ext/date/tests/DateTime_setISODate_variation1.phpt > > M ext/date/tests/bug49585.phpt > > M ext/date/tests/date_isodate_set_variation2.phpt > > M ext/date/tests/getdate_variation7.phpt > > M ext/date/tests/localtime_variation3.phpt > > > > > > Diff: > > diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c > > index a77fdd7..ccfea99 100644 > > --- a/ext/date/lib/dow.c > > +++ b/ext/date/lib/dow.c > > @@ -23,9 +23,21 @@ > > 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) > > @@ -36,9 +48,9 @@ static timelib_sll timelib_day_of_week_ex(timelib_sll y, > > timelib_sll m, timelib_ > > * 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; > > diff --git a/ext/date/tests/DateTime_setISODate_variation1.phpt > > b/ext/date/tests/DateTime_setISODate_variation1.phpt > > index d685f27..a4e8865 100644 > > --- a/ext/date/tests/DateTime_setISODate_variation1.phpt > > +++ b/ext/date/tests/DateTime_setISODate_variation1.phpt > > @@ -145,7 +145,7 @@ object(DateTime)#%d (3) { > > -- 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"]=> > > @@ -165,7 +165,7 @@ object(DateTime)#%d (3) { > > -- 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"]=> > > diff --git a/ext/date/tests/bug49585.phpt b/ext/date/tests/bug49585.phpt > > index 2ec1424..d21bba6 100644 > > --- a/ext/date/tests/bug49585.phpt > > +++ b/ext/date/tests/bug49585.phpt > > @@ -10,7 +10,8 @@ var_dump($date->format('r')); > > $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" > > diff --git a/ext/date/tests/date_isodate_set_variation2.phpt > > b/ext/date/tests/date_isodate_set_variation2.phpt > > index 5b59a69..3c3b692 100644 > > --- a/ext/date/tests/date_isodate_set_variation2.phpt > > +++ b/ext/date/tests/date_isodate_set_variation2.phpt > > @@ -145,7 +145,7 @@ object(DateTime)#%d (3) { > > -- 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"]=> > > @@ -165,7 +165,7 @@ object(DateTime)#%d (3) { > > -- 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"]=> > > diff --git a/ext/date/tests/getdate_variation7.phpt > > b/ext/date/tests/getdate_variation7.phpt > > index 5af2dd5..2088fa1 100644 > > --- a/ext/date/tests/getdate_variation7.phpt > > +++ b/ext/date/tests/getdate_variation7.phpt > > @@ -61,7 +61,7 @@ array\(11\) { > > \["mday"\]=> > > int\((9|14|23)\) > > \["wday"\]=> > > - int\((6|-4)\) > > + int\(0\) > > \["mon"\]=> > > int\((10|12)\) > > \["year"\]=> > > @@ -69,7 +69,7 @@ array\(11\) { > > \["yday"\]=> > > int\((282|347|295)\) > > \["weekday"\]=> > > - string\((8|7)\) "(Saturday|Unknown)" > > + string\(6\) "Sunday" > > \["month"\]=> > > string\((7|8)\) "(October|December)" > > \[0\]=> > > diff --git a/ext/date/tests/localtime_variation3.phpt > > b/ext/date/tests/localtime_variation3.phpt > > index d941e38..34d8f57 100644 > > --- a/ext/date/tests/localtime_variation3.phpt > > +++ b/ext/date/tests/localtime_variation3.phpt > > @@ -87,7 +87,7 @@ array\(9\) { > > \[5\]=> > > int\((104|1|-3843)\) > > \[6\]=> > > - int\((5|-5)\) > > + int\(6\) > > \[7\]=> > > int\((281|346|294)\) > > \[8\]=> > > @@ -107,7 +107,7 @@ array\(9\) { > > \["tm_year"\]=> > > int\((104|1|-3843)\) > > \["tm_wday"\]=> > > - int\((5|-5)\) > > + int\(6\) > > \["tm_yday"\]=> > > int\((281|346|294)\) > > \["tm_isdst"\]=> > > > > > > -- > > PHP CVS Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug Posted with an email client that doesn't mangle email: alpine

« previous php.cvs (#83574) next »