Merge branch 'rs/worktree-use-strbuf-absolute-path'
[git.git] / git-gui / lib / date.tcl
blobabe82992b6529cf49983029d85348df5d27ceaf5
1 # git-gui date processing support
2 # Copyright (C) 2007 Shawn Pearce
4 set git_month(Jan) 1
5 set git_month(Feb) 2
6 set git_month(Mar) 3
7 set git_month(Apr) 4
8 set git_month(May) 5
9 set git_month(Jun) 6
10 set git_month(Jul) 7
11 set git_month(Aug) 8
12 set git_month(Sep) 9
13 set git_month(Oct) 10
14 set git_month(Nov) 11
15 set git_month(Dec) 12
17 proc parse_git_date {s} {
18 if {$s eq {}} {
19 return {}
22 if {![regexp \
23 {^... (...) (\d{1,2}) (\d\d):(\d\d):(\d\d) (\d{4}) ([+-]?)(\d\d)(\d\d)$} $s s \
24 month day hr mm ss yr ew tz_h tz_m]} {
25 error [mc "Invalid date from Git: %s" $s]
28 set s [clock scan [format {%4.4i%2.2i%2.2iT%2s%2s%2s} \
29 $yr $::git_month($month) $day \
30 $hr $mm $ss] \
31 -gmt 1]
33 regsub ^0 $tz_h {} tz_h
34 regsub ^0 $tz_m {} tz_m
35 switch -- $ew {
36 - {set ew +}
37 + {set ew -}
38 {} {set ew -}
41 return [expr "$s $ew ($tz_h * 3600 + $tz_m * 60)"]
44 proc format_date {s} {
45 if {$s eq {}} {
46 return {}
48 return [clock format $s -format {%a %b %e %H:%M:%S %Y}]
51 proc reformat_date {s} {
52 return [format_date [parse_git_date $s]]