Alright, great, soonix, thank you. I can dispense with that longer script and focus on the essential output and simply glean the values. Your formula looks right to me, and I'll test it as best I can. I have to wonder out loud how you were able to cobble it together from scratch so quickly. (I've been puzzling for weeks.) Julian dates aren't the stuff that most people can wrap their heads around. Let's look at a toy script:

#! /usr/bin/perl use warnings; use strict; use 5.010; use DateTime; use DateTime::TimeZone; my $begin = 2457205.09272861; my $middle = 2457205.09613609; my $end = 2457205.09954643; my $dt1 = jd2dt($begin); say "date1 is $dt1"; my $dt2 = jd2dt($middle); say "date2 is $dt2"; my $dt3 = jd2dt($end); say "date3 is $dt3"; my $dur = $dt3-$dt1; say "dur is $dur"; sub jd2dt { # convert JD to DateTime my $jd_to_convert = shift; my $days = int $jd_to_convert; # that odd date is "julian day zero", converted to "proleptic" gre +gorian calendar my $dt = DateTime->new(year => -4713, month => 11, day =>24, hour +=> 12, time_zone => DateTime::TimeZone->new( name => 'UTC' ))->add(da +ys => $days); $dt->add(hours => 24 * ($jd_to_convert - $days)); say "date is $dt"; }

Output:

date is 2015-07-01T14:13:31 date1 is 1 date is 2015-07-01T14:18:26 date2 is 1 date is 2015-07-01T14:23:20 date3 is 1 dur is 0

How is $dt unity at the end of the subroutine and a well-formed string in main?

How do I fix my duration calculation to reflect the difference in two dates?

Thanks again for giving my starwatching a perl infusion.


In reply to Re^2: getting a utc value from julian date by Aldebaran
in thread getting a utc value from julian date by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.