colinsheppard / time

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

Daily and monthly tasks #34

Closed dk-forestry closed 9 years ago

dk-forestry commented 9 years ago

Hi Colin,

I asked this question at Stackoverflow (http://stackoverflow.com/questions/25082203/discrete-event-scheduling-in-netlogo-daily-and-monthly-tasks) and it was suggested to report the issue here. Here's the content of the question:

Using the NetLogo time extension on NetLogo 5.1.0 and Windows 8.1, I would like my simulation to

According to the time documentation, this should be possible: "So if you use the time:plus primitive to add 1 month to the date "2012-02-02", you will get "2012- 03-02"; and if you add another month you get "2012-04-02" even though February and March have different numbers of days."

However, in my minimal working example below, the output of the print command in the console is 2011 January 2, 2011 February 2, 2011 March 5 and 2011 April 5.

So, how can I schedule a task on the some day each month? Bonus question: How can I schedule the task in the first of each month (instead of the second)?

Here's the working example:

extensions [time]

globals[ start-time current-time ]

to setup clear-all reset-ticks

set start-time time:create "2011-01-01" set current-time time:anchor-to-ticks start-time 1.0 "days" time:anchor-schedule start-time 1.0 "days"

;time:schedule-repeating-event-with-period "observer" task do-daily 1 1.0 "days" time:schedule-repeating-event-with-period "observer" task do-monthly 1 1 "months" go-until end

to do-daily ; here are the daily tasks end

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

to go-until time:go-until 100 end

colinsheppard commented 9 years ago

Thanks for opening this issue sonjnow. The problem stemmed from the fact that the calculation of the number of ticks into the future for rescheduling was being based upon the original LogoTime used to anchor the schedule. Since 1 month from Jan 1 is always 31 days, it was using 31 every time.

I fixed the issue so now if your repeat interval is MONTHS or YEARS, it will use the current time to figure out how far ahead to reschedule the event. I will publish an update to the extension shortly that should work for you.