Re: A "time"ly problem

From: George Greer (greerga@circlemud.org)
Date: 12/07/01


On Fri, 7 Dec 2001, RK wrote:

>I want to make a procedure (void) that is capable of doing a planned set
>of instructions on the first of the month, every month. Preferably I'd
>*like* for it to run at 00:00:00 server time, but any time is fine. I
>figured I could conver the time to a string and use a compare to "1
>00:00" or "1 00:00:00", but that would require that the check be run
>every second and I don't see much of a reason to spam the CPU with wasted
>cycles for a whole month. I imagine whatever solution is found, it can be
>converted to once a day and once a year and once a week...

CircleMUD already calls gettimeofday() per cycle.  You can use that
information to determine if it's the beginning of the month with
localtime() and the 'tm_mday' field it returns in 'struct tm'.

You probably want to go backwards though.  First figure out what the first
day of the next month is in seconds, then compare that seconds value with
what gettimeofday() returns while you're running.  That way you're not
calling localtime() every cycle.

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/24/03 PDT