Losing track of time

J. Landman Gay jacque at hyperactivesw.com
Mon Aug 11 21:50:01 EDT 2003


On 8/11/03 5:45 PM, Robert Brenstein wrote:

> What this code does (for those less familiar with date/time conversions) 
> is: it first gets the current seconds and converts them to dateitems. 
> Then, it is a matter of increasing hour by 1 and setting minutes and 
> seconds to 0. We have now next full hour, which we convert back to 
> seconds and then ask to 'send' in whatever is the difference between the 
> calculated seconds for next full hour and current seconds.
> 
> The only complication is that one needs to account for midnight (end of 
> the day), end of the month, and end of the year. May be there is a way 
> to avoid this somehow.

Actually, that's the beauty of dateitems -- you don't have to account 
for any of that stuff. When you add a number to any item of the 
dateItems and then convert that string back to any other date/time 
format, the conversion handles all the spanning calculations for you.

For example, starting at 8 PM on January 1:

   get "1/1/03 8:00 PM"
   convert it to dateitems
   add 6 to item 4 of it -- add six hours to the "hours" item
   convert it to long date and time
   put it

In this case, adding 6 hours to the dateItems string causes it to span 
midnight. The second conversion yields:

   Thursday, January 2, 2003 2:00 AM

It is one of the handiest things about the whole date/time "convert" 
process.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list