maennchen / crontab

Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
https://hex.pm/packages/crontab
MIT License
92 stars 32 forks source link

inc_month may skip a month #57

Closed xingd closed 5 years ago

xingd commented 5 years ago

The following statements

~N[2019-05-31 23:00:00] |> Crontab.DateHelper.inc_month

returns ~N[2019-07-01 23:00:00].

Two workaround, add fewer days:

  def inc_month(%NaiveDateTime{day: day} = date) do
    days =
      date
      |> NaiveDateTime.to_date()
      |> Date.days_in_month()

    NaiveDateTime.add(date, (days + 1 - day) * 86_400, :second)
  end

or change function call order:

  defp correct_date(:month, date, :increment),
    do: date |> DateHelper.beginning_of(:month)  |> DateHelper.inc_month()
maennchen commented 5 years ago

@xingd Thanks for the report. A fix has been published with v1.1.6.