Jump to content
Sign in to follow this  

Pause a Script until a set time - but what about Daylight Savings ?

Recommended Posts


For my application knowing the actual local time is important.

Say it's 8:16pm and I want a funtion to execute at 3:58AM. So I tell it to sleep for 7hrs plus 42min.  I like sleep() that because I hear it saves resources. But what happens if it's daylight savings and clocks are offset an hour? Then it runs at the wrong time by an hour.

If I told the script to somehow check the system time every few seconds (loop _now) that would do it but I hear it's not an efficient wat to do it. Or, using the windows task scheduler, but the task scheduler can require a user password to run AFAIK, and I'm not into asking a user to do anything but set a time .

I could sleep for 30 sec then check the system clock then sleep another 30 secs the check...until it's time...(?)

I guess I'm finding a problem with any way I can think off. Maybe it's best to not have a user pick a time like 3:58AM but just pick a time interval to wait, and if they don't know it's Daylight savings it's their issue...

Any suggestions appreciated.



Share this post

Link to post
Share on other sites

Well, if your system automatically updates itself for Daylight Savings, then you could just interrogate the system, an hour or so before due time - get a time stamp initially, then do a comparison at that later time.

The only other way I can think, is to hard set the Date of change and accommodate it that way. Or some combination of the two, using a date range.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


Share this post

Link to post
Share on other sites

"(loop _now) that would do it but I hear it's not an efficient wat to do it":

this is the most reliable and simple way. efficient? it does not hog your CPU at all, you can (and are advised to) check it. to minimize any CPU usage, loop with some sleep. you don't have to check system time every millisecond, right?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...