Leap Seconds and Epochs

2005-11-20 Thread Rick Measham
Why does time() return a multiple of 60? Surely each time there's a leap 
second time()%60 should increment?


Cheers!
Rick Measham



Re: Leap Seconds and Epochs

2005-11-20 Thread mathieu longtin
Cause time since the epoch doesn't measure leap seconds. See in the
DateTime manual, under the epoch() method description.

On 11/20/05, Rick Measham [EMAIL PROTECTED] wrote:
 Why does time() return a multiple of 60? Surely each time there's a leap
 second time()%60 should increment?

 Cheers!
 Rick Measham




Re: Leap Seconds and Epochs

2005-11-20 Thread Rick Measham

mathieu longtin wrote:

Cause time since the epoch doesn't measure leap seconds. See in the
DateTime manual, under the epoch() method description.


I'm aware that it doesn't measure them ... but I'm wondering why? Surely 
that makes it Capital-W-Wrong. Perl will return the Wrong number of 
elapsed seconds since 1970  ...


Cheers!
Rick Measham


A sane answer for datetime subtraction?

2005-11-20 Thread Dave Rolsky
I think I've hit upon a fairly sane answer, although it makes the 
internals of DateTime.pm even yuckier than before (which may be hard to 
imagine if you've already poked around in some of the methods ;)


I've summarized it on the wiki here: 
http://datetime.perl.org/wiki/index.cgi?MathProblems


Please read this and let me know what you all think.  If you have 
additional examples please just add them to the page, but it's probably 
better to have the discussion here on the list (at least I'd prefer that).


I think it'll make most people happy, and I think it does a fairly good 
job of being intuitive.


However, it still does not make this set of equations always true:

  $dt2 - $dt1 = $dur
  $dt1 + $dur = $dt2
  $dt2 - $dur = $dt1

The last line there may sometimes not be true in certain cases where the 
first line's subtraction involves DST.  I've managed to get it to the 
point where this _only_ happens when $dt2 is the day of a DST transition. 
Simply crossing the transition is ok.


I think this is about as good as I can get it without simply forcing lots 
of additional complexity onto the user by adding many options to the API, 
which I am loathe to do.


I'm hoping, however, that Rick will make sure that users can use 
DT::F::Duration to handle anything that they cannot do with DateTime.pm 
itself ;)



-dave

/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/


Re: Leap Seconds and Epochs

2005-11-20 Thread Dave Rolsky

On Mon, 21 Nov 2005, Rick Measham wrote:


mathieu longtin wrote:

Cause time since the epoch doesn't measure leap seconds. See in the
DateTime manual, under the epoch() method description.


I'm aware that it doesn't measure them ... but I'm wondering why? Surely that 
makes it Capital-W-Wrong. Perl will return the Wrong number of elapsed 
seconds since 1970  ...


I started writing up an explanation but then realized I was too confused. 
I suggest reading these links:


http://en.wikipedia.org/wiki/Unix_epoch
http://cr.yp.to/proto/utctai.html

That'll clear everything up.  The upshot is that the epoch is just a 
number, but the formula for translating it into a datetime just works, 
except _during_ a leap second, when it gives you an answer that is one 
second off.


What it doesn't work for is addition and subtraction, if you're expecting 
UTC results.  Instead you get TAI results.


So which is stupider, leap seconds or POSIX?  Hard to say ;)


-dave

/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/


Re: Adding seconds gets stuck

2005-11-20 Thread Dave Rolsky

On Sat, 5 Nov 2005, Mike Schilli wrote:


Adding seconds to a date gets stuck when it reaches a leap second:

   use DateTime;

   my $dt = DateTime-new(
 year  = 1972,
 month = 12,
 day   = 31,
 hour  = 23,
 minute= 59,
 second= 55,
 time_zone = UTC);

   for(1..10) {
   $dt-add( seconds = 1);

   print $dt-datetime(), \n;
   }

produces

1972-12-31T23:59:56
1972-12-31T23:59:57
1972-12-31T23:59:58
1972-12-31T23:59:59
1972-12-31T23:59:60
1972-12-31T23:59:60
1972-12-31T23:59:60
1972-12-31T23:59:60
1972-12-31T23:59:60
1972-12-31T23:59:60


That is indeed a bug.  It'll be fixed in the next release, which assuming 
I actually came up with a subtraction algorithm that makes sense, will be 
soon.



-dave

/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/


Re: A sane answer for datetime subtraction?

2005-11-20 Thread Rick Measham

Dave Rolsky wrote:
I think this is about as good as I can get it without simply forcing 
lots of additional complexity onto the user by adding many options to 
the API, which I am loathe to do.


To sing my usual song: This looks great .. anyone who wants anything 
else should use something like DateTime::Decorator::UTCMath


I'm hoping, however, that Rick will make sure that users can use 
DT::F::Duration to handle anything that they cannot do with DateTime.pm 
itself ;)


I've decided that DateTime math is quite possibly the ugliest thing in 
the entire world -- especially after reading the Wiki :)


Thanks heaps for all this work, though I can see that my job comes next 
 and it will be a doozy.


Cheers!
Rick Measham