I am in a bit of dilemma here handling the tcl clock function
Here is my code:
set old_date 0
if{ "[clock format [clock scan $old_date] -format {%d %b}] != "[clock format [clock scan $event_date] -format {%d %b}]}
{
if{$old_date !=0}
{
set myTest($value) $old_date;
#some other stuff
}
}
set old_date $event_date
It works(should) in most cases.
But my problem is
[clock format [clock scan $old_date] -format {%d %b}] returns today’s date if $old_date=0.
I know it’s probably returning the right value but I do not want it return today’s date if the value is zero. It kind of messes my comparison logic. I can probably check for an if condition but
Is there something i can do with the clock function?
The problem is that you’re doing (in effect)
[clock scan 0]. Theclock scancommand will, if all else fails, fall back to trying to parse whatever you throw into it. With a0, it ends up as deciding it refers to00:00:00on the current date. I don’t know if this is a correct parse of that string, but it’s arguably not wrong: it’s a truly horribly denormalized time.What would make sense is keeping a timestamp in
old_date; that’s the kind of value thatclock scanreturns. Since you’re looking for a date-level granularity, let’s pick a standard time of the day to represent that day (midday, GMT). Now, we can use the-baseand-gmtoptions to make everything work in our conversion code (put into a little procedure for convenience):Given that, we can now rewrite the rest of your code: