Hello, yes i know this has been asked and i searched for "duration" but can't fiure out im a newbie to TCL and is a hard language i did not code tthsi script is just part of it but what im tryign to do is instead of showing
duration <seconds>
Returns: the number of seconds converted into years, weeks, days, hours,
minutes, and seconds. 804600 seconds is turned into 1 week 2 days
7 hours 30 minutes.
set prestamp_ago [duration [expr [unixtime] - $prestamp]]; # e.g. 4 years 37 weeks 2 days 18 hours 48 minutes 58 seconds
set prestamp_day [clock format $prestamp -format "%m/%d"]; # e.g. 05/27
but duration isnt the best method imho... noone wants to calc 1y 33weeks too days... so i here is my code, which i'm usin...
If you dont want duration to show more than 2 units, you could cut off the rest by using:
lrange [duration $d] 0 3
this should cut '1 week 2 days 7 hours 30 minutes' to '1 week 2 days'. No need to write an own proc about it .
PS: why use a regexp "\[^\\d\]" if you can use a non regexp expression like (though this matchs rather {^\s*\d+\s*$}):
![string is integer -strict $timestamp]
Differences: your regexp continues if string is zero. 'string is' is valid when the value is trailed or lead by whitespace characters and therefore more accurate for TCL to determine, if a following integer operation will succeed.
De Kus wrote:If you dont want duration to show more than 2 units, you could cut off the rest by using:
lrange [duration $d] 0 3
this should cut '1 week 2 days 7 hours 30 minutes' to '1 week 2 days'. No need to write an own proc about it :D.
i just wanted to have days - no years or weeks
it should cut '1 week 2 days 7 hours 30 minutes' to '9 days 7 hours 30 minutes' ;)
De Kus wrote:
PS: why use a regexp "\[^\\d\]" if you can use a non regexp expression like (though this matchs rather {^\s*\d+\s*$}):
![string is integer -strict $timestamp]
Differences: your regexp continues if string is zero. 'string is' is valid when the value is trailed or lead by whitespace characters and therefore more accurate for TCL to determine, if a following integer operation will succeed.
tnx a lot - mayb 'string is' was a bit to easy -.^