bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 245 forks source link

Please help me construct "minute of year" time period #197

Open denna10 opened 7 years ago

denna10 commented 7 years ago

Hello! First and foremost I'd like to say that LaterJS is very useful, and that I'm very thankful for all the hard work that has been put into it!

The problem I need help with is the following: I need to be able to construct schedules like for example starting today at 08:45 and repeat every 134 minutes, or maybe reapeat every 2.75 days. I was thinking about how I should express this with recur, but I couldn't find a soultion. I wasn't able to achieve this with ("08:15").time().every(134).minute() or every(134),minute().startingOn(8.25).hour().

Therefore I thought a "minute of year" time period could be the solution. For example 08:15 would be minute 495, and if it recurs every 135 minutes, the next occurrence would be on minute 630, and if it recurs every 2.75 days, it would be on minute 4455.

Unfortunately I seem to lack the skills and understanding to be able to construct this custom time period. I have tried to understand how other time periods are constructed and steal/modify the code, but so far it has only resulted in exciting and unpredictable time travels.

So if any of you kind souls would like to help me out, I'd be most grateful! Many thanks in advance!

later.minuteOfYear = later.my = { name: "minute of year", range: 60, extent: function(d) { var year = later.Y.val(d); return d.myExtent = [ 1, year % 4 ? (3652460) : (3662460) ]; },

val: function(d) { ???}, isValid: function(d, val) {???}, start: function(d) { ???}, end: function(d) { ???}, next: function(d, val) {???}, prev: function(d, val) {???} };

bunkat commented 7 years ago

Later wasn't really built for 'every x amount of time' type schedules. It's a very basic constraint solver where you can say 'make sure the hours value is such and such and the minutes value is such and such'. If you just need to execute something every so often, the built in setInterval might be more what you need.