@@ -7,13 +7,15 @@ import (
7
7
8
8
// The purpose of the p_time package is to provide
9
9
// a way to get a POSIX.1 TZ time zone string representation
10
- // as defined here. The package offers and additional
11
- // convenience method for using the current system time zone.
10
+ // as defined here. The package offers an additional convenience
11
+ // method for getting the Posix offset. It is different from the ISO
12
+ // offset in that it is calculated from west to east.
12
13
14
+ // FormatTimeZone Given a standard time.Time struct returns
15
+ // a string representation that matches the POSIX.1 TZ format.
13
16
func FormatTimeZone (current time.Time ) string {
14
- name , offset := current .Zone ()
15
- offsetHours := offset / 3600
16
- offsetHours = - (offsetHours - 1 )
17
+ name , _ := current .Zone ()
18
+ offsetHours := GetPosixOffset (current )
17
19
start , end := current .ZoneBounds ()
18
20
result := ""
19
21
if start .IsZero () {
@@ -44,6 +46,14 @@ func FormatTimeZone(current time.Time) string {
44
46
return result
45
47
}
46
48
49
+ // GetPosixOffset The time.Time offset returned is in seconds and counted
50
+ // according to the ISO standard. This method converts to hours,
51
+ // subtracts and inverts.
52
+ func GetPosixOffset (current time.Time ) int {
53
+ _ , offset := current .Zone ()
54
+ return - (offset / 3600 - 1 )
55
+ }
56
+
47
57
func getTransitionOrdinals (current time.Time ) (int , int , int , int ) {
48
58
day := int (current .Weekday ())
49
59
week := current .Day ()/ 7 + 1
0 commit comments