#40271 [Opn]: strtotime() produces unexpected results while using Day of week items

2007-01-29 Thread slomo at sonarkollektiv dot de
 ID:   40271
 User updated by:  slomo at sonarkollektiv dot de
 Reported By:  slomo at sonarkollektiv dot de
 Status:   Open
 Bug Type: Date/time related
 Operating System: Mac OS X 10.4.8
 PHP Version:  5.2.0
 New Comment:

code :
strtotime('1999-01-04 UTC + 1 week last monday');
strtotime('1999-01-11 UTC + 0 week last monday');

actual result:
916012800
915408000

expected result:
at least the same value

Another example

code :
strtotime('1999-01-04 UTC + 0 week last monday');
strtotime('1999-01-04 UTC + 1 week last monday');
strtotime('1999-01-04 UTC + 2 week last monday');

actual result:
914803200
916012800
916617600

expected result:
at least always the same gap (604800 is a week), but it 
differs


Previous Comments:


[2007-01-29 12:02:37] slomo at sonarkollektiv dot de

thanks [EMAIL PROTECTED], that's brilliant :)

and it seems to be bug free. I still think my code produced a 
bug in PHP and I do not get why this happens.



[2007-01-29 12:01:58] [EMAIL PROTECTED]

Could you please just paste something like this:
code :
strftime(something)

actual result:
something you can actually see

expected result:
something you expected to see

I really don't think those functions, cycles and HTML output are
required to demonstrate a problem with strftime().




[2007-01-29 11:55:33] slomo at sonarkollektiv dot de

My Reproduce code was quite complete. Here it is again, 
this time it starts with ?php and ends with ? :-)

I expect: using strtotime(last monday) should behave 
always the same. If you run my code you will see that it 
differs depending on the given date. My code is not complex, 
so I hope you get the point very soon.

This Day of week items are a little bit confusing, because 
if you have e.g. a $date for a monday and state strtotime
($date last monday), you get $date. I assume this is 
correct.

Anyway I would think it's just my fault if my function would 
be off 1 week for the whole year if the date is a monday 
every time. But this happens only for the first week, in any 
other week the result is like I learned strtotime() is doing 
it.

Can you follow?

?php

function MondayOfWeek($year, $week) { 
return strtotime($year-01-04 UTC +  . ($week-1) . ' 
week last monday');
} 

for ($y = 1998; $y  2012; $y++) {
for ($w = 1; $w  53; $w++) {
$start = MondayOfWeek($y, $w);
$end   = strtotime(+6 day, $start);

echo KW $w/$y:  . gmstrftime('%A, %x %X', $start) 
. ' - ' . gmstrftime('%A, %x %X', $end) . ' - reverse check 
(week/year): ' . gmstrftime('%V/%G', $start) . br /\n;

if ($w != gmstrftime('%V', $start) || $y != 
gmstrftime('%G', $start)) {
echo 'span style=color: red;Oops, 
EXCEPTIONAL ERROR!/span' . br /\n;
}
}
echo hr\n;
}

?

best regards,
  slomo



[2007-01-29 11:50:06] [EMAIL PROTECTED]

You can also just use strtotime('2007W011'); for Monday 1, of Week
1 (01) of year 2007 (2007).



[2007-01-29 11:33:36] [EMAIL PROTECTED]

And please do not forget about expected and actual results.
Thank you.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/40271

-- 
Edit this bug report at http://bugs.php.net/?id=40271edit=1


#40271 [Opn]: strtotime() produces unexpected results while using Day of week items

2007-01-29 Thread slomo at sonarkollektiv dot de
 ID:   40271
 User updated by:  slomo at sonarkollektiv dot de
 Reported By:  slomo at sonarkollektiv dot de
 Status:   Open
 Bug Type: Date/time related
 Operating System: Mac OS X 10.4.8
 PHP Version:  5.2.0
 New Comment:

Just to point out why I think somethings weird, compare the 
previous code and result to this one.

code:
strtotime('2000-01-04 UTC + 1 week last monday');
strtotime('2000-01-11 UTC + 0 week last monday');

actual result:
947462400
947462400

expected result:
947462400
947462400

 same value, fine.

And the same for

code:
strtotime('2000-01-04 UTC + 0 week last monday');
strtotime('2000-01-04 UTC + 1 week last monday');
strtotime('2000-01-04 UTC + 2 week last monday');

actual result:
946857600
947462400
948067200

expected result:
946857600
947462400
948067200

 always the same gap (604800 is a week), fine.


Previous Comments:


[2007-01-29 12:22:42] slomo at sonarkollektiv dot de

code :
strtotime('1999-01-04 UTC + 1 week last monday');
strtotime('1999-01-11 UTC + 0 week last monday');

actual result:
916012800
915408000

expected result:
at least the same value

Another example

code :
strtotime('1999-01-04 UTC + 0 week last monday');
strtotime('1999-01-04 UTC + 1 week last monday');
strtotime('1999-01-04 UTC + 2 week last monday');

actual result:
914803200
916012800
916617600

expected result:
at least always the same gap (604800 is a week), but it 
differs



[2007-01-29 12:02:37] slomo at sonarkollektiv dot de

thanks [EMAIL PROTECTED], that's brilliant :)

and it seems to be bug free. I still think my code produced a 
bug in PHP and I do not get why this happens.



[2007-01-29 12:01:58] [EMAIL PROTECTED]

Could you please just paste something like this:
code :
strftime(something)

actual result:
something you can actually see

expected result:
something you expected to see

I really don't think those functions, cycles and HTML output are
required to demonstrate a problem with strftime().




[2007-01-29 11:55:33] slomo at sonarkollektiv dot de

My Reproduce code was quite complete. Here it is again, 
this time it starts with ?php and ends with ? :-)

I expect: using strtotime(last monday) should behave 
always the same. If you run my code you will see that it 
differs depending on the given date. My code is not complex, 
so I hope you get the point very soon.

This Day of week items are a little bit confusing, because 
if you have e.g. a $date for a monday and state strtotime
($date last monday), you get $date. I assume this is 
correct.

Anyway I would think it's just my fault if my function would 
be off 1 week for the whole year if the date is a monday 
every time. But this happens only for the first week, in any 
other week the result is like I learned strtotime() is doing 
it.

Can you follow?

?php

function MondayOfWeek($year, $week) { 
return strtotime($year-01-04 UTC +  . ($week-1) . ' 
week last monday');
} 

for ($y = 1998; $y  2012; $y++) {
for ($w = 1; $w  53; $w++) {
$start = MondayOfWeek($y, $w);
$end   = strtotime(+6 day, $start);

echo KW $w/$y:  . gmstrftime('%A, %x %X', $start) 
. ' - ' . gmstrftime('%A, %x %X', $end) . ' - reverse check 
(week/year): ' . gmstrftime('%V/%G', $start) . br /\n;

if ($w != gmstrftime('%V', $start) || $y != 
gmstrftime('%G', $start)) {
echo 'span style=color: red;Oops, 
EXCEPTIONAL ERROR!/span' . br /\n;
}
}
echo hr\n;
}

?

best regards,
  slomo



[2007-01-29 11:50:06] [EMAIL PROTECTED]

You can also just use strtotime('2007W011'); for Monday 1, of Week
1 (01) of year 2007 (2007).



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/40271

-- 
Edit this bug report at http://bugs.php.net/?id=40271edit=1