[ Reference Manual | Alphabetic Index ]

library(calendar)

Routines for calendar computations, based on modified julian dates (MJD).   [more]

Predicates

date_to_mjd(++DMY, ?MJD)
Convert a date in day/month/year form to an MJD day number
dwy_to_mjd(++DWY, ?MJD)
Convert a DayOfWeek/WeekOfYear/Year representation to MJD
dwy_to_mjd(++DWY, ++FirstWeekday, ?MJD)
Convert a DayOfWeek/WeekOfYear/Year representation to MJD
dy_to_mjd(++DY, ?MJD)
Convert a DayOfYear/Year representation to MJD
easter_mjd(+Year, ?MJD)
Calculate Easter Sunday date for a given year
jd_to_mjd(++JD, ?MJD)
Convert Julian Dates (JD) to Modified Julian Dates (MJD)
mjd_now(?MJD)
Returns the current date/time as (float) MJD
mjd_to_date(++MJD, ?DMY)
Converts an MJD day number into the corresponding Day/Month/Year
mjd_to_dow(?, ?)
No description available
mjd_to_dow(?, ?, ?)
No description available
mjd_to_dwy(++MJD, ?DWY)
Convert an MJD to a DayOfWeek/WeekOfYear/Year representation
mjd_to_dwy(++MJD, ++FirstWeekday, ?DWY)
Convert an MJD to a DayOfWeek/WeekOfYear/Year representation
mjd_to_dy(++MJD, ?DY)
Convert an MJD to a DayOfYear/Year representation
mjd_to_jd(++MJD, ?JD)
Convert Modified Julian Dates (MJD) to Julian Dates (JD)
mjd_to_time(++MJD, ?HMS)
Extracts the time in H:M:S form from a float MJD
mjd_to_unix(++MJD, ?UnixTime)
Convert an MJD to the UNIX time representation
mjd_to_weekday(++MJD, ?DayName)
returns the weekday of the specified MJD as atom monday, tuesday etc
mjd_to_ymd(++MJD, ?YMD)
Converts an MJD day number into the corresponding ISO8601 Year-Month-Day form
mjd_to_ywd(++MJD, ?YWD)
Convert an MJD to ISO8601 Year-Week-Day representation
time_to_mjd(++HMS, ?MJD)
Convert the time in H:M:S form to a float MJD <1.0
unix_to_mjd(++UnixTime, ?MJD)
Convert the UNIX time representation into a (float) MJD
ymd_to_mjd(++YMD, ?MJD)
Convert a date in ISO8601 Year-Month-Day form to an MJD day number
ywd_to_mjd(++DWY, ?MJD)
Convert an ISO8601 Year-Week-Day representation to MJD

Description

Julian Dates (JD) and Modified Julian Dates (MJD) are a consecutive day numbering scheme widely used in astronomy, space travel etc. It is defined for a long period from 12 noon, 1 Jan 4713 BC to 12 noon, 1 Jan 3268 AD.

Here we use MJDs as the central representation (JDs are a bit awkward because they change at noon and are very large numbers).

Note that you can use fractional MJDs to denote the time of day. The time is then defined to be Universal Time (UT, formerly GMT). That means that every day has a unique integer number, or every time point has a unique float representation! (Using double floats, the resolution is better than 10 microseconds until the year 2576, and better than 100 microseconds until the year 24826).

Differences between times are obviously trivial to compute, and so are weekdays (by simple mod(7) operation).

The code is valid for dates starting from 1 Mar 0004 = MJD -677422 = JD 1722578.5

The relationship between JD and MJD is simply MJD = JD-2400000.5, ie MJD 0 = 17 Nov 1858.

Examples

What day of the week was the 29th of December 1959?
[eclipse 1]: lib(calendar).
[eclipse 2]: date_to_mjd(29/12/1959, MJD), mjd_to_weekday(MJD,W).
MJD = 36931
W = tuesday
What date and time is it now?
[eclipse 3]: mjd_now(MJD), mjd_to_date(MJD,Date), mjd_to_time(MJD,Time).
Date = 19 / 5 / 1999
MJD = 51317.456238425926
Time = 10 : 56 : 59.000000017695129
How many days are there in the 20th century?
[eclipse 4]: N is date_to_mjd(1/1/2001) - date_to_mjd(1/1/1901).
N = 36525
The library code does not detect invalid dates, but this is easily done by converting a date to its MJD and back and checking whether they match:
[eclipse 5]: [user].
valid_date(Date) :-
        date_to_mjd(Date,MJD),
        mjd_to_date(MJD,Date).

[eclipse 6]: valid_date(29/2/1900). % 1900 is not a leap year!
no (more) solution.

About


Generated from calendar.eci on 2017-08-19 21:59