Working with dates and time in Tcl 
Author Message
 Working with dates and time in Tcl

I want to set an expiring cookie that expires 20 minutes from now as
part of a Tcl Script that executes on submission of a password form.

I've gotten code written where I break manipulate individual elements
of the date (using DATE_FORMAT NOW), and I can add values to each
individual element (minutes, hours, etc.)

My problem comes when the minutes are less than 10, like in "11:09".
Tcl sees the minutes as "09" and gives me an error when I try to add 20
to this value.  at 11:10, it will work fine all the way to 12:00, then
at 12:01, I get the error again.  Any ideas?

Is there any way to get Tcl to display the date in milliseconds elapsed
from some reference date, like in JS?  that would be so much easier.  I
would also need something similar to JS's GMT function, to turn the
date back into a cookie-acceptable format.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Fri, 28 Jun 2002 03:00:00 GMT  
 Working with dates and time in Tcl

Quote:
> I want to set an expiring cookie that expires 20 minutes from now as
> part of a Tcl Script that executes on submission of a password form.

> I've gotten code written where I break manipulate individual elements
> of the date (using DATE_FORMAT NOW), and I can add values to each
> individual element (minutes, hours, etc.)

> My problem comes when the minutes are less than 10, like in "11:09".
> Tcl sees the minutes as "09" and gives me an error when I try to add 20
> to this value.  at 11:10, it will work fine all the way to 12:00, then
> at 12:01, I get the error again.  Any ideas?

Yes. 09 and 08 are not octal, that's most likely the error you're running
into. Have you looked at

clock scan

perchance? It should return an integer value for your date. Then you add
1200 seconds to it an there's your 20 minute delta.

L

--
Penguin Power!           Nothing I say reflects the views of my employer


CGI - FWFM Project                                 Phone: (514) 350-3368



Fri, 28 Jun 2002 03:00:00 GMT  
 Working with dates and time in Tcl

Quote:

> My problem comes when the minutes are less than 10, like in "11:09".
> Tcl sees the minutes as "09" and gives me an error when I try to add 20
> to this value.  at 11:10, it will work fine all the way to 12:00, then
> at 12:01, I get the error again.  Any ideas?

"09" ininterpreted as an octal number.  Try doing

regsub {^0} $minutes {} minutes

before doing the arithmetic.  That will strip the leading zero that is causing
the error.

Quote:
> Is there any way to get Tcl to display the date in milliseconds elapsed
> from some reference date, like in JS?

Look at the "clock" man page.

Jeff David



Fri, 28 Jun 2002 03:00:00 GMT  
 Working with dates and time in Tcl

Quote:

> I want to set an expiring cookie that expires 20 minutes from now as
> part of a Tcl Script that executes on submission of a password form.

> I've gotten code written where I break manipulate individual elements
> of the date (using DATE_FORMAT NOW), and I can add values to each
> individual element (minutes, hours, etc.)

Just a thought: I probably would handle *all* date-data internally in
`seconds since epoch' as returned by [clock seconds] or [clock
scan]. Then it should be easy to add a minute (+60) or substract 24
hours (-24*60*60). Only for external representation would I convert to
human readable format.

But be careful: Adding `1 day' is not trivial. If that day covers the
night where daylight saving time (stupid thing) is turned on or off,
`1 day' may have 23 or even 25 hours.

Harald Kirsch

--
P.S.: Never ever mail me copies of your posts.
---------------------+---------------------------------------------




Fri, 28 Jun 2002 03:00:00 GMT  
 Working with dates and time in Tcl

: Just a thought: I probably would handle *all* date-data internally in
: `seconds since epoch' as returned by [clock seconds] or [clock
: scan]. Then it should be easy to add a minute (+60) or substract 24
: hours (-24*60*60). Only for external representation would I convert to
: human readable format.

: But be careful: Adding `1 day' is not trivial. If that day covers the
: night where daylight saving time (stupid thing) is turned on or off,
: `1 day' may have 23 or even 25 hours.

If you need only days (say, you want to print calendar) it can be easily
solved by keeping values of midday rather than midnight. If you start
with today's midday and substract six months you'll get 11:00am June 13.
But you need June 13, and if you don't care about time, it is perfectly
Ok.
: Harald Kirsch

: --
: P.S.: Never ever mail me copies of your posts.
: ---------------------+---------------------------------------------


--
People who are funny and smart and return phone calls get much better
press than people who are just funny and smart.
                -- Howard Simons, "The Washington Post"



Mon, 01 Jul 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Create Time / date or Modified Time / date of a txt file

2. convert labview date/time to excel date/time

3. DOS compressed date/time into real date/time

4. dATE AND TIME PICKER ACTIVEX NOT WORKING

5. Unix system g77 calls DATE and TIME not working for Alpha/Linux

6. How to display time/date in Tcl/TK?

7. Date/Time proc's for TCL

8. date/time within tcl

9. Getting the current date/time in tcl/tk

10. Date&Time in a PC Tcl program

11. time/date extension for Tcl?

12. Tcl extensions supporting date/time operations

 

 
Powered by phpBB® Forum Software