Skip to content
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

Relative formatting of future Date-structs is off by 1 day #775

Open
HansGlimmerfors opened this issue Dec 25, 2024 · 0 comments
Open

Relative formatting of future Date-structs is off by 1 day #775

HansGlimmerfors opened this issue Dec 25, 2024 · 0 comments

Comments

@HansGlimmerfors
Copy link

Steps to reproduce

iex(1)> Timex.format(Timex.shift(Date.utc_today(), days: 1), "{relative}", :relative)
{:ok, "in 3 hours"}
iex(2)> Timex.format(Timex.shift(Date.utc_today(), days: 2), "{relative}", :relative)
{:ok, "tomorrow"}

(note that the number of hours returned by the first call will vary depending on the current system time, e.g. calling the function at 12:00 should instead result in {:ok, "in 12 hours"})

Description of issue

I would expect the relative date of today + 1 day to result in tomorrow, but instead it is today + 2 days that gives tomorrow.
The reason for this is due to Timex.Format.DateTime.Formatters.Relative.lformat/3 which calls Timex.to_naive_datetime/1 on the passed date. The returned value of Timex.to_naive_datetime/1 for a Date-struct is the same date as the Date-struct, but with a time of 00:00:00. This means that a call to Timex.Format.DateTime.Formatters.Relative.lformat/3 when the passed date is a Date-struct in the future, in x days will always be off by 1 day.

I haven't found any examples of past days having incorrect offsets, though! 👍

@HansGlimmerfors HansGlimmerfors changed the title Relative formatting of future Date-structs are off by 1 day Relative formatting of future Date-structs is off by 1 day Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant