JD2date

From DavinciWiki
Jump to: navigation, search

Description

Convert input Julian Date to date and time

Arguments and Return Values

Parameters: Numbers (scalars) specifying the Julian Date, digits of seconds fraction to display, calendar mode, and print mode. Only the first input is required; the others are optional. The calendar mode and print mode must be passed by reference, with the names cal and print, respectively.

Return Value: An array specifying the date and time. The function can also print a string giving the date and time. There may be a slight discrepancy between the two, due to rounding.

Usage

Syntax: JD2date(JD,digits,cal=n,print=m)

The only required input is the Julian Date. Julian Date is a continuous count of days since noon UTC on January 1, 4713 BCE in the proleptic Julian calendar. This input (and all others for this function) must be scalar.

The second input (optional) specifies how many digits to display after the decimal in the number of seconds. Defaults to 0 if omitted.

If the calendar mode is specified, it must be passed by reference, with the name cal and a value of 0 or 1. (See the examples.)

If the calender mode is omitted, the function will guess, based on the input date. Dates before October 15, 1582 (JD 2299160.5) use the Julian calendar. Dates after that use the Gregorian (modern) calendar. This reflects the first changeover date. However, different countries changed at different times. See http://www.tondering.dk/claus/cal/node3.html.

The print mode, print, also must be passed by reference. It sets whether to print the date as a string, in addition to returning it. This defaults to one, so the string will be shown unless print=0. The string will give the date and time if the input is a float or double, or just the date if the input is integer format.

The formulae used here for the Gregorian calendar are from http://en.wikipedia.org/wiki/Julian_day; the formulae for the Julian calendar were derived based on the Gregorian formulae. Both have been checked extensively against USNO calculator at http://aa.usno.navy.mil/data/docs/JulianDate.php.

It is advisable to enter inputs in double format to ensure accuracy. See intermediate float bug.

The returned array has the same organization as an array from the clock function: [year, month, day, hour, minute, second, time zone]. The returned time zone is always zero (UTC).

The returned clock system is the same as the input clock system. So if the input Julian dates were UTC, the returned dates/times will be UTC as well, and so on for TT, TAI, etc.

The returned array is always integer format. The second input only affects the displayed string.

When JD2date() is entered without any arguments, it prints its description, as shown below.

Examples

dv> JD2date()

Convert Julian Date to date and time
Scalar inputs only - no arrays!
JD2date(JD,digits,cal=n,print=m) returns an array specifying the date
 and time, and can also print a string giving the date and time.
 There may be a slight discrepancy between the two, due to rounding.
 Optional second input controls how many digits of second fraction
  of time will be displayed; 0 if omitted
 cal (sets calendar mode) must be passed by reference
  cal=0 for Julian calendar; cal=1 for Gregorian (modern) calendar
  If cal is omitted, the function will guess, based on the date.
   Dates before October 15, 1582 (JD 2299160.5) use Julian calendar
   Dates after that use Gregorian calendar
   This reflects the first changeover date. However, different
    countries changed at different times. See
    http://www.tondering.dk/claus/cal/node3.html
 print also must be passed by reference. It sets whether to print
  the date as a string, in addition to returning it. Prints string if
  nonzero or omitted; does not print string only if print=0
 Return format: [year, month, day, hour, minute, second, 0]
  The final zero is the time zone offset (0, since this uses UTC).
  This is the same format used by the function clock.
  The returned clock system is the same as the input clock system.
   So if the input Julian dates were UTC, the returned dates/times
   will be UTC as well, and so on for TT, TAI, etc.
Gregorian formulae from http://en.wikipedia.org/wiki/Julian_day
Julian formulae derived based on Gregorian formulae
Both were checked extensively against the USNO calculator at
 http://aa.usno.navy.mil/data/docs/JulianDate.php
It is advisable to enter inputs in double format to ensure accuracy.
 See the DavinciWiki article on the intermediate float bug.
S.Marshall 01-22-2010

0
dv> JD2date(2299160)

Thursday, October 4, 1582

 (Julian calendar)

7x1x1 array of int, bsq format [28 bytes]
1582    10      4       12      0       0       0
dv> JD2date(atod("2299159.875"), 2)

Thursday, October 4, 1582, 09:00:00.00 UTC

 (Julian calendar)

7x1x1 array of int, bsq format [28 bytes]
1582    10      4       9       0       0       0
dv> JD2date(atod("2299160.875"))

Friday, October 15, 1582, 09:00:00 UTC

 (Gregorian calendar)

7x1x1 array of int, bsq format [28 bytes]
1582    10      15      9       0       0       0
dv> JD2date(atod("2299160.875"), cal=0)

Friday, October 5, 1582, 09:00:00 UTC

 (Julian calendar)

7x1x1 array of int, bsq format [28 bytes]
1582    10      5       9       0       0       0
dv> JD2date(2299161, cal=0, print=0)
7x1x1 array of int, bsq format [28 bytes]
1582    10      5       12      0       0       0

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left

Related Functions

Recent Library Changes

Created On: 11-18-2009
Modified On: 06-01-2010

Personal tools