cunningrat has asked for the wisdom of the Perl Monks concerning the following question:
This drove me nuts for several hours today until I figured it out. Sample code below:
#!/usr/bin/perl use strict; use Time::Local; #use bignum(p => -3); my $key='121005'; print $key." ==> ".convtime($key)."\n"; sub convtime { my @months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @dow=qw{Sun Mon Tue Wed Thu Fri Sat}; my $date=@_[0]; my $year=substr $date,0,2; $year += 100; my $month=substr $date,2,2; $month -= 1; my $day=substr $date,4; my $gmt = timegm(0,0,0,$day,$month,$year); my @gmtime = gmtime($gmt); my $convstring=$dow[$gmtime[6]]." ".$months[$gmtime[4]]." ".$gmtime[3 +]; return $convstring }
If you run this, it returns "121005 ==> Fri Oct 5", as it should. If you uncomment the "use bignum" line, however, it returns "121005 ==> Mon Jan 23".
What I *think* (after some testing) is going on is that the Math::BigInt and Math::Bigfloat overload the arithmetic operators, which breaks timegm().
Is this expected behavior and/or documented anywhere?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bignum breaks Time::Local? (constants)
by tye (Sage) on Nov 05, 2012 at 23:34 UTC | |
|
Re: Bignum breaks Time::Local?
by tobyink (Canon) on Nov 05, 2012 at 22:54 UTC | |
by cunningrat (Acolyte) on Nov 06, 2012 at 14:41 UTC |