|Welcome to the Monastery|
Check current time between range of dates and timesby AcidHawk (Vicar)
|on May 13, 2009 at 13:43 UTC||Need Help??|
AcidHawk has asked for the
wisdom of the Perl Monks concerning the following question:
When I see a certain condition (I.e. a file is written in a directory) I need to perform an action. I am wanting to check that the current time (I.e. now) is between certain dates and times and if so I will NOT perform this action. So this is a simple exclusion\blackout list and I identify which config element to use based on criteria in the file that I have read from the dir. The configuration is in xml and looks as follows
What I do is convert the start time to epoch and then the end time to epoch and check if the current epoch is between these two times. I have a method that looks as follows:
Obviously, if there is no end time, or no start and no end time, I handle that accordingly (see the config xml comments). You will also see in the toEpoch function if the word "every" is received as the first element in the configured date that is passed from the configuration I check only the times i.e. start time and end time for each and every day.
So far this rudimentary way of handling the checking if the current time falls between two configurable exclusion\blackout times has worked well. However, some-one has now asked that we exclude/blackout processing the actions every Monday. I now have to come up with a way of identifying if it is Monday between the times in the config and if say it is Tuesday perform the action. however if it is any Monday between the defined times do not perform the action. I would like the configuration to look as follows;
This I can get (I think) by getting (localtime) and checking
The problem I am trying to rack my head around is, if I want to configure a blackout period of say between "Mon 11:00" and "Wed 11:30" how would I identify the epoch time and how would I check between say "Fri 16:00" and "Mon 8:00" (I.e. nothing over the weekend).
I hope this explanation has not proved to be too tiresome. Regards AcidHawk
Of all the things I've lost in my life, its my mind I miss the most.