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

  • Comment on Re^2: Is there an official DST border day detection module? (localtime)
  • Download Code

Replies are listed 'Best First'.
Re^3: Is there an official DST border day detection module? (localtime)
by hippo (Archbishop) 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.