#20382 [Fbk->Opn]: strtotime ("Monday", $date) can produce incorrect output

2005-06-18 Thread nickj-phpbugs at nickj dot org
 ID:   20382
 User updated by:  nickj-phpbugs at nickj dot org
 Reported By:  nickj-phpbugs at nickj dot org
-Status:   Feedback
+Status:   Open
 Bug Type: Date/time related
 Operating System: *
 PHP Version:  5CVS, 4CVS (2004-04-13)
 Assigned To:  derick
 New Comment:

That's a lot better, it takes much longer to find problems, but there
are still some cases it doesn't seem to work on (using the same Debian
GNU/Linux Woody 3.0r6 system), such as:

===



===

Which for me gives:

===
ludo:~/tmp/php-5.1-dev/php5-200506182230/sapi/cli# ./php
~/test/19-june-2005-linux-strtotime-tests.php 
tStamp=Monday 1983-04-11 17:17:17 CET
result=Monday 1983-04-18 01:00:00 CEST
wanted=Monday00:00:00

tStamp=Wednesday 1981-03-25 17:17:17 YERT
result=Wednesday 1981-04-01 01:00:00 YERST
wanted=Wednesday00:00:00

tStamp=Wednesday 1974-01-16 17:17:17 ART
result=Wednesday 1974-01-23 01:00:00 ARST
wanted=Wednesday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1974-09-30 17:17:17 ART
result=Monday 1974-10-07 01:00:00 ARST
wanted=Monday00:00:00

tStamp=Monday 1980-03-31 17:17:17 CET
result=Sunday 1980-04-06 23:00:00 CET
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 EST
result=Sunday 1970-01-04 23:00:00 EST
wanted=Monday00:00:00

tStamp=Monday 1995-12-25 17:17:17 AZT
result=Monday 1996-01-01 01:00:00 AZST
wanted=Monday00:00:00

ludo:~/tmp/php-5.1-dev/php5-200506182230/sapi/cli# 
===

> About the Windows tests, they are not going to work yet because
> on Windows the date() function doesn't understand timezone 
> names like "Asia/Dubai". This is going to be implement before
> 5.1 is released if I have the time.

No worries; If this does get added, feel free to let me know, and I can
rerun some of the date-related tests on the Win32 platform.


Previous Comments:


[2005-06-18 16:10:54] [EMAIL PROTECTED]

All those tests run fine for me, perhaps my latest commit already
changed this, so please try a new snapshot.

About the WIndows tests, they are not going to work yet because on
Windows the date() function doesn't understand timezone names like
"Asia/Dubai". This is going to be implement before 5.1 is released if I
have the time.



[2005-06-18 01:29:54] nickj-phpbugs at nickj dot org

Reopening, as the original test case is now working correctly (thank
you!), but there are others that don't appear to be producing the
expected results.

The ones that don't work seem to differ between operating systems. For
Linux, I've included some of these below as a series of ten small,
separate, simple test cases, structured in the format you've indicated
you prefer. Then below that I've included another ten cases for Windows
2000 systems, in the same format:

==

==
Results (on my system, a Debian GNU/Linux Woody 3.0r6 box), are as
follows:


ludo:~/tmp/php-5.1-dev/php5-200506170030/sapi/cli# ./php
~/test/test-output.php 
tStamp=Monday 2037-10-19 17:17:17 CEST
result=Monday 2037-10-26 01:00:00 CET
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 GST
result=Monday 1970-01-05 04:00:00 GST
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 AFT
result=Monday 1970-01-05 04:30:00 AFT
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 AST
result=Sunday 1970-01-04 20:00:00 AST
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 AST
result=Sunday 1970-01-04 20:00:00 AST
wanted=Monday00:00:00

tStamp=Monday 1983-04-11 17:17:17 CET
result=Monday 1983-04-18 01:00:00 CEST
wanted=Monday00:00:00

tStamp=Monday 2037-10-19 17:17:17 AMST
result=Monday 2037-10-26 04:00:00 AMT
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 AST
result=Sunday 1970-01-04 20:00:00 AST
wanted=Monday00:00:00

tStamp=Thursday 1970-01-01 17:17:17 WAT
result=Monday 1970-01-05 01:00:00 WAT
wanted=Monday

#20382 [Fbk->Opn]: strtotime ("Monday", $date) can produce incorrect output

2002-11-26 Thread sniper
 ID:   20382
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
-Status:   Feedback
+Status:   Open
 Bug Type: Date/time related
 Operating System: Linux Mandrake 7.2
 PHP Version:  4.3.0-dev


