-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timex.shift/2 with time-shift always converts precision to :microsecond in Elixir v1.14+ #731
Comments
That change went live in Elixir 1.14.3, so the versions prior to that work fine still. |
Same happend to NaiveDatetime, as it converts the NaiveDateTime to DateTime under the hood. timex/lib/datetime/naivedatetime.ex Lines 238 to 240 in e1c4d42
It uses the iex(1)> now = ~N[2023-03-31 10:31:57]
iex(2)> Timex.shift(now, hours: 1)
~N[2023-03-31 11:31:57.000000] This breaks some of my code (using ecto), with the error "...naive_datetime expects microseconds to be empty...", where just The intended behaviour is to only add microseconds when subsecond precisions is requested. https://github.com/elixir-lang/elixir/blob/5a583c753b96865a7cdec2fb4c1ab9c96b836d24/lib/elixir/lib/calendar/naive_datetime.ex#L379-L387 |
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Resolves bitwalker#731 Unfortunately this broke with elixir-lang/elixir@5a583c7 which was release with Elixir 1.14.3 Elixir 1.13.4: ``` iex(3)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:56:10.136274Z] ~U[2023-04-13 09:56:10Z] ~U[2023-04-13 09:57:10Z] ``` Elixir 1.14.4: ``` iex(1)> DateTime.utc_now() |> IO.inspect() |> DateTime.truncate(:second) |> IO.inspect() |> Timex.shift(minutes: 1) |> IO.inspect() ~U[2023-04-13 09:55:16.405357Z] ~U[2023-04-13 09:55:16Z] ~U[2023-04-13 09:56:16.000000Z] ```
Steps to reproduce
with Elixir v1.13
with Elixir v1.14
Description of issue
Time.add
behaviour changed in 1.14 elixir-lang/elixir#12303:microsecond
precision to apply time-shift result.timex/lib/datetime/datetime.ex
Line 450 in e1c4d42
This causes unnecessary precision conversions in Elixir v1.14 and later.
The text was updated successfully, but these errors were encountered: