Skip to content

Next-date miscalculation for dates at the end of months followed by a shorter month #2

@brendonjwong

Description

@brendonjwong

I encountered a bug where dates at the end of months (e.g. March 30) that are followed by shorter months (in this case April) will get an incorrect next-date with the cron string "0 0 0 1 * *.

Examples:

(cronp/next-date (time/date-time 2020 3 30) "0 0 0 1 * *")

;; expected
#<org.joda.time.DateTime@1434863 2020-04-01T00:00:00.000Z>

;; actual
#<org.joda.time.DateTime@1434863 2020-03-31T00:00:00.000Z>

;; -------------------------------------------------------
(cronp/next-date (time/date-time 2020 1 30) "0 0 0 1 * *")

;; expected
#<org.joda.time.DateTime@4e6d20b 2020-02-01T00:00:00.000Z>

;; actual
#<org.joda.time.DateTime@4e6d20b 2020-01-30T00:00:00.000Z>

I've tracked the bug down to this line in the now-with-doms function: https://github.com/shmish111/clj-cron-parse/blob/b503a2dd96d6574fdc807947aacabd9c293b376d/src/clj_cron_parse/core.clj#L234

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions