bitwalker / bitwalker/timex

Timex.shift/2 with time-shift always converts precision to :microsecond in Elixir v1.14+

Open
#731 2 comments 10 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

### Steps to reproduce

with Elixir v1.13
```elixir
iex(1)> now = ~U[2023-01-01 10:20:30Z]
~U[2023-01-01 10:20:30Z]
iex(2)> Timex.shift(now, hours: 1)
~U[2023-01-01 11:20:30Z] # OK
```

with Elixir v1.14
```elixir
iex(1)> now = ~U[2023-01-01 10:20:30Z]
~U[2023-01-01 10:20:30Z]
iex(2)> Timex.shift(now, hours: 1)
~U[2023-01-01 11:20:30.000000Z] # precision changes unnecessarily
```

### Description of issue

- Elixir v1.14 changes DateTime.add/4 behaviour to preserve the maximum precision of given parameters.
- commit: https://github.com/elixir-lang/elixir/commit/5a583c753b96865a7cdec2fb4c1ab9c96b836d24
- relates to: https://github.com/elixir-lang/elixir/issues/12303
- Timex.shift/2 uses DateTime.add/4 with `:microsecond` precision to apply time-shift result.
- https://github.com/bitwalker/timex/blob/e1c4d424a5c7840f63efd33cd70e3b5d4f9bfaa1/lib/datetime/datetime.ex#L450

This causes unnecessary precision conversions in Elixir v1.14 and later.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.