Last active
December 25, 2015 22:18
-
-
Save kode54/7048222 to your computer and use it in GitHub Desktop.
This is a wrapper around clock scan for Tcl older than 8.6, which lacks the -format argument to manually specify a timestamp format. This will remove any timezone offset, which clock scan will choke on, and turns it into a relative time offset to apply to the remaining timestamp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc urllog:clock_scan {datestring} { | |
set regpat {([-+]{1}[0-9]{1,4})} | |
set offset_string "0 seconds" | |
if {[regexp $regpat $datestring -> offset]} { | |
regsub $regpat $datestring {} datestring | |
set offset_hours 0 | |
set offset_minutes 0 | |
set offset_length [string length $offset] | |
scan $offset %d offset | |
set offset_sign [expr { ($offset > 0) ? "ago" : "" }] | |
if {$offset < 0} { set offset [expr 0 - $offset] } | |
if {$offset_length == 5} { | |
set offset_hours [expr $offset / 100] | |
set offset_minutes [expr $offset % 100] | |
} else { | |
set offset_hours $offset | |
} | |
set offset_string "$offset_hours hours $offset_minutes minutes $offset_sign" | |
} | |
return [clock scan $offset_string -base [clock scan $datestring]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment