php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48245 Setting file datetime outside of matching DST settings loses time.
Submitted: 2009-05-12 14:30 UTC Modified: 2009-06-18 15:23 UTC
From: RQuadling at GMail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3CVS-2009-05-12 (snap) OS: Windows XP SP3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2009-05-12 14:30 UTC] RQuadling at GMail dot com
Description:
------------
Touching a file with a non DST datetime and then reading it back is 
losing 1 hour.

Using Procmon, Windows is getting and returning the correct times.

It seems that PHP is adjusting the times it gets when in DST and 
reading a file NOT in DST.





Reproduce code:
---------------
<?php
// Create a dummy file.
$s_File = getenv('TEMP') . DIRECTORY_SEPARATOR . 'junktime.txt';
file_put_contents($s_File, 'JUNK');

$a_Dates = array(
  'Some time today' => strtotime('today 13:14:15'),
  'January 1st'     => strtotime('2009/02/03 04:05:06'),
  'October 1st'     => strtotime('2008/10/01 04:05:06'),
);

foreach($a_Dates as $s_When => $dt_Date) {
  touch($s_File, $dt_Date);
  clearstatcache();
  $dt_Modified = filemtime($s_File);

  echo
    'Wanted to set the date to : (', $dt_Date, ') ', date('r', $dt_Date), PHP_EOL,
    'File was set to           : (', $dt_Modified, ') ', date('r', $dt_Modified), PHP_EOL,
    ($dt_Date === $dt_Modified ? 'Match' : 'Different'), PHP_EOL, PHP_EOL;
}

// Clean-up
unlink($s_File);

Expected result:
----------------
Wanted to set the date to : (1242130455) Tue, 12 May 2009 13:14:15 
+0100
File was set to           : (1242130455) Tue, 12 May 2009 13:14:15 
+0100
Match

Wanted to set the date to : (1233633906) Tue, 03 Feb 2009 04:05:06 
+0000
File was set to           : (1233633906) Tue, 03 Feb 2009 04:05:06 
+0000
Match

Wanted to set the date to : (1222830306) Wed, 01 Oct 2008 04:05:06 
+0100
File was set to           : (1222830306) Wed, 01 Oct 2008 04:05:06 
+0100
Match

Actual result:
--------------
Wanted to set the date to : (1242130455) Tue, 12 May 2009 13:14:15 
+0100
File was set to           : (1242130455) Tue, 12 May 2009 13:14:15 
+0100
Match

Wanted to set the date to : (1233633906) Tue, 03 Feb 2009 04:05:06 
+0000
File was set to           : (1233630306) Tue, 03 Feb 2009 03:05:06 
+0000
Different

Wanted to set the date to : (1222830306) Wed, 01 Oct 2008 04:05:06 
+0100
File was set to           : (1222830306) Wed, 01 Oct 2008 04:05:06 
+0100
Match

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-13 08:28 UTC] RQuadling at GMail dot com
No difference...

>php -n -f z:\testDST.php
PHP V5.2.10-dev OS:WINNT SAPI:cli
Loaded INI:

Wanted to set the date to : (1242216855) 1 Wed, 13 May 2009 13:14:15 
+0100
File was set to           : (1242216855) 1 Wed, 13 May 2009 13:14:15 
+0100
Match

Wanted to set the date to : (1233633906) 0 Tue, 03 Feb 2009 04:05:06 
+0000
File was set to           : (1233630306) 0 Tue, 03 Feb 2009 03:05:06 
+0000
Different

Wanted to set the date to : (1222830306) 1 Wed, 01 Oct 2008 04:05:06 
+0100
File was set to           : (1222830306) 1 Wed, 01 Oct 2008 04:05:06 
+0100
Match

and

PHP V5.3.0RC3-dev OS:WINNT SAPI:cli
Loaded INI:D:\PHP\INI\php-cli.ini

Wanted to set the date to : (1242216855) 1 Wed, 13 May 2009 13:14:15 
+0100
File was set to           : (1242216855) 1 Wed, 13 May 2009 13:14:15 
+0100
Match

Wanted to set the date to : (1233633906) 0 Tue, 03 Feb 2009 04:05:06 
+0000
File was set to           : (1233630306) 0 Tue, 03 Feb 2009 03:05:06 
+0000
Different

Wanted to set the date to : (1222830306) 1 Wed, 01 Oct 2008 04:05:06 
+0100
File was set to           : (1222830306) 1 Wed, 01 Oct 2008 04:05:06 
+0100
Match


With the latest 5.2 and 5.3 snapshots.
 [2009-05-13 08:30 UTC] RQuadling at GMail dot com
If I use the -n option for V5.3 to not use my INI file, I get the 
normal notice regarding a lack of timezone settings ...

"It is not safe to rely on the system's timezone settings. You are 
*required* to use the date.timezone setting or the 
date_default_timezone_set() function. In case you used any of
 those methods and you are still getting this warning, you most 
likely misspelled the timezone identifier. We selected 
'Europe/London' for '1.0/DST'"

date

date/time support => enabled
"Olson" Timezone Database Version => 2009.7
Timezone Database => internal
Default timezone => Europe/London

Directive => Local Value => Master Value
date.default_latitude => 50.3870 => 50.3870
date.default_longitude => -3.9520 => -3.9520
date.sunrise_zenith => 90.583333 => 90.583333
date.sunset_zenith => 90.583333 => 90.583333
date.timezone => Europe/London => Europe/London
 [2009-06-10 13:04 UTC] jani@php.net
Just checking: Are the dates correct in the files when you check them 
without PHP? (like dir something..dunno, *nix has 'ls -l' :)
 [2009-06-10 14:00 UTC] RQuadling at GMail dot com
Oh darn.

At the command prompt I created a new plain text file.
I then used Cygwin's touch ...

touch RAQ.txt -t 200901011213.14

then ...

dir RAQ.txt

which outputs ...

01/01/2009  13:13                27 RAQ.txt

Which is wrong. 

But having just read 
http://www.codeproject.com/KB/datetime/dstbugs.aspx it seems that 
windows is simply screwed.
 [2009-06-18 15:23 UTC] pajoye@php.net
Not a php issue
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 23:01:33 2025 UTC