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

Wrong DateTime with "1 1 1 31 * ?" #73

Closed
graingert opened this issue Apr 20, 2017 · 8 comments
Closed

Wrong DateTime with "1 1 1 31 * ?" #73

graingert opened this issue Apr 20, 2017 · 8 comments
Labels
Milestone

Comments

@graingert
Copy link

scala> val oldDate = new DateTime("2016-09-04T00:00:00.000Z", DateTimeZone.UTC)
oldDate: org.joda.time.DateTime = 2016-09-04T00:00:00.000Z

scala> Cron.unsafeParse("1 1 1 31 * ?").next(oldDate)
res33: Option[org.joda.time.DateTime] = None

scala> Cron.unsafeParse("1 1 1 30 * ?").next(oldDate)
res34: Option[org.joda.time.DateTime] = Some(2016-09-30T01:01:01.000Z)

Should be Some(2016-10-31T01:01:01.000Z)

@graingert
Copy link
Author

It seems totally bizarre because I can match a time in the future from "2016-09-04T00:00:00.000Z"

scala> val newDate = new DateTime("2016-10-31T01:01:01.000Z", DateTimeZone.UTC)
newDate: org.joda.time.DateTime = 2016-10-31T01:01:01.000Z

scala> Cron.unsafeParse("1 1 1 31 * ?").allOf(newDate)
res44: Boolean = true

@graingert
Copy link
Author

This also happens for "1 1 1 30 * ?" with an input date in February.

scala> val oldDate = new DateTime("2016-02-04T00:00:00.000Z", DateTimeZone.UTC)
oldDate: org.joda.time.DateTime = 2016-02-04T00:00:00.000Z

scala> Cron.unsafeParse("1 1 1 30 * ?").next(oldDate)
res46: Option[org.joda.time.DateTime] = None

It seems that cron is forgetting to roll on the month in this case.

@alonsodomin
Copy link
Owner

I see, surely what's happening here is that each field is getting rolled up individually from each other and when the turn comes for the day of month, it fails because the month of the original date is wrong as it hasn't been rolled up yet.

The reason why it works when matching is because the match operations do not perform any date field rolling, therefore, if you are able to have a DateTime object, the cron expression will always be able to tell you if it matches or not.

This is not too difficult to solve so I'll try to get something working ASAP. Thanks for reporting!

@alonsodomin alonsodomin added this to the 0.4.1 milestone Apr 20, 2017
@graingert
Copy link
Author

@alonsodomin any update on this?

@alonsodomin
Copy link
Owner

@graingert Nothing really worth mentioning yet, been quite busy with a series of personal matters and did not have any serious time to dedicate to this.

I did prototype a couple of solutions but this has highlighted the fact that there is a design flaw in the date-time integration. I expect to be able to tackle in the next weeks as soon as I get some free time.

@groblochon
Copy link

Hi !

val cronExp = "0 0 2 ? * *"
val Right(cron) = Cron(cronExp)
val previous = cron.prev(LocalTime.now())

In this case, previous is None.

@alonsodomin
Copy link
Owner

A fix has been merged into master, a new release will be published in the next days.

@graingert
Copy link
Author

graingert commented Jul 14, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants