Skip to content

Conversation

@confusingstraw
Copy link
Contributor

@confusingstraw confusingstraw commented Oct 22, 2025

This PR fixes an issue I introduced in the initial useDate=temporal PR here. The generated code for toTimestamp was dividing the epochMilliseconds twice, causing the date to get truncated to 1970-01-01, so the tests would seem to work for dates.

There was also a bug in how nanos was calculated:

Temporal.Instant
    .fromEpochMilliseconds(instant.epochMilliseconds)
    .until(instant);

since we were deriving the start date from epochMilliseconds, so the remainder only included micro/nanoseconds (milliseconds were always 000).

The PR addresses the first issue by ensuring we only divide once, in the generated seconds code. It fixes the latter by using the built-in Temporal.Instant.prototype.round method to round to the nearest second without needing to do any explicit math.

Lastly, it also updates the tests, as the toStrictEqual check was succeeding even for Instants whose string representations were clearly different, so now we will test against the output string.

@stephenh
Copy link
Owner

Nice, great idea to use their round method.

@stephenh stephenh merged commit d25e922 into stephenh:main Oct 22, 2025
7 checks passed
stephenh pushed a commit that referenced this pull request Oct 22, 2025
## [2.8.1](v2.8.0...v2.8.1) (2025-10-22)

### Bug Fixes

* fix double division, fix loss of millisecond unit ([#1221](#1221)) ([d25e922](d25e922))
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 2.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants