Astro.Time (Astro v0.5.0) View Source
Calculations converting between geometry and time
All public functions use degrees as their input parameters
Time is a fraction of a day after UTC
Link to this section Summary
Types
A moment is a floating point representations of days (the mantissa) and fraction of a day (the fraction). Days is since a known epoch.
Functions
Adds the requested minutes to a date returning a datetime in the UTC time zone
Returns the datetime for a given Julian day
Returns the number of seconds since 0001-01-01
in the Gregorian calendar.
Converts a float number of hours
since midnight into {hours, minutes, seconds}.
Returns the day number for January 1st, 2000
Returns the Julian centuries for a given Julian day
Returns the astronomical Julian day for a given date
Returns the Julian day for a given Julian century
Returns the modified Julian day for a date
Converts a float number of hours since midnight to
a DateTime.t()
Returns the offset in float days
for a given moment and time zone.
Converts a number of seconds
since midnight into {hours, minutes, seconds}.
Converts a terrestrial datetime to a UTC datetime
Link to this section Types
Specs
hours() :: number()
Specs
moment() :: number()
A moment is a floating point representations of days (the mantissa) and fraction of a day (the fraction). Days is since a known epoch.
Specs
season() :: Astro.angle()
Link to this section Functions
Adds the requested minutes to a date returning a datetime in the UTC time zone
Arguments
minutesis a float number of minutes since midnightdateis any date in the Gregorian calendar
Returns
- a datetime in the UTC time zone
Returns the datetime for a given Julian day
Arguments
julian_dayis any astronomical Julian day such as returned fromAstro.Time.julian_day_from_date/1
Returns
- a
DateTime.tin the UTC time zone
Example
iex> Astro.Time.datetime_from_julian_days 2458822.5
{:ok, ~U[2019-12-05 00:00:00Z]}
Returns the number of seconds since 0001-01-01
in the Gregorian calendar.
Arguments
datetimeis anyDateTime.tsince0001-01-01in theCalendar.ISOcalendar
Returns
- An integer number of seconds since
0001-01-01
Converts a float number of hours
since midnight into {hours, minutes, seconds}.
Arguments
time_of_dayis a float number of hours since midnight
Returns
- A
{hour, minute, second}tuple.
Examples
iex> Astro.Time.hours_to_hms 0.0 {0, 0, 0}
iex> Astro.Time.hours_to_hms 23.999 {23, 59, 56}
iex> Astro.Time.hours_to_hms 15.456 {15, 27, 21}
Returns the day number for January 1st, 2000
Returns the Julian centuries for a given Julian day
Arguments
julian_dayis any astronomical Julian day such as returned fromAstro.Time.julian_day_from_date/1
Returns
- the astronomical Julian century as a
float
Returns the astronomical Julian day for a given date
Arguments
dateis anyCalendar.date
Returns
- the astronomical Julian day as a
float
Example
iex> Astro.Time.julian_day_from_date ~D[2019-12-05] 2458822.5
Returns the Julian day for a given Julian century
Arguments
julian_centuryis any astronomical Julian century such as returned fromAstro.Time.julian_centuries_from_julian_day/1
Returns
- the astronomical Julian day as a
float
Returns the modified Julian day for a date
Arguments
dateis anyCalendar.date
Returns
- the modified Julian day as a
float
Notes
A modified version of the Julian date denoted MJD is obtained by subtracting 2,400,000.5 days from the Julian date JD,
The MJD therefore gives the number of days since
midnight on November 17, 1858. This date corresponds
to 2400000.5 days after day 0 of the Julian calendar.
Converts a float number of hours since midnight to
a DateTime.t()
Arguments
time_of_dayis a float number of hours since midnightdateis anyCalendar.date()
Returns
A DateTime.t() combining the date and time_of_day
in the UTC timezone.
Returns the offset in float days
for a given moment and time zone.
Example
# Returns a 1 hour offset as a fraction of day
iex> t = Cldr.Calendar.date_to_iso_days(~D[2021-08-01])
iex> Astro.Time.offset_for_zone t, "Europe/London"
0.041666666666666664
Converts a number of seconds
since midnight into {hours, minutes, seconds}.
Arguments
time_of_dayis a number of seconds
Returns
- A
{hour, minute, second}tuple.
Examples
iex> Astro.Time.seconds_to_hms 0.0 {0, 0, 0}
iex> Astro.Time.seconds_to_hms 3214 {0, 53, 34}
iex> Astro.Time.seconds_to_hms 10_000 {2, 46, 39}
Converts a terrestrial datetime to a UTC datetime
Arguments
datetimeis any UTC datetime which is considered to be a Terrestrial Time.
Returns
- A UTC datetime adjusted for the difference between Terrestrial Time and UTC time
Notes
Terrestrial Time (TT) was introduced by the IAU in 1979 as the coordinate time scale for an observer on the surface of Earth. It takes into account relativistic effects and is based on International Atomic Time (TAI), which is a high-precision standard using several hundred atomic clocks worldwide. As such, TD is the atomic time equivalent to its predecessor Ephemeris Time (ET) and is used in the theories of motion for bodies in the solar system.
To ensure continuity with ET, TD was defined to match ET for the date 1977 Jan 01. In 1991, the IAU refined the definition of TT to make it more precise. It was also renamed Terrestrial Time (TT) from the earlier Terrestrial Dynamical Time (TDT).