Skip to content

Time extension#91

Merged
embray merged 5 commits intoasdf-format:mainfrom
jhunkeler:ext-time
Mar 26, 2026
Merged

Time extension#91
embray merged 5 commits intoasdf-format:mainfrom
jhunkeler:ext-time

Conversation

@jhunkeler
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Collaborator

@embray embray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bravo--super nice work.

ASDF_TIME_FORMAT_PLOT_DATE,
ASDF_TIME_FORMAT_YMDHMS,
ASDF_TIME_FORMAT_datetime64,
} asdf_time_base_format;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to add the _t suffix even with type-def'd enums. But I don't have a strict rule about this. Just mentioning it but I won't nitpick over it beyond that ;)

struct asdf_time_info_t {
struct timespec ts;
struct tm tm;
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but then don't use the _t suffix for anything that isn't typedef'd; then it's hard to remember it needs struct :)

src/core/time.c Outdated
const int HOURS_PER_DAY = 24;
const int SECONDS_PER_DAY = 86400;
const int SECONDS_PER_HOUR = 3600;
const int SECONDS_PER_MINUTE = 60;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More stuff should be static around here.

"t_jd",
"t_mjd",
"t_byear",
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can also write parametrized tests with μnit. Not so important here but you can see an example in test-ndarray.c for example (test_numeric_conversion_params).


value = asdf_get_value(file, key);
if (asdf_value_as_time(value, &t) != ASDF_VALUE_OK) {
fprintf(stderr, "asdf_value_as_time failed: %s\n", key);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, you can use

munit_logf("asdf_value_as_time failed: %s\n", key);

for this and other print calls in the tests. And below this you can return MUNIT_FAIL

Implement the asdf/core/time-1.4.0 schema as an extension, supporting
deserialization and serialization of time values from/to ASDF files.

The extension handles these time formats: ISO 8601, ordinal (yday), Unix
epoch, Julian Date, Modified Julian Date, and Besselian year, with
optional time scale and observer location.
Replace mkstemp-based temp file paths (random names scattered in TEMP_DIR)
with per-run numbered subdirectories (TEMP_DIR/000001/, 000002/, ...).

All test binaries that share a process group (i.e. all binaries launched
by a single `make check` invocation) land in the same subdirectory via a
PGID coordination file (TEMP_DIR/.pgid-<PGID>).  The first binary to start
is "pioneer" (wins an O_CREAT|O_EXCL race on the coordination file) and
creates the run directory; subsequent binaries are "followers" that read
the serial from the coordination file and join the same directory.

Coordination files are cleaned up lazily: on startup each binary removes
files whose process group is no longer alive (kill(-pgid, 0) == ESRCH).

Empty run directories are reclaimed on exit via a destructor that calls
rmdir (no-op if non-empty).  The pioneer also reuses the most recent
run directory if it is empty, so clean runs do not accumulate directories.
A "latest" symlink points to the most recently started run for convenience.

test: fix get_total_memory call in parse util tests
@embray embray marked this pull request as ready for review March 26, 2026 14:28
@embray
Copy link
Copy Markdown
Collaborator

embray commented Mar 26, 2026

Finally got around to coming back to this. Fixed a few of my review comments and rebased on main, adding serialization support in the process. While working on this was also motivated to revive a stashed experimental improvement to the test infrastructure for outputting temp files produced by tests. I like this much better now.

embray added 3 commits March 26, 2026 15:31
test: use TEST_SERIAL_FMT macro in more places where it's relevant
@embray embray merged commit fff42e1 into asdf-format:main Mar 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants