(none) 
Author Message
 (none)


Subject: Re: PFR: Julian Date
Newsgroups: comp.lang.perl.misc,comp.lang.perl.moderated
X-Newsreader: TIN [version 1.2 PL2]

[jday function posted by Jeff Godden]
: Note, this is off from the "usual" definition of Julian days by a
: constant, but if that is important to you, then just add the constant
: back in.  It also does not take into account the week that was lost
: when most of the world switched to the Gregorian calender, but if all
: you want to do is compute the number of days between 2 recent (100
: years or so) to future dates, it works fine.  If there is interest,
: one of these days I'll try to write the routine to go from the Julian
: day to month/day/year.

The following was posted (in VMS' CLI lingo, DCL) to comp.os.vms by

Comment by the author: "here is a DCL version of the R.G. Tantzen algorithm
that convert gregorian date to julian day number and back. all is integer
arithmetic and 32-bit integers. this algorithm is year-2000-proof, leap-year-
proof, century-leap-year-proof and you can compute julian day with this
algorithm back to the begining of the gregorian calendar, october 15, 1582."

sub dmy_to_julian ($$$) {
        use integer;


        if ($month > 2) { $month -= 3; } else { $month += 9; --$year; }

        return ($year / 100) * 146097 / 4
               + ($year % 100) * 1461 / 4
               + ($month * 153 + 2) / 5
               + $day + 1721119;

Quote:
}

sub julian_to_dmy ($) {
        use integer;

        my $julian = shift;
        my ($day, $month, $year);

        $julian -= 1721119;

        $year = (4 * $julian - 1) / 146097;
        $julian = (4 * $julian - 1) % 146097;
        $day = $julian / 4;

        $julian = (4 * $day + 3) / 1461;
        $day = (4 * $day + 3) % 1461;
        $day = ($day + 4) / 4;

        $month = (5 * $day - 3) / 153;
        $day = (5 * $day - 3) % 153;
        $day = ($day + 5) / 5;

        $year = $year * 100 + $julian;

        if ($month < 10) { $month += 3; } else { $month -= 9; ++$year; }

        return ($day, $month, $year);

Quote:
}

cu,
  Martin
--
                        | Martin Vorlaender | VMS & WNT programmer

 Microsoft wants        |       http://www.*-*-*.com/



Tue, 31 Jul 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. (none)

2. (none)

3. (none)

4. None

5. None

6. None

7. None

8. None

9. None

10. Symbol referencing errors in IO.none on Solaris 2.5 install

11. None

12. (none)

 

 
Powered by phpBB® Forum Software