This question is slightly related to this one.
Using the NetLogo time extension on NetLogo 5.1.0 and Windows 8.1, I would like my simulation to
represent one day as one netlogo tick,
do some daily tasks,
do some monthly task on the first day of each month,
(do some yearly and decadal tasks, but that's not relevant for this question).
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
This was a bug that has now been fixed. See:
https://github.com/colinsheppard/time/issues/34
Related
I would like to use Heroku scheduler to run every OTHER Monday. However, it only runs hourly, daily, every 10 minutes.
I read this...
How can I schedule a 'weekly' job on Heroku?
However, I'm not sure what code can be used. I think I can figure out every Monday, but not every OTHER Monday.
thanks
As you get more complicated, I'd recommend checking out scheduling gems. If you want to stick to vanilla Ruby, look at a combination of monday? and cweek, which tells you the week number in the current year. Run your job on Mondays in even-numbered weeks.
date = Date.today
date.monday? && date.cweek.even?
Note that cweek can return 53, since 365 isn't divisible by 7 and it has to handle that last, partial week. The new year's first week will be 1 (it doesn't count from 0), so you have to either skip a week or do two runs in a row when Monday falls in week 53.
I want to get the current hour of the week in which day starts from Sunday.
Consider current time is
Time.now
=> 2014-10-29 12:09:23PM +0530
The result should be : 84
Explanation:
Sunday - 24 hours
Monday - 24 hours
Tuesday - 24hours
Wednesday - 12 hours
Total: 84
How can get the user hour of the week. Is there any method available in Ruby ? Or how to do it without Ruby method.
You can get the day of the week and hour of the day using Time#wday and Time#hour.
Time.now.wday
#=> 3
Time.now.hour
#=> 14
The rest is basic mathematics.
Even though I upvoted Yu Hao, I must say it's not a good approach if you want to pay attention to the concerns Jon Skeet raised. To that end, here's another approach:
(Time.now - (Date.today - Date.today.wday).to_time) / 3600
Date.today is, well, today. If you subtract the number of days since the week started, you get Sunday. Convert it to Time and it's the midnight when Sunday began. Subtraction gives you number of seconds between then and now. Divide by 3600 (and optionally round) to get number of hours. The DST details should be transparently handled by Time#-.
EDIT: Timezones... Run this before:
ENV['TZ']='EST5EDT'
(be sure to reset it back to what it used to be afterwards, in case anyone else needs to know time and didn't count on you switching timezones.) You can also use "America/New_York" instead. See tz list for details.
I have this recurring job in our Rails service that sends out emails on Friday every two weeks. However, based on our business requirement, the first week of the "every two weeks" schedule should be this week, which means the email should be sent out this Friday, and then 2 weeks after that, and 4 weeks after that, etc.
The schedule shouldn't be broken when the service restarts. For example, after the email is sent out this Friday, if I restart the service on Saturday, it shouldn't schedule the job to Friday next week -- should still be the Friday of the week after next week. In short, the week 0 should be persistent and stick to this week.
Is it doable in ice_cube? Or are there any other better solution? Thank!
Setting "week 0" is built into IceCube. When you create the schedule, specify the start time rather than Time.now.
2.1.4 :012 > s = IceCube::Schedule.new(Time.now.beginning_of_month)
2.1.4 :013 > s.add_recurrence_rule IceCube::Rule.monthly.count(3)
2.1.4 :014 > s.all_occurrences
=> [2014-12-01 00:00:00 -0500, 2015-01-01 00:00:00 -0500, 2015-02-01 00:00:00 -0500]
Here, I told IceCube the schedule starts at the beginning of this month, although I could have used any value. IceCube computes the schedule based on that time, giving me Dec 1, Jan 1, and Feb 1.
Well, i'm beginner in MS Project (specifically in MS Project 2007) and a i got the following problem:
1 - I have all tasks maped in "Grantt Charts".
2 - My workday is 14 hours per week (monday to monday, without holidays).
3 - The work schedule is from 21:00PM to 23:00PM, so calculating this we have:
(2h per day) X (7 days in a week) = 14h per week.
The big problem is: When i put 7 days in column durating (in any task) the work shows 14h (this is correct) but the start date and end date just count 1, my ideia is that for MS PROJECT 1 day have 8h of work (and not 2h as i wanna), so 14h is like 1,75 days, but should be exact 7 days because my project is like that, only 2h per day and not 8h per day as MS PROJECT think.
There is an independant setting in MS-Project that tells the system how many hours you consider there to be in a working day. In your case it should be 2, not the default of 7.
Go to "Change Working Time" on the Tools menu. Click the "Options" button. Change the field entitled "Hours per day" to 2.
I need to schedule a task to run on the last night of each month, on a Windows 2003 Server.
I see that you can schedule it to run on the "first or last Mon-Fri", or even on the nth day of each month - but, not how to get it to run on the last day (regardless of day of the week or number).
Thanks in advance.
Note: I did check "How do you schedule tasks in Windows?", etc...
Looks like you have to set up multiple schedules for your task. One schedule for the months with 31 days, another for those with 30, and one more for February. See this: http://support.microsoft.com/kb/936627
I do it a little differently - I run one task every day but since the task is in vbscript - I do this:
DIM datecur, datefut
datecur = DATEPART("m",NOW())
datefut = DATEPART("m",NOW()+1)
If (datecur <> datefut) then
'insert code you want to run here
end if
Simple and it works - hope this helps someone
As of November 2022, much newer Windows version (2019)
I see this option in Triggers:
WinScheduler Task Triggers
Begin the task: On a schedule
Settings:
Monthly
On: Last > then select All weekdays