[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: File.mtime: Bug on Windows?

Holger Arndt

5/1/2006 9:54:00 PM

[I have included parts of the original message from
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/186956?186...
as there is/seems to be a problem with the gateway between ruby-talk and
the newsgroup.]

Axel Friedrich wrote:
> I think, there is a bug in File.mtime, unfortunately:
>
> Using:
> ruby 1.8.4 (2005-12-24) [i386-mswin32]
> Windows XP with NTFS filesystem
>
> When reading File.mtime( 'any existing filename'),
> the result is different by one hour, when doing this with the
> computer clock set to a daylight saving time (DST) and doing this
> with the computer clock set to a standard time.
>

I have been bitten by this too. For more information about the problem
and possible solutions see
http://search.cpan.org/~shay/Win32-UTCFileTime-1.45/lib/Win32/UTCF...
as pointed out in the original mail.

My temporary solution - not more than a hack - is to include the
following in my program:

class File
class << self
alias builtin_mtime mtime
end

def self.mtime(file)
t = self.builtin_mtime(file)
t -= 3600 if Time.now.dst? # correct time when dst is active
end
end

It's really only a hack, but it works for me. Be adviced that I think it
will give wrong results on FAT - I use only NTFS.
For portable programs this would have to be wrapped with a check to see
if the program runs on Windows NT/XP/2k/2k3 (and FAT). If someone uses
ctime() or atime(), apply the "patch" to this functions also.

Regards,
Holger Arndt