timex icon indicating copy to clipboard operation
timex copied to clipboard

Fix: preserve datetime precision after Timex.shift/2

Open tfiedlerdejanze opened this issue 1 year ago • 4 comments

Summary of changes

Resolves https://github.com/bitwalker/timex/issues/731

Unfortunately this broke with https://github.com/elixir-lang/elixir/commit/5a583c753b96865a7cdec2fb4c1ab9c96b836d24 which was released with Elixir 1.14.3

As Timex.shift/2 calculates the total microseconds of the shift options and then uses DateTime.add/4 to apply, Elixir returns a new datetime with the highest precision it finds (microseconds) opposed to keeping the original precision.

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]

tfiedlerdejanze avatar Apr 13 '23 10:04 tfiedlerdejanze

@bitwalker is this a change you'd be considering for Timex?

tfiedlerdejanze avatar Apr 20 '23 12:04 tfiedlerdejanze

@bitwalker Do you have any time plans for reviewing/merging this PR?

"I don't have time" is also a totally fine answer that helps us plan accordingly. Thank you for your efforts!

ftes avatar May 15 '23 06:05 ftes

Thank you doing this work. I've been unable to complete an upgrade to 1.14 as a huge number of our legacy database tables were created w/ resolution only down to the second. We thankfully have a shim layer where we can perform this for as well, but would love to see this merged to make our testing a little easier

petermueller avatar May 19 '23 16:05 petermueller

Any chance of getting this merged? 🙏🏻

edennis avatar Oct 10 '23 11:10 edennis