Commit d25e922
authored
fix: fix double division, fix loss of millisecond unit (#1221)
This PR fixes an issue I introduced in the initial `useDate=temporal` PR
[here](#1219). 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:
```typescript
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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/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 `Instant`s whose string representations were clearly
different, so now we will test against the output string.1 parent feab2c9 commit d25e922
File tree
5 files changed
+23
-15
lines changed- integration
- grpc-js-use-date-temporal-bigint
- grpc-js-use-date-temporal
- src
5 files changed
+23
-15
lines changedLines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
993 | 993 | | |
994 | 994 | | |
995 | 995 | | |
996 | | - | |
| 996 | + | |
997 | 997 | | |
998 | 998 | | |
999 | | - | |
1000 | | - | |
1001 | | - | |
| 999 | + | |
1002 | 1000 | | |
1003 | 1001 | | |
1004 | 1002 | | |
| |||
0 commit comments