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

set/2 : Pre parse/sort options to prevent wrong date creation #738

Closed
Zarathustra2 opened this issue Apr 3, 2023 · 1 comment
Closed

Comments

@Zarathustra2
Copy link

Steps to reproduce

iex(2)> date = ~D[2023-03-31]
~D[2023-03-31]
iex(3)> time =  ~N[2023-04-03 13:30:00]
~N[2023-04-03 13:30:00]
iex(4)> Timex.set(time, day: date.day, month: date.month, year: date.year)
~N[2023-03-30 13:30:00]
iex(5)> Timex.set(time, month: date.month, year: date.year, day: date.day)
~N[2023-03-31 13:30:00]
iex(10)> Timex.set(time, date: {date.year, date.month, date.day})
[date: {2023, 3, 31}]

Description of issue

  • What are the expected results?
    The order of argument put into set/2 matters since Timex.set(time, day: date.day, month: date.month, year: date.year) will not always produce the same result as Timex.set(time, month: date.month, year: date.year, day: date.day)

Technically the user could/should have used the date option but this may not always be obvious.

I kinda propose to either pre parse the options to convert month, year & day options into a single date option or sort the options list by importance such that year is being set first, month second and day third (in our example).

What are you thinking?

Would happily work on this! :)

@Zarathustra2
Copy link
Author

Oh there is a PR for this issue already: #671

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