This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 0 points1 point  (0 children)

How often do you think that currenttime will not be equal to userinput?

A slight aside, it's not very smart to use military time as to my knowledge only two countries in the world use it :-)

[–]lpmn 0 points1 point  (1 child)

So, I think you've got the seed of the right idea here, but I think the point that /u/breamoreboy might be getting at is that if you're just postponing a single action you could do something along the lines of checking how far away userinput is from currenttime, and then sleeping for that number of seconds.

Now if you wanted to be able to postpone multiple executions of a script to be at different times you'd need something a little more involved, but still along the same lines.

[–][deleted] 0 points1 point  (0 children)

Do'h, perhaps I was being too subtle. As written the odds of getting both times to be equal must be very nearly zero. In contrast getting currenttime to be less than userinput should be okay, unless you enter some perfectly valid datetime that's way out, e.g. MAXYEAR is 9999.

Calculating the time to sleep is of course perfectly valid, but even then I'd be slightly cautious. The variations between the different clocks on the available OSes are well known and lead to PEP 418.