| View previous topic :: View next topic |
| Author |
Message |
Slightz Voice
Joined: 16 May 2006 Posts: 3
|
Posted: Tue May 23, 2006 8:32 pm Post subject: duraiton help [SOLVED] |
|
|
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
i wan't somethign like this
| Code: | | 2 weeks 1 day 3 hours 4 mins 30 secs 05/23 |
something liek this i been looking at this pice of the code but cant get it
| Code: | proc check:stamp { timestamp } {
regsub -- {[nN][oO][wW]} $timestamp "" timestamp
if { $timestamp == "" || $timestamp == "\-" } { return [unixtime] } else { return $timestamp}
}
proc unx2nps { timestamp } {
if {[regexp "\[^\\d\]" $timestamp]} { error "unx2nps: parameter is not a valid unix timestamp" }
if {$timestamp > "2000000000"} { error "unx2nps: parameter is too large" }
return [clock format $timestamp -format "%m/%d/%Y %l:%M:%p"]
} |
i was tryign to set something like
set blah [duration $unx2nps]
but then the script does nto output the info
any help would be thanksfull
Thank You
Last edited by Slightz on Mon May 29, 2006 4:38 am; edited 1 time in total |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Tue May 23, 2006 10:07 pm Post subject: |
|
|
From tcl-commands.doc:
| Quote: | 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. |
You may also find the clock manual page of use. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
Slightz Voice
Joined: 16 May 2006 Posts: 3
|
Posted: Tue May 23, 2006 11:53 pm Post subject: |
|
|
i haved... read and just got to change the format from 24 horus to PM AM but i dont get it how can i tweak that pice of code or how can i do it
can you help me out |
|
| Back to top |
|
 |
noname Voice
Joined: 27 May 2006 Posts: 5
|
Posted: Sat May 27, 2006 4:48 pm Post subject: |
|
|
| Code: | 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...
| Code: | ### dupecheck
[...]
set nothetime [unixtime]
set tim_ago [no:dupe:ago $nothetime $tim]; #e.g. 20d 7h 13m 16s
set tim_day [no:dupe:day $tim]; # e.g. 05/07
[...]
### dupe tim ago
proc no:dupe:ago { unixtime prestamp } {
if {[regexp "\[^\\d\]" $unixtime] != "1" && [regexp "\[^\\d\]" $prestamp] != "1" && $unixtime < "2000000000" && $prestamp < "2000000000" && $unixtime != "0" && $prestamp != "0"} {
set timdiff [expr $unixtime - $prestamp]
set d [expr {$timdiff/86400}]
set h [expr {($timdiff%86400)/3600}]
set m [expr {(($timdiff%86400)%3600)/60}]
set s [expr {(($timdiff%86400)%3600)%60}]
append ds $d "d"
append hs $h "h"
append ms $m "m"
append ss $s "s"
if { $d > 0 } {
append dupeago $ds " " $hs " " $ms " " $ss
} elseif { $h > 0 } {
append dupeago $hs " " $ms " " $ss
} elseif { $m > 0 } {
append dupeago $ms " " $ss
} else {
append dupeago $ss
}
return $dupeago
}
}
### dupe day ago
proc no:dupe:day { prestamp } {
if {[regexp "\[^\\d\]" $prestamp] != "1" && $prestamp < "2000000000" && $prestamp != "0" && $prestamp != "0"} {
return [clock format $prestamp -format "%m/%d"]
}
} |
btw: a new version will b published in a few days -.^ |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun May 28, 2006 6:54 am Post subject: |
|
|
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
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
noname Voice
Joined: 27 May 2006 Posts: 5
|
Posted: Sun May 28, 2006 10:30 am Post subject: |
|
|
| 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 -.^ |
|
| Back to top |
|
 |
Ofloo Owner
Joined: 13 May 2003 Posts: 953 Location: Belguim
|
Posted: Sun May 28, 2006 12:04 pm Post subject: |
|
|
try clock scan _________________ XplaiN but think of me as stupid |
|
| Back to top |
|
 |
noname Voice
Joined: 27 May 2006 Posts: 5
|
Posted: Sun May 28, 2006 3:49 pm Post subject: |
|
|
| Ofloo wrote: | | try clock scan |
try sentence |
|
| Back to top |
|
 |
Slightz Voice
Joined: 16 May 2006 Posts: 3
|
Posted: Mon May 29, 2006 4:37 am Post subject: |
|
|
| thanks noname that works perfectly does that i needed |
|
| Back to top |
|
 |
|