php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21933 Date/Sec bug
Submitted: 2003-01-29 03:48 UTC Modified: 2003-01-29 13:06 UTC
From: kepesk at peto dot hu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.0 OS: WinXP
Private report: No CVE-ID: None
 [2003-01-29 03:48 UTC] kepesk at peto dot hu
When I run this script, it has make an error.
While I increment the an date with secsperday, it is make an wrong result !

The example:

<?php

 define("SECSPERMIN",60);
 define("MINSPERHOUR",60);
 define("HOURSPERDAY",24);
 define("SECSPERHOUR",SECSPERMIN*MINSPERHOUR);
 define("SECSPERDAY",SECSPERHOUR*HOURSPERDAY);


 function TimeToStr($time){
  $str="";
  $dt=GetDate($time);
  $str= sprintf("%02d",$dt['hours']).":".sprintf("%02d",$dt['minutes']).":".sprintf("%02d",$dt['seconds']);
  return($str);
 }

 function DateToStr($date) {
  $str="";
  $dt=GetDate($date);
  $str=$dt['year'].'.'.sprintf("%02d",$dt['mon']).'.'.sprintf("%02d",$dt['mday']);
  return($str);
  };

 function DateTimeToStr($datetime) {
  $r=DateToStr($datetime).' '.TimeToStr($datetime);
  return($r);
 }

 function EncodeDate($y,$m,$d){
  #printbr("$y $m $d");
  if (!checkdate($m,$d,$y)) return(-1);
  $res=mktime(0,0,0, $m, $d, $y);
  return($res) ;
 }

 function DecodeDate($date,&$y,&$m,&$d){
  $y=-1;$m=-1;$d=-1;
  $dt=GetDate($date);if($dt===False) return(False);
  $y=$dt['year'];
  $m=$dt['mon'];
  $d=$dt['mday'];
 }

 print "<html>\n";

 $date=EncodeDate(2003,01,01);
 for ($i=0;$i<1000;$i++) {
  DecodeDate($date,$y,$m,$d);
  $a1=DateTimeToStr($date);
  $date2=EncodeDate($y,$m,$d);
  $a2=DateTimeToStr($date);
  print "$date $a1 <-> $date2 $a2<br>\n";
  if (($a1<>$a2) or ($date<>$date2)) {print "!!!! ERROR !!!!<br>\n"; exit;}
  $date=$date+SECSPERDAY;
 }
 print "DONE WITHOUT ERRORS !<br>\n";
 print '</html>';
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-29 13:01 UTC] michael dot mauch at gmx dot de
When I run your script, it exits at this line:
1049065200 2003.03.31 01:00:00 <-> 1049061600 2003.03.31 01:00:00
!!!! ERROR !!!!

As you can see on <http://greenwichmeantime.com/local/europe/hu.htm>, March 30th does not have 24*60*60 seconds, because that's when Hungary switches to daylight savings time.
 [2003-01-29 13:06 UTC] derick@php.net
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which do
not suffer from DST.

not a bug -> bogus 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 14:01:31 2024 UTC