1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/**
* Data type and extension for the ``stsci.edu/schemas/asdf/time/time`` schema
*/
//
/** .. _time-types:
*
* Types
* -----
*/
/**
* The representation format of a time.
*
* These correspond to the astropy time formats and the schema's ``format`` /
* ``base_format`` enums. The values from ``ASDF_TIME_FORMAT_BYEAR_STR`` onward
* are the schema's ``other_format`` values, which are valid only in
* ``base_format`` on the wire; see `asdf_time_t` ``format`` for how the two
* collapse into a single effective format.
*/
typedef enum asdf_time_format_t;
/** The time scale (time standard), as in the schema's ``scale`` field. */
typedef enum asdf_time_scale_t;
/** Observer location, used by location-sensitive scales such as ``tdb``. */
typedef struct asdf_time_location_t;
/**
* Best-effort calendar representation of a parsed time
*
* These fields are *computed* from ``value`` / ``format`` / ``scale`` purely
* for convenience. The authoritative instant is always the ``value``,
* ``format`` and ``scale``, 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. ``scale`` other than
* `ASDF_TIME_SCALE_UTC`, and the atomic-scale formats ``gps``, ``unix_tai``,
* ``cxcsec`` and ``tai_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``, ``tcb`` and
* ``tcg`` scales 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`` / ``scale`` themselves (e.g. via ERFA
* or astropy).
*/
typedef struct asdf_time_info_t;
/**
* A single instant in time, as read from or written to a ``time/time`` tag.
*
* The instant is defined by `value` together with `format` and `scale`; `info`
* is a derived, best-effort calendar representation for convenience.
*/
typedef struct asdf_time_t;
;
/** .. _time-accessors:
*
* Accessors
* ---------
*/
// clang-format off
/**
* .. c:function:: bool asdf_is_time(asdf_file_t *file, const char *path)
*
* Test whether the value at ``path`` in the tree is a ``time/time`` object
*
* :param file: The `asdf_file_t *` for the file
* :param path: The :ref:`yaml-pointer` to the value
* :return: ``true`` if the value exists and is a time, otherwise ``false``
*/
/**
* .. c:function:: 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`.
*
* :param file: The `asdf_file_t *` for the file
* :param path: The :ref:`yaml-pointer` to the time
* :param out: An `asdf_time_t **` into which the `asdf_time_t *` is returned
* :return: `ASDF_VALUE_OK` if the value exists and is a time, otherwise
* `ASDF_VALUE_ERR_NOT_FOUND` or `ASDF_VALUE_ERR_TYPE_MISMATCH`.
*/
/**
* .. c:function:: 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``, ``scale`` and ``location`` fields need be
* populated; the derived `asdf_time_info_t` ``info`` is not required for
* writing.
*
* :param file: The `asdf_file_t *` for the file
* :param path: The :ref:`yaml-pointer` for the time
* :param time: An `asdf_time_t *` to store
* :return: `ASDF_VALUE_OK` on success, otherwise an error code
*/
/**
* .. c:function:: bool asdf_value_is_time(asdf_value_t *value)
*
* Test whether a generic `asdf_value_t *` is a ``time/time`` object
*
* :param value: The `asdf_value_t *` handle
* :return: ``true`` if ``value`` is a time, otherwise ``false``
*/
/**
* .. c:function:: 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`.
*
* :param value: The `asdf_value_t *` handle
* :param out: An `asdf_time_t **` into which the `asdf_time_t *` is returned
* :return: `ASDF_VALUE_OK` if ``value`` is a time, otherwise
* `ASDF_VALUE_ERR_TYPE_MISMATCH`.
*/
/**
* .. c:function:: void asdf_time_destroy(asdf_time_t *time)
*
* Free an `asdf_time_t *` returned by `asdf_get_time` or `asdf_value_as_time`
*
* :param time: The `asdf_time_t *` to free
*/
// clang-format on
/** .. _time-parsing:
*
* Parsing and formatting
* ----------------------
*/
/**
* Parse `time`'s ``value`` (according to its ``format``) into the derived
* `asdf_time_info_t` ``info`` fields.
*
* This is called automatically during deserialization; it may be called again
* after changing ``value`` or ``format``. See `asdf_time_info_t` for the
* accuracy caveat on non-UTC scales.
*
* :param time: The time to parse; its ``info`` is filled in on success.
* :return: ``0`` on success, or ``-1`` on failure (e.g. an unsupported or
* unparseable ``value``).
*/
ASDF_EXPORT int ;
/**
* Return the schema string name of a time format (e.g. ``"iso"``, ``"jd"``).
*
* :param format: A time format.
* :return: The format's name, or ``NULL`` if `format` is out of range or has no
* string representation.
*/
ASDF_EXPORT const char *;
/** .. _time-defines:
*
* Defines
* -------
*/
/** Tag URI prefix for time objects; a version is appended (e.g. ``"1.4.0"``). */
/**
* 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 the ``ASDF_REGISTER_EXTENSION`` call in ``time.c``.
*/
/** Maximum length in bytes of a time `asdf_time_t` ``value`` string. */
/* ASDF_CORE_TIME_H */