Skip to content

Issue #233 -- time improvements - #235

Merged
embray merged 10 commits into
asdf-format:mainfrom
embray:issue-233
Jul 24, 2026
Merged

Issue #233 -- time improvements#235
embray merged 10 commits into
asdf-format:mainfrom
embray:issue-233

Conversation

@embray

@embray embray commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Description

Resolves #233 , adding support from time<=1.4.0, and the base_format property for time>=1.2.

In scrutinizing the schemas I noticed that the iso format was mishandled--it's just called iso, not iso_time (I think that name might have been accidentally read from the defines).

Resolves #208 as well, except for time array handling which is deferred to #237

AI Disclosure

No AI tools used.

@embray embray changed the title Issue 233 Issue #233 -- time improvements Jul 22, 2026
embray added 4 commits July 22, 2026 14:05
Especially on serialization it's important to write the format as
the _str variants if the values are actually strings with
epoch prefixed-values, simply as that is what existing software (both
asdf-astropy, and by extension astropy itself) will accept.
This is effectively equivalent to just the "iso" format.  In principle
should require a 'T' in the time string but we don't really worry about
it and lean towards flexibility; it's more a question for serialization.
@embray

embray commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

The proper handling of the Astropy-specific "other_formats" is even weirder than I thought. AFAICT the right approach is to serialize them as "iso" format strings, though the "fits" format is kind of an odd case too because it supports this extended year format (signed, five-digit years) which is actually not "iso" or one of what it considers a "guessable format".

Actually, after some experimentation, it turns out this case does not even work properly in Astropy despite what the documentation says:

tf = Time('-12000-07-23T11:36:10', format='fits', in_subfmt='longdate_hms')
...
ValueError: Input values did not match the format class fits:
ErfaError: ERFA function "dtf2d" yielded 1 of "bad year"

I realize this is an edge case that I shouldn't spend too much time on, but I think this is a good exercise in stress-testing the schema and the specification, because right now I think it's a bit under-cooked when it comes to these Astropy-specific cases, and the behavior for handling them seems only specified in code for now (in asdf_astropy, which converts most of these Astropy-specific formats to ISO format as far as I can tell...except...that isn't always correct).

embray added 3 commits July 23, 2026 14:41
After re-reading the schema again and TimeConverter in asdf_astropy I
have a better understanding of how base_format is used, and that the
"format" property should, if correct within the schema, *never* contain
one of the Astropy other-formats.

This presents several challenges for how to handle this in the API, but
what I settled on is to delete the previously added
`asdf_time_t.base_format` field.  `asdf_time_t.format` is always the
*effective* format (e.g. fits, datetime) as read from the file (taking
into account base_format) or specified by the user.  The standard "wire"
format--what's written in the file to the "format" property is always
one of the ASDF-supported formats, and where no other direct
representation of that format is possible, we try to convert to an ISO
time string, which is close to what asdf_astropy does.

There is a hairy corner-case in the case of the "fits" format when it
uses extended signed five-digit years.  Here we refuse to specify a
"format" (only "base_format").  libasdf will handle this correctly;
Astropy + asdf_astropy may not but that is a bug there, and one that
probably doesn't come up often.
includes gps, galexsec, cxcsec, tai, unix_tai, utime; this is a best
effort minimal approach that doesn't account for leap seconds when
converting to timestamps, which is documented.
This is really a mess because ASDF has no internal representation for
these so always serializes them in "isot" format effectively.  This also
led to finding a bug in plot_date along similar lines--asdf_astropy can
write a plot_date as an ISO format string, but it is also allowed to be
a float technically, so we have to be extra careful in round-tripping it
in the former case.

All the more reason these time formats need to be clarified better
because I'm just guessing here as to what the best behavior is really
intended to be...
@embray embray added enhancement New feature or request standard-compliance Missing feature required to meet fully compliance with the ASDF standard labels Jul 24, 2026
@embray
embray merged commit b945618 into asdf-format:main Jul 24, 2026
12 checks passed
@embray
embray deleted the issue-233 branch July 24, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request standard-compliance Missing feature required to meet fully compliance with the ASDF standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand time tag support time parsing improvements

1 participant