cheatah
Module

space::time

cheatah-space v0.1.0-alpha — Biome Standard 0.6.3-alpha

Concepts

Functions

fn double jd_unix_epoch() #

Julian Date of the Unix epoch, 1970-01-01T00:00:00Z.

Returns

2440587.5.

Complexity

O(1).

Allocation

none.

System testsystests/test_jd.purr
Example
import io
import space.time as st

# The Unix epoch's Julian Date is the anchor of every unix<->jd conversion.
io.print(st.jd_unix_epoch())                       # 2440587.5
io.print(st.unix_to_jd(0.0) == st.jd_unix_epoch()) # true
fn double jd_j2000() #

Julian Date of the J2000.0 epoch, 2000-01-01T12:00:00 TT.

Returns

2451545.0.

Complexity

O(1).

Allocation

none.

System testsystests/test_jd.purr
Example
import io
import space.time as st

# J2000.0 — the reference epoch of modern astronomical series.
io.print(st.jd_j2000())                            # 2451545.0
io.print(st.jd_to_j2000_seconds(st.jd_j2000()))    # 0.0 — J2000 is its own origin
fn double cdf_epoch_unix_offset_ms() #

CDF_EPOCH of the Unix epoch: milliseconds from 0000-01-01T00:00:00.000 to 1970-01-01 — the constant that bridges Unix time and NASA CDF's millisecond epoch.

Returns

62167219200000.0.

Complexity

O(1).

Allocation

none.

System testsystests/test_cdf_epoch.purr
Example
import io
import space.time as st

# The Unix epoch expressed as a CDF_EPOCH (ms since year 0).
io.print(st.cdf_epoch_unix_offset_ms())                             # 62167219200000.0
io.print(st.unix_to_cdf_epoch(0.0) == st.cdf_epoch_unix_offset_ms())  # true
fn auto unix_to_jd(TimeInput auto &&seconds) #

Unix epoch seconds → Julian Date.

Parameters
seconds

scalar or numeric ndarray of seconds since 1970-01-01T00:00:00Z.

Returns

the corresponding Julian Date(s).

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_jd.purr systests/test_vectorized.purr
Example
import io
import ndarray
import space.time as st

io.print(st.unix_to_jd(946728000.0))               # 2451545.0 — J2000, exactly
let jds = st.unix_to_jd(ndarray.array([0.0, 86400.0]))   # a whole array, vectorized
io.print(jds[0], jds[1])                           # 2440587.5 2440588.5
fn auto jd_to_unix(TimeInput auto &&jd) #

Julian Date → Unix epoch seconds.

Parameters
jd

scalar or numeric ndarray of Julian Dates.

Returns

seconds since 1970-01-01T00:00:00Z.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_jd.purr systests/test_vectorized.purr
Example
import io
import space.time as st

io.print(st.jd_to_unix(2451545.0))                 # 946728000.0 — J2000 in Unix seconds
io.print(st.jd_to_unix(st.unix_to_jd(86400.0)))    # 86400.0 — the round trip
fn auto jd_to_mjd(TimeInput auto &&jd) #

Julian Date → Modified Julian Date (MJD = JD − 2400000.5).

Parameters
jd

scalar or numeric ndarray of Julian Dates.

Returns

the Modified Julian Date(s).

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_mjd.purr
Example
import io
import space.time as st

io.print(st.jd_to_mjd(st.jd_j2000()))              # 51544.5 — J2000 as an MJD
fn auto mjd_to_jd(TimeInput auto &&mjd) #

Modified Julian Date → Julian Date.

Parameters
mjd

scalar or numeric ndarray of Modified Julian Dates.

Returns

the Julian Date(s).

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_mjd.purr
Example
import io
import space.time as st

io.print(st.mjd_to_jd(51544.5))                    # 2451545.0 — back to a full JD
fn auto unix_to_mjd(TimeInput auto &&seconds) #

Unix epoch seconds → Modified Julian Date.

Parameters
seconds

scalar or numeric ndarray of seconds since the Unix epoch.

Returns

the Modified Julian Date(s).

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_mjd.purr systests/test_vectorized.purr
Example
import io
import space.time as st

io.print(st.unix_to_mjd(0.0))                      # 40587.0 — the Unix epoch's MJD
fn auto mjd_to_unix(TimeInput auto &&mjd) #

Modified Julian Date → Unix epoch seconds.

Parameters
mjd

scalar or numeric ndarray of Modified Julian Dates.

Returns

seconds since the Unix epoch.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_mjd.purr
Example
import io
import space.time as st

io.print(st.mjd_to_unix(40587.0))                  # 0.0 — the Unix epoch again
fn auto jd_to_j2000_seconds(TimeInput auto &&jd) #

Seconds elapsed since the J2000.0 epoch for a given Julian Date.

Parameters
jd

scalar or numeric ndarray of Julian Dates.

Returns

seconds since 2000-01-01T12:00:00.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_j2000.purr
Example
import io
import space.time as st

io.print(st.jd_to_j2000_seconds(2451546.0))        # 86400.0 — one day after J2000
fn auto jd_to_j2000_centuries(TimeInput auto &&jd) #

Julian centuries (36525 days) elapsed since J2000.0 — the time argument for most astronomical polynomial series (mean sidereal time, precession, …).

Parameters
jd

scalar or numeric ndarray of Julian Dates.

Returns

Julian centuries since J2000.0.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_j2000.purr
Example
import io
import space.time as st

# The `T` fed to precession / sidereal-time polynomial series.
io.print(st.jd_to_j2000_centuries(2451545.0 + 36525.0))   # 1.0 — one Julian century
fn auto unix_to_cdf_epoch(TimeInput auto &&seconds) #

Unix epoch seconds → NASA CDF_EPOCH (milliseconds since year 0).

Feeds space.cdf epoch variables directly. CDF_TT2000 (ns since J2000 with leap seconds) needs a leap-second table and lands with space.cdf — see the cdf roadmap.

Parameters
seconds

scalar or numeric ndarray of seconds since the Unix epoch.

Returns

the CDF_EPOCH value(s) in milliseconds.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_cdf_epoch.purr systests/test_vectorized.purr
Example
import io
import space.time as st

# J2000 as a CDF_EPOCH — ready to write into a CDF epoch variable.
io.print(st.unix_to_cdf_epoch(946728000.0))        # 63113947200000.0
fn auto cdf_epoch_to_unix(TimeInput auto &&ms) #

NASA CDF_EPOCH (milliseconds since year 0) → Unix epoch seconds.

Parameters
ms

scalar or numeric ndarray of CDF_EPOCH values in milliseconds.

Returns

seconds since the Unix epoch.

Complexity

O(n).

Allocation

one result array for an ndarray; none for a scalar.

System testsystests/test_cdf_epoch.purr
Example
import io
import space.time as st

# An epoch read from a CDF file, back onto the Unix scale.
io.print(st.cdf_epoch_to_unix(63113947200000.0))   # 946728000.0 — J2000

Constants & variables

var bool is_datetime_v #

Trait hook for cheatah's forthcoming datetime struct.

It defaults to false; when cheatah::datetime defines its broken-down datetime type, this is specialized to true for it (here or there), which lights up DatetimeScalar / DatetimeArray and the datetime overloads — without this header taking a dependency on that type today.