Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Is there an official DST border day detection module? (localtime)

by flowdy (Scribe)
on Oct 28, 2014 at 10:17 UTC ( [id://1105273]=note: print w/replies, xml ) Need Help??


in reply to Re: Is there an official DST border day detection module? (localtime)
in thread Is there an official DST border day detection module?

Hi tye,

thanks to you a lot. As I want to get amount of hours in the day, I tried to modify your suggestion to:

sub hours_in_day { my $now = 60*60*int( shift()/60/60 ); # Start of this hour my $hour = ( localtime($now) )[2]; $now -= $hour*60*60; # Start of this day $hour = ( localtime($now+24*60*60) )[2]; $hour -= 24 if int($hour/12); return 24-$hour; }

But it is not working, hm ...

Thinking & probing,
flowdy

Replies are listed 'Best First'.
Re^3: Is there an official DST border day detection module? (localtime)
by hippo (Bishop) on Oct 28, 2014 at 11:08 UTC

    I think your logic is slightly amiss when you calculate the "start of this day". This variant works for me:

    #!/usr/bin/perl -Tw use strict; print "Today: " . hours_in_day (time) . "hours.\n"; print "Sun: " . hours_in_day (time-170000) . "hours.\n"; sub hours_in_day { my $now = 60*60*int( shift()/60/60 ); # Start of this hour my $hour = ( localtime($now) )[2]; $now -= $hour*60*60; # Offset from start of thi +s day $hour = ( localtime($now) )[2]; $hour += 24 unless int($hour/12); return $hour; }

    and gives this output for me (Sunday was the switch from BST to GMT here):

    Today: 24hours. Sun: 25hours.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-28 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found