Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / August 2004



Tip: Looking for answers? Try searching our database.

Time::Local problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Ledger - 30 Aug 2004 11:15 GMT
Can anyone explain the following? (the difference in commands is the
year spec.)

david@g4: perl -e 'use Time::Local;print ( (localtime(timelocal(0, 0,
0, 1, 1, 55)))[6], "\n");'
2
david@g4: perl -e 'use Time::Local;print ( (localtime(timelocal(0, 0,
0, 1, 1, 54)))[6], "\n");'
Cannot handle date (0, 0, 0, 1, 1, 2054) at -e line 1
david@g4:

All years I've tried > 55 are Ok; all years I've tried < 54 fail.

David

perl -v:
This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
(with 1 registered patch, see perl -V for more detail)

uname -a:
Darwin G4.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug  5
19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC  Power
Macintosh powerpc

Signature

David Ledger - Freelance Unix Sysadmin in the UK.
Chair of HPUX SysAdmin SIG of hpUG technical user group (www.hpug.org.uk)
dledger@ivdcs.co.uk
www.ivdcs.co.uk

Sherm Pendley - 30 Aug 2004 19:10 GMT
> Can anyone explain the following? (the difference in commands is the
> year spec.)
[quoted text clipped - 8 lines]
>
> All years I've tried > 55 are Ok; all years I've tried < 54 fail.

Here's the relevant bit from the Time::Local perldoc:

     o   Years in the range 0..99 are interpreted as shorthand for
years in
           the rolling "current century," defined as 50 years on either
side
           of the current year.

So, this being 2004, 55 is interpreted as 1955, while 54 is interpreted
as 2054.

So, what's wrong with the year 2054? That's covered later in the
perldoc:

       Please note, however, that the range of dates that can be
actually be
       handled depends on the size of an integer (time_t) on a given
platform.
       Currently, this is 32 bits for most systems, yielding an
approximate
       range from Dec 1901 to Jan 2038.

This applies to the default Perl for Mac OS X, which uses 32-bit
integers. This can be easily verified:

sherm:~ sherm$ perl -e 'use Time::Local;print ( (localtime(timelocal(0,
0, 0, 1, 1, 36)))[6], "\n");'
5
sherm:~ sherm$ perl -e 'use Time::Local;print ( (localtime(timelocal(0,
0, 0, 1, 1, 37)))[6], "\n");'
0
sherm:~ sherm$ perl -e 'use Time::Local;print ( (localtime(timelocal(0,
0, 0, 1, 1, 38)))[6], "\n");'
Cannot handle date (0, 0, 0, 1, 1, 2038) at -e line 1

sherm--
Rick Measham - 31 Aug 2004 00:01 GMT
> Can anyone explain the following? (the difference in commands is the
> year spec.)
[quoted text clipped - 8 lines]
>
> All years I've tried > 55 are Ok; all years I've tried < 54 fail.

As Sherm has pointed out, it's due to the two-digit year wrap around.
(Remember the so-called Millennium bug? That's what you're perpetuating
in the above code)

Your best bet for anything to do with dates and times is to use the
DateTime modules. They work on all platforms and comprehensively handle
any date and time you can throw at it (right up to $MAXINT-12-31). They
handle localization and know all current and historic DST rules back to
1972.

Cheers!
Rick Measham

(disclaimer: I have developed some of the DateTime modules)

Senior Developer
PrintSupply - Print Procurement & Supply Management
18 Greenaway Street VIC 3105
Tel: (03) 9850 3255
Fx: (03) 9850 3277
http://www.printsupply.com.au/
Sherm Pendley - 31 Aug 2004 03:09 GMT
> Your best bet for anything to do with dates and times is to use the
> DateTime modules. They work on all platforms and comprehensively
> handle any date and time you can throw at it (right up to
> $MAXINT-12-31).

Great - so now our ancestors have to deal with the Y4G bug? ;-)

sherm--
Rick Measham - 31 Aug 2004 03:14 GMT
> Great - so now our ancestors have to deal with the Y4G bug? ;-)

LOL .. no .. unless you continue to abbreviate. The dates will range
from 10000-01-01 to 10000-12-31 and 2004 will mean 2004 not 12004.

Cheers!
Rick

(They're your decedents by the way, your ancestors have stopped
counting)

Senior Developer
PrintSupply - Print Procurement & Supply Management
18 Greenaway Street VIC 3105
Tel: (03) 9850 3255
Fx: (03) 9850 3277
http://www.printsupply.com.au/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.