Skip to content

Read missing, infinite and fractional-millisecond datetimes and durations - #254

Open
Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:missing-datetimes
Open

Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:missing-datetimes

Conversation

@Thenewmanator15

Copy link
Copy Markdown

A datetime array holding NaT, or a duration holding NaN or a fractional number of milliseconds, is not converted at all today: the conversion throws — DateTime of NaN, Millisecond(1.5), Millisecond(NaN) — and the variable comes back as its raw uint32 MCOS reference (UInt32[0xdd000000, 0x2, …]) instead of values. Fractional milliseconds are common in real durations (milliseconds(1.5), seconds(0.0025)), so any such array was affected, as was every datetime array with a gap.

With this change:

  • NaT and NaN durations become missing, so an array holding one is Union{Missing,DateTime} / Union{Missing,Millisecond}; arrays without one keep their concrete element type;
  • ±Inf datetimes (which DateTime cannot hold) are missing too;
  • durations are rounded to whole milliseconds, as datetimes already are.

The comment asking whether a stored datetime's imaginary part is the sub-millisecond part now answers it: it is the low half of a double-double, below half an ulp of the real part, so real + imag == real in Float64 and nothing is lost at DateTime resolution.

Tests, and the same request as #253. test/missing_gen.m writes test/v7/missing_times.mat and test/v7.3/missing_times.mat: NaT in an array, alone, and with a time zone; ±Inf datetimes; NaN durations, in an array and alone; 1.5, 2.25 and 2.75 ms. I can't contribute the .mat files, so they are not included — could someone with MATLAB run the script in test/ and commit its two files? Until then the testset skips. Against the files the script writes (MATLAB R2025a), on master all seven variables come back as raw uint32 references in both formats; with this change the full suite passes (599). Without the files: 581 pass, 2 skipped.

Not in scope: writing arrays with missing datetimes or durations back to a file.

🤖 Generated with Claude Code

…ions

A datetime array holding NaT, or a duration holding NaN or a fractional number of
milliseconds, was not converted at all: the conversion threw (DateTime of NaN,
Millisecond(1.5) or Millisecond(NaN)), and the object came back as its raw uint32
MCOS reference. Missing and infinite values now become `missing` (so an array with
one is Union{Missing,DateTime} or Union{Missing,Millisecond}), and durations are
rounded to whole milliseconds, as datetimes already were.

test/missing_gen.m writes test/v7 and test/v7.3/missing_times.mat (NaT in an array,
alone and with a time zone; ±Inf datetimes; NaN durations; 1.5, 2.25 and 2.75 ms).
The .mat files are not included; the testset is skipped until they are generated
in MATLAB and committed.

This branch has not been deployed

No deployments
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.

1 participant