You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I want to know how I can get a Previous Ocurrence from a Cron expression. I tried reading the source code but couldn't understand how it works. The only i could get it is expression.GetOccurence(DateTime.MinValue.ToUniversalTime(), fromUTC).Reverse().Skip(1).First(). Is there a better way to do this?
Does this request makes sense to add as a feature? If so what can I read to better my understanding of the algorithm used so I can implement it myself.
Ty in advance
The text was updated successfully, but these errors were encountered:
I've recently created a library called Occurify.TimeZones that can be used to do just this. It uses Cronos under the hood and is also licensed under The MIT License (MIT):
TimeZoneInstants.FromCron gives you a ITimeline you can traverse in both directions.
Implementation
The implementation is simular to what you suggest in your comment. It will take the difference between the very first instant and the second instant to create a search window duration. Using that duration, it will simply loop back and get all instances within that duration relative to where the search starts, then take the last instant of that. Since cron intervals are roughly the same, usually it only takes 1 or 2 iterations to find what we need. Source: here.
Hello, I want to know how I can get a Previous Ocurrence from a Cron expression. I tried reading the source code but couldn't understand how it works. The only i could get it is expression.GetOccurence(DateTime.MinValue.ToUniversalTime(), fromUTC).Reverse().Skip(1).First(). Is there a better way to do this?
Does this request makes sense to add as a feature? If so what can I read to better my understanding of the algorithm used so I can implement it myself.
Ty in advance
The text was updated successfully, but these errors were encountered: