in reply to Timegm and timelocal

Did I understand correct, that you are interested in just the difference?

Then, if your times are really at most 10 minutes apart, I don't think that you need to take care of the date or even the hour. Even if the daylight saving time occured between two timestamps. You just need to check the minutes and seconds. if the result is negative, just add 60 minutes and you should be okay.

Here a small example:

my $a="20070101005959"; my $z="20070101010101"; my $t1=substr($a,-4,2)*60+substr($a,-2); my $t2=substr($z,-4,2)*60+substr($z,-2); print (($t2+3600-$t1)%3600);

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Timegm and timelocal
by Chon-Ji (Novice) on Jun 08, 2007 at 00:09 UTC
    Yes, I'm interseted to see the difference since my application executes faster when using timegm compared to timelocal. It seems for my application I could juts use timegm since I'm only using it to compute the elapsed number of seconds, and my expected value shouldn't exceed 600 seconds since the timestamps were taken at very little intervals within the day.
Re^2: Timegm and timelocal
by Chon-Ji (Novice) on Jun 08, 2007 at 00:33 UTC
    I have question for this part of your code print (($t2+3600-$t1)%3600 Why again do I need to add 3600 to $t2

      You don't need to, but if you do, you don't need to check for negative values afterwards.

      You can replace this by:

      my $r= $t2-$t1; $r+= 3600 if $r<0;

      This code may even be faster because you don't need to divide by 3600.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e