colinsheppard / time

A NetLogo extension that brings date/time utilities and discrete event scheduling to NetLogo
12 stars 13 forks source link

Schedule monthly repeating events with ticks anchored to any value other than 1 minute/day/week #62

Open ckarren opened 1 year ago

ckarren commented 1 year ago

Similar to https://github.com/colinsheppard/time/issues/34: when ticks and schedule are anchored to 1 "days", "hours" or "minutes" there is no issue. But when ticks and schedule are anchored to other integers, such as 15 "minutes" and repeating events are scheduled with a period of 1 "months", the intervals seem to occur every 31 days, instead of on the same day of each month. MWE: extensions [time]

globals[ start-time current-time ]

to setup clear-all reset-ticks

set start-time time:create "2011-01-01 00:00" set current-time time:anchor-to-ticks start-time 15 "minutes" time:anchor-schedule start-time 15 "minutes"

time:schedule-repeating-event-with-period "observer" [-> do-monthly] 0 1 "months" go-until end

to do-monthly ; here are the monthly tasks print time:show current-time "yyyy MMMM dd HH:mm" end

to go-until time:go-until 30000 end

Expected output: 2011 January 01 00:00 2011 February 01 00:00 2011 March 01 00:00 2011 April 01 00:00 2011 May 01 00:00 2011 June 01 00:00 2011 July 01 00:00 2011 August 01 00:00 2011 September 01 00:00 2011 October 01 00:00 2011 November 01 00:00 . . .

Actual output: 2011 January 01 00:00 2011 February 01 00:00 2011 March 04 00:00 2011 April 04 00:00 2011 May 05 00:00 2011 June 05 00:00 2011 July 06 00:00 2011 August 06 00:00 2011 September 06 00:00 2011 October 07 00:00 2011 November 07 00:00 . . .

My ticks and schedule are anchored to 15 "minutes" and I would like to schedule events to repeat weekly (which works fine), monthly and bimonthly. The month and bimonthly scheduled events currently occur every 31 and 62 days, respectively instead of on the same day every month and every other month, respectively.