Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Subtracting and Comparing Two Dates

by jettero (Monsignor)
on Jan 08, 2007 at 18:35 UTC ( [id://593646]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^4: Subtracting and Comparing Two Dates
in thread Subtracting and Comparing Two Dates

I'm not sure that's quite right...

sub gmtime { usage "gmtime(time)" if @_ != 1; CORE::gmtime($_[0]); }
verses
sub timegm { my ($sec,$min,$hour,$mday,$month,$year) = @_; if ($year >= 1000) { $year -= 1900; } elsif ($year < 100 and $year >= 0) { $year += ($year > $Breakpoint) ? $Century : $NextCentury; } unless ($Options{no_range_check}) { if (abs($year) >= 0x7fff) { $year += 1900; croak "Cannot handle date ($sec, $min, $hour, $mday, $month, * +$year*)"; } croak "Month '$month' out of range 0..11" if $month > 11 or $month + < 0; my $md = $MonthDays[$month]; # ++$md if $month == 1 and $year % 4 == 0 and # ($year % 100 != 0 or ($year + 1900) % 400 == 0); ++$md unless $month != 1 or $year % 4 or !($year % 400); croak "Day '$mday' out of range 1..$md" if $mday > $md or $mda +y < 1; croak "Hour '$hour' out of range 0..23" if $hour > 23 or $hou +r < 0; croak "Minute '$min' out of range 0..59" if $min > 59 or $min + < 0; croak "Second '$sec' out of range 0..59" if $sec > 59 or $sec + < 0; } my $days = _daygm(undef, undef, undef, $mday, $month, $year); my $xsec = $sec + $SecOff + 60*$min + 3600*$hour; unless ($Options{no_range_check} or ($days > $Min{Day} or $days == $Min{Day} and $xsec >= $Min +{Sec}) and ($days < $Max{Day} or $days == $Max{Day} and $xsec <= $Max +{Sec})) { warn "Day too small - $days > $Min{Day}\n" if $days < $Min{Day +}; warn "Day too big - $days > $Max{Day}\n" if $days > $Max{Day}; warn "Sec too small - $days < $Min{Sec}\n" if $days < $Min{Sec +}; warn "Sec too big - $days > $Max{Sec}\n" if $days > $Max{Sec}; $year += 1900; croak "Cannot handle date ($sec, $min, $hour, $mday, $month, $year +)"; } no integer; $xsec + 86400 * $days; }

They seem to be different by a kilobyte or two. I noticed they both use CORE::gmtime() though.

-Paul

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593646]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.