Skip to content

Cast DateTime and DateOnly through the MEOS conversions - #68

Merged
estebanzimanyi merged 2 commits into
MobilityDB:mainfrom
estebanzimanyi:fix/time-casts-through-meos
Nov 14, 2026
Merged

estebanzimanyi merged 2 commits into
MobilityDB:mainfrom
estebanzimanyi:fix/time-casts-through-meos

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

Regenerate the functions and types layers from the catalog of MobilityDB master

tools/codegen.py and tools/objectgen.py over the catalog of MobilityDB
master b49672e545 (MEOS-API c13560a8a7): the functions layer gains the
MEOS conversions of the time types, timestamp_to_unix_us,
unix_us_to_timestamp, date_to_unix_days, unix_days_to_date,
interval_to_parts, interval_from_parts, time_to_parts, time_from_parts,
timetz_to_parts and timetz_from_parts, with the ever and always overlaps
of the temporal types and boxes and the box restrictions of the temporal
cells; the object layer gains their methods. GAP-LEDGER.md records the
functions still left to the raw binding.

Measured: dotnet build MEOS.NET.sln -c Release prints 0 warnings, 0
errors; dotnet test passes 106 tests, 0 failing, 0 skipped, and the
ExampleApp smoke run exits 0, against libmeos of the same master.

Cast DateTime and DateOnly through the MEOS conversions

MEOSConvert, which tools/objectgen.py generates, casts a timestamptz
through timestamptz_to_unix_us and unix_us_to_timestamptz, a timestamp
through timestamp_to_unix_us and unix_us_to_timestamp, and a date
through date_to_unix_days and unix_days_to_date, in place of the text of
TimestamptzOut, TimestamptzIn, DateOut and DateIn. A DateTime of UTC or
local kind is a timestamptz at its instant; one of unspecified kind is
read in the zone of the MEOS session through timestamp_to_timestamptz, as
MEOS reads a timestamp without an offset. A tick below a microsecond is
refused with ArgumentOutOfRangeException, and a value the other side
cannot state is refused by the constructor of DateTime or DateOnly. A
MEOS Timestamp maps to its own pair, ToTimestamp and ToUnzonedDateTime,
where the object layer sent it through the timestamptz cast. ExampleApp
drops the ticks below a microsecond of DateTime.UtcNow before it makes an
instant.

Why: a binding casts to the types of its host through the conversions of
MEOS, never through text or arithmetic of its own; the text wrote six
digits of a fraction, dropping the seventh of a tick, and ToUniversalTime
read a DateTime of unspecified kind in the zone of the machine.

Witness: TFloatInst.Make(1.0, 2001-01-01 00:00 of unspecified kind)
answers a start of 2000-12-31 23:00 UTC on a Europe/Brussels machine with
the session in UTC, and now 2001-01-01 00:00 UTC; a moment of
.1234565 s answered .123456 s, and now raises.

Measured: TimeCastTests fails 2 of its 5 tests on main (the tick is
dropped, the unspecified moment is an hour off) and passes all 5 here;
dotnet test passes 111 tests, 0 failing, 0 skipped, under TZ=UTC and
TZ=Europe/Brussels; dotnet build prints 0 warnings; the ExampleApp smoke
run exits 0; against libmeos of MobilityDB master b49672e545.

…yDB master

tools/codegen.py and tools/objectgen.py over the catalog of MobilityDB
master b49672e545 (MEOS-API c13560a8a7): the functions layer gains the
MEOS conversions of the time types, timestamp_to_unix_us,
unix_us_to_timestamp, date_to_unix_days, unix_days_to_date,
interval_to_parts, interval_from_parts, time_to_parts, time_from_parts,
timetz_to_parts and timetz_from_parts, with the ever and always overlaps
of the temporal types and boxes and the box restrictions of the temporal
cells; the object layer gains their methods. GAP-LEDGER.md records the
functions still left to the raw binding.

Measured: dotnet build MEOS.NET.sln -c Release prints 0 warnings, 0
errors; dotnet test passes 106 tests, 0 failing, 0 skipped, and the
ExampleApp smoke run exits 0, against libmeos of the same master.
MEOSConvert, which tools/objectgen.py generates, casts a timestamptz
through timestamptz_to_unix_us and unix_us_to_timestamptz, a timestamp
through timestamp_to_unix_us and unix_us_to_timestamp, and a date
through date_to_unix_days and unix_days_to_date, in place of the text of
TimestamptzOut, TimestamptzIn, DateOut and DateIn. A DateTime of UTC or
local kind is a timestamptz at its instant; one of unspecified kind is
read in the zone of the MEOS session through timestamp_to_timestamptz, as
MEOS reads a timestamp without an offset. A tick below a microsecond is
refused with ArgumentOutOfRangeException, and a value the other side
cannot state is refused by the constructor of DateTime or DateOnly. A
MEOS Timestamp maps to its own pair, ToTimestamp and ToUnzonedDateTime,
where the object layer sent it through the timestamptz cast. ExampleApp
drops the ticks below a microsecond of DateTime.UtcNow before it makes an
instant.

Why: a binding casts to the types of its host through the conversions of
MEOS, never through text or arithmetic of its own; the text wrote six
digits of a fraction, dropping the seventh of a tick, and ToUniversalTime
read a DateTime of unspecified kind in the zone of the machine.

Witness: TFloatInst.Make(1.0, 2001-01-01 00:00 of unspecified kind)
answers a start of 2000-12-31 23:00 UTC on a Europe/Brussels machine with
the session in UTC, and now 2001-01-01 00:00 UTC; a moment of
.1234565 s answered .123456 s, and now raises.

Measured: TimeCastTests fails 2 of its 5 tests on main (the tick is
dropped, the unspecified moment is an hour off) and passes all 5 here;
dotnet test passes 111 tests, 0 failing, 0 skipped, under TZ=UTC and
TZ=Europe/Brussels; dotnet build prints 0 warnings; the ExampleApp smoke
run exits 0; against libmeos of MobilityDB master b49672e545.
@estebanzimanyi
estebanzimanyi merged commit 7bec439 into MobilityDB:main Nov 14, 2026
1 check passed
@estebanzimanyi
estebanzimanyi deleted the fix/time-casts-through-meos branch November 14, 2026 12:57
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