Previous Comments:


[2002-11-21 23:42:22] [EMAIL PROTECTED]

Ran the automated-date-test script on a different box, this one running
windows 2000 SP2 (previously was Mandrake Linux 7.2), using the latest
available snapshot of the 4.4.0-dev tree (was php4-win32-200211220330),
and it produced the same list of incorrect dates as in the above
comment.



[2002-11-12 19:46:28] [EMAIL PROTECTED]

OK, I decided that was needed was some kind of automated testing, so I
wrote it:

#!/root/php4-200211122230 -q
 7, "Monday" => 1, "Tuesday" => 2,
"Wednesday" => 3,
"Thursday" => 4, "Friday" => 5, "Saturday"
=> 6);

// convert into a number
$desired_day_of_week_number = $weekdays[$desired_day_of_week];

// see what day we have currently
list ($year, $month, $day) = explode ("-",$date);
$date_day_of_week = date("w", mktime
(17,17,17,$month,$day,$year));

$new_day = $day+(($desired_day_of_week_number-$date_day_of_week)+7) %
7;
return date("Y-n-j", mktime (17,17,17,$month,$new_day,$year));
}


// run an automated test to compare the output of these two functions,
and complain if they differ
for ($i=1; $i<1000; $i++) {
$date =  date("Y-n-j", mktime (17,17,17,1,$i,1999));
$strtotime_date = getDateWithModifier($date, "Monday");
$other_date = getDayOfTheWeekFromDate($date, "Monday");
if ($strtotime_date != $other_date) {
print "Discrepancy for $date - results were $strtotime_date vs
$other_date\n";
}
}

print "PHP version: " . phpversion(). "\n";

?>



Here's the output that I get:

[root@www tmp]# ./automated-date-test.php 
Discrepancy for 1999-3-23 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 1999-3-24 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 1999-3-25 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 1999-3-26 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 1999-3-27 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 1999-3-28 - results were 1999-3-28 vs 1999-3-29
Discrepancy for 2000-3-21 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2000-3-22 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2000-3-23 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2000-3-24 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2000-3-25 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2000-3-26 - results were 2000-3-26 vs 2000-3-27
Discrepancy for 2001-3-20 - results were 2001-3-25 vs 2001-3-26
Discrepancy for 2001-3-21 - results were 2001-3-25 vs 2001-3-26
Discrepancy for 2001-3-22 - results were 2001-3-25 vs 2001-3-26
Discrepancy for 2001-3-23 - results were 2001-3-25 vs 2001-3-26
Discrepancy for 2001-3-24 - results were 2001-3-25 vs 2001-3-26
Discrepancy for 2001-3-25 - results were 2001-3-25 vs 2001-3-26
PHP version: 4.3.0-dev
[root@www tmp]# 


In other words, the result for these 6 days of the year consistently
appears to be wrong. (I suppose I should be glad that the very first
date I choose to test this function with just by fluke happened to be
one of those 6 days, as opposed to causing mysterious problems later!)


Does anyone else get any results that appear incorrect on running this
script?



[2002-11-12 19:25:41] [EMAIL PROTECTED]

No problem - Modified script slightly, as shown below, to use
gmmktime(), and to also print out the before and after timestamps.
Source:
=
#!/root/php4-200211122230 -q
\n";
print "2001-3-17, goto mon: " . getDateWithModifier("2001-3-17",
"Monday") . "; should be 2001-3-19.\n";
print "2001-3-18, goto mon: " . getDateWithModifier("2001-3-18",
"Monday") . "; should be 2001-3-19.\n";
print "2001-3-19, goto mon: " . getDateWithModifier("2001-3-19",
"Monday") . "; should be 2001-3-19.\n";
print "2001-3-20, goto mon: " . getDateWithModifier("2001-3-20",
"Monday") . "; should be 2001-3-26 ###.\n";
print "2001-3-21, goto mon: " . getDateWithModifier("2001-3-21",
"Monday") . "; should be 2001-3-26 ###.\n";
print "2001-3-22, goto mon: " . getDateWithModifier("2001-3-22",
"Monday") . "; should be 2001-3-26 ###.\n";
print "2001-3-23, goto mon: " . getDateWithModifier("2001-3-23",
"Monday") . "; should be 2001-3-26 ###.\n";
print "2001-3-24, goto mon: " . getDateWithModifier("2001-3-24",
"Mon