Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Simple (I thought) time comparison?

by sjessie (Novice)
on Dec 20, 2016 at 00:26 UTC ( [id://1178149]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Simple (I thought) time comparison?
in thread Simple (I thought) time comparison?

And further illustrating my noob-ness, I didn't include the entire updated script so it actually made sense. Sorry. Here it is:

use strict; use warnings; use Time::Piece; my $ctime = Time::Piece->new; my $oldtime = Time::Piece->strptime('Dec 19 17:44:00 2016', '%b %d %T +%Y'); $oldtime = $oldtime - $ctime->tzoffset; print "The current time is $ctime\n"; print "The old time is ", $oldtime + $ctime->tzoffset, "\n"; my $halfago = $ctime - 1800; print "Half an hour ago is $halfago\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; }

Replies are listed 'Best First'.
Re^5: Simple (I thought) time comparison?
by soonix (Canon) on Dec 20, 2016 at 09:16 UTC
    I modified your script, so that it outputs a little more information:
    use strict; use warnings; use Time::Piece; my $ctime = Time::Piece->new; my $oldtime = Time::Piece->strptime('Dec 19 17:44:00 2016', '%b %d %T +%Y'); $oldtime = $oldtime - $ctime->tzoffset; sub showtime { shift->strftime } print "The current time is ", showtime($ctime), "\n"; print "The old time is ", showtime($oldtime + $ctime->tzoffset), "\n"; my $halfago = $ctime - 1800; print "Half an hour ago is ", showtime($halfago), "\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; }
    The parameterless form of Time::Piece's strftime includes time zone name. My output was:
    The current time is Di, 20 Dez 2016 10:09:19 Mitteleuropäische Zeit The old time is Mo, 19 Dez 2016 17:44:00 UTC Half an hour ago is Di, 20 Dez 2016 09:39:19 Mitteleuropäische Zeit Old time is outside a half hour
    Of course, since I didn't update $halfgo, it is really outside, but it illustrates davido's point.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found