Skip to content

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

Description

@Zarathustra2

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! :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions