Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 92972
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: ali [...] ll.mit.edu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.09



Subject: please calculate jd from mjd
Date: Wed, 12 Feb 2014 13:57:28 -0500
To: <bug-DateTime [...] rt.cpan.org>
From: Anye Li <ali [...] ll.mit.edu>
Dear DateTime maintainer, Please calculate jd from mjd instead of mjd from jd. This trival change will improve the accuracy of mjd without affecting jd accuracy in the modern era. Minimal proposed patch is attached. I did not fix comments or variable names. To see what the problem is, consider calculating the mjd of 2012-06-30 12:00:00 UTC, which occurs on the day of the latest leap second. The mjd is 56108+43200/86401. The truncation error in seconds From calculating mjd this way can be evaluated by (56108+43200/86401-56108)*86401-43200 which in IEEE-754 double precision is about 6.8e-8, already quite a few nanoseconds. If you calculate using Julian date (as is done in DateTime-1.07), (2456108.5+43200/86401-2456108.5)*86401-43200 is about 1.7e-5, which is a whole lot more nanoseconds. Sub-nanosecond truncation error in the modern era is possible by using JD 2436934.5 (1960-01-01, the start of UTC as defined by the IAU) or JD 2441317.5 (1972-01-01, introduction of leap seconds) and is possible for all representable time by using 2-part dates (whole+fractional JD) as is done by the IAU-endorsed SOFA library. Thank you, Anye Li Package: DateTime-1.07 Perl: v5.14.2 (+ whatever patches Debian 7 has) uname -a: Linux gleep 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
--- old/DateTime.pm 2014-02-12 13:36:07.536401887 -0500 +++ new/DateTime.pm 2014-02-12 13:40:01.587274581 -0500 @@ -980,10 +980,10 @@ } # RD 1 is JD 1,721,424.5 - a simple offset -sub jd { +sub mjd { my $self = shift; - my $jd = $self->{utc_rd_days} + 1_721_424.5; + my $jd = $self->{utc_rd_days} - 678576; my $day_length = $self->_day_length( $self->{utc_rd_days} ); @@ -992,7 +992,7 @@ + ( $self->{rd_nanosecs} / $day_length / MAX_NANOSECONDS ) ); } -sub mjd { $_[0]->jd - 2_400_000.5 } +sub jd { $_[0]->mjd + 2_400_000.5 } { my %strftime_patterns = (
Download smime.p7s
application/x-pkcs7-signature 1.8k

Message body not shown because it is not plain text.