asdf/core/time.h - Time tag operations¶
Data type and extension for the stsci.edu/schemas/asdf/time/time schema
Types¶
-
enum asdf_time_format_t¶
The representation format of a time.
These correspond to the astropy time formats and the schema’s
format/base_formatenums. The values fromASDF_TIME_FORMAT_BYEAR_STRonward are the schema’sother_formatvalues, which are valid only inbase_formaton the wire; see asdf_time_tformatfor how the two collapse into a single effective format.-
enumerator ASDF_TIME_FORMAT_ISO = 0¶
ISO 8601 date-time,
YYYY-MM-DDTHH:MM:SS.sss...(the default)
-
enumerator ASDF_TIME_FORMAT_YDAY¶
Year, day-of-year and time,
YYYY:DOY:HH:MM:SS.sss...
-
enumerator ASDF_TIME_FORMAT_BYEAR¶
Besselian epoch year, e.g.
B1950.0
-
enumerator ASDF_TIME_FORMAT_JYEAR¶
Julian epoch year, e.g.
J2000.0
-
enumerator ASDF_TIME_FORMAT_DECIMALYEAR¶
Decimal year, integer values being the start of the year
-
enumerator ASDF_TIME_FORMAT_JD¶
Julian Date: days since the start of the Julian period
-
enumerator ASDF_TIME_FORMAT_MJD¶
Modified Julian Date: days since 1858-11-17 00:00
-
enumerator ASDF_TIME_FORMAT_GPS¶
GPS time: seconds from 1980-01-06 00:00:00 UTC
-
enumerator ASDF_TIME_FORMAT_UNIX¶
Unix time: seconds from 1970-01-01 00:00:00 UTC, ignoring leap seconds
-
enumerator ASDF_TIME_FORMAT_UTIME¶
UT seconds from 1979-01-01 00:00:00 UTC, ignoring leap seconds
-
enumerator ASDF_TIME_FORMAT_TAI_SECONDS¶
SI seconds from 1958-01-01 00:00:00, including leap seconds (TAI)
-
enumerator ASDF_TIME_FORMAT_CXCSEC¶
Chandra X-ray Center seconds from 1998-01-01 00:00:00 TT
-
enumerator ASDF_TIME_FORMAT_GALEXSEC¶
GALEX time: seconds from 1980-01-06 00:00:00 UTC
-
enumerator ASDF_TIME_FORMAT_UNIX_TAI¶
SI seconds from 1970-01-01 00:00:00 TAI
-
enumerator ASDF_TIME_FORMAT_RESERVED1¶
Reserved; not a usable format
-
enumerator ASDF_TIME_FORMAT_BYEAR_STR¶
Besselian epoch string form, e.g.
B1950.0
-
enumerator ASDF_TIME_FORMAT_DATETIME¶
A Python
datetime.datetime(naive or timezone-aware)
-
enumerator ASDF_TIME_FORMAT_FITS¶
FITS date-time string; permits a signed five-digit “long” year
-
enumerator ASDF_TIME_FORMAT_ISOT¶
ISO 8601 with a literal
Tdate/time separator
-
enumerator ASDF_TIME_FORMAT_JYEAR_STR¶
Julian epoch string form, e.g.
J2000.0
-
enumerator ASDF_TIME_FORMAT_PLOT_DATE¶
matplotlib ordinal: days from 0001-01-01 00:00:00 UTC plus one
-
enumerator ASDF_TIME_FORMAT_YMDHMS¶
Year/month/day/hour/minute/second fields
-
enumerator ASDF_TIME_FORMAT_DATETIME64¶
NumPy
datetime64
-
enumerator ASDF_TIME_FORMAT_ISO = 0¶
-
enum asdf_time_scale_t¶
The time scale (time standard), as in the schema’s
scalefield.-
enumerator ASDF_TIME_SCALE_UTC = 0¶
Coordinated Universal Time (the default scale)
-
enumerator ASDF_TIME_SCALE_TAI¶
International Atomic Time
-
enumerator ASDF_TIME_SCALE_TCB¶
Barycentric Coordinate Time
-
enumerator ASDF_TIME_SCALE_TCG¶
Geocentric Coordinate Time
-
enumerator ASDF_TIME_SCALE_TDB¶
Barycentric Dynamical Time
-
enumerator ASDF_TIME_SCALE_TT¶
Terrestrial Time
-
enumerator ASDF_TIME_SCALE_UT1¶
Universal Time (UT1)
-
enumerator ASDF_TIME_SCALE_UTC = 0¶
-
struct asdf_time_location_t¶
Observer location, used by location-sensitive scales such as
tdb.
-
struct asdf_time_info_t¶
Best-effort calendar representation of a parsed time
These fields are computed from
value/format/scalepurely for convenience. The authoritative instant is always thevalue,formatandscale, which libasdf preserves verbatim and round-trips losslessly; only this derived representation is approximate.Warning
For any time not on the UTC scale, i.e.
scaleother than ASDF_TIME_SCALE_UTC, and the atomic-scale formatsgps,unix_tai,cxcsecandtai_seconds, these fields ignore leap seconds. libasdf has no leap-second table, so it does not apply the TAI/TT-to-UTC offsets.The computed calendar reading is therefore in the format’s own timescale, off from UTC by the relevant offset. The
tdb,ut1,tcbandtcgscales need still more external data and are likewise approximate.Consumers needing an exact UTC instant for a non-UTC-scale time should convert the raw
value/format/scalethemselves (e.g. via ERFA or astropy).-
struct timespec ts¶
Seconds + nanoseconds from the Unix epoch (approximate; see above)
-
struct timespec ts¶
-
struct asdf_time_t¶
A single instant in time, as read from or written to a
time/timetag.The instant is defined by value together with format and scale; info is a derived, best-effort calendar representation for convenience.
-
char *value¶
The time value, exactly as it appears (or will appear) in the file.
-
asdf_time_info_t info¶
Derived calendar representation; best-effort and, for non-UTC scales, approximate. See asdf_time_info_t for the leap-second caveat.
-
asdf_time_format_t format¶
The effective (real) format of the time.
This may be any format, including one of the schema’s
other_formatvalues (e.g.fits,isot,plot_date) which the schema only permits in thebase_formatfield on the wire. On deserialization theformatandbase_formatkeys are collapsed into this single effective format (base_formatoverridesformatwhen present); on serialization the wireformat/base_formatsplit is derived back from it.
-
asdf_time_scale_t scale¶
The time scale. A non-UTC scale means the derived
infofields are approximate (leap seconds are not applied); see asdf_time_info_t.
-
asdf_time_location_t location¶
Observer location; used only by location-sensitive scales (e.g.
tdb).
-
char *value¶
Accessors¶
-
bool asdf_is_time(asdf_file_t *file, const char *path)¶
Test whether the value at
pathin the tree is atime/timeobject- Parameters:
file – The asdf_file_t* for the file
path – The YAML Pointer to the value
- Returns:
trueif the value exists and is a time, otherwisefalse
-
asdf_value_err_t asdf_get_time(asdf_file_t *file, const char *path, asdf_time_t **out)¶
Get an asdf_time_t* out of the ASDF tree
The returned object is owned by the caller and must be freed with asdf_time_destroy.
- Parameters:
file – The asdf_file_t* for the file
path – The YAML Pointer to the time
out – An asdf_time_t** into which the asdf_time_t* is returned
- Returns:
ASDF_VALUE_OK if the value exists and is a time, otherwise ASDF_VALUE_ERR_NOT_FOUND or ASDF_VALUE_ERR_TYPE_MISMATCH.
-
asdf_value_err_t asdf_set_time(asdf_file_t *file, const char *path, const asdf_time_t *time)¶
Store an asdf_time_t* at a path in the ASDF tree
Only the
value,format,scaleandlocationfields need be populated; the derived asdf_time_info_tinfois not required for writing.- Parameters:
file – The asdf_file_t* for the file
path – The YAML Pointer for the time
time – An asdf_time_t* to store
- Returns:
ASDF_VALUE_OK on success, otherwise an error code
-
bool asdf_value_is_time(asdf_value_t *value)¶
Test whether a generic asdf_value_t* is a
time/timeobject- Parameters:
value – The asdf_value_t* handle
- Returns:
trueifvalueis a time, otherwisefalse
-
asdf_value_err_t asdf_value_as_time(asdf_value_t *value, asdf_time_t **out)¶
Interpret a generic asdf_value_t* as a time value, if possible
The returned object is owned by the caller and must be freed with asdf_time_destroy.
- Parameters:
value – The asdf_value_t* handle
out – An asdf_time_t** into which the asdf_time_t* is returned
- Returns:
ASDF_VALUE_OK if
valueis a time, otherwise ASDF_VALUE_ERR_TYPE_MISMATCH.
-
void asdf_time_destroy(asdf_time_t *time)¶
Free an asdf_time_t* returned by asdf_get_time or asdf_value_as_time
- Parameters:
time – The asdf_time_t* to free
Parsing and formatting¶
-
int asdf_time_parse(asdf_time_t *time)¶
Parse time’s
value(according to itsformat) into the derived asdf_time_info_tinfofields.This is called automatically during deserialization; it may be called again after changing
valueorformat. See asdf_time_info_t for the accuracy caveat on non-UTC scales.- Parameters:
time – The time to parse; its
infois filled in on success.
- Returns:
0on success, or-1on failure (e.g. an unsupported or unparseablevalue).
-
const char *asdf_time_format_string(asdf_time_format_t format)¶
Return the schema string name of a time format (e.g.
"iso","jd").- Parameters:
format – A time format.
- Returns:
The format’s name, or
NULLif format is out of range or has no string representation.
Defines¶
-
ASDF_CORE_TIME_TAG_BASE¶
Tag URI prefix for time objects; a version is appended (e.g.
"1.4.0").
-
ASDF_CORE_TIME_TAG¶
The time tag written by libasdf, and the newest version it reads.
Older versions (
ASDF_CORE_TIME_TAG_BASE"1.x.0") are also recognized when reading; see theASDF_REGISTER_EXTENSIONcall intime.c.
-
ASDF_TIME_TIMESTR_MAXLEN¶
Maximum length in bytes of a time asdf_time_t
valuestring.