@@ -7,13 +7,15 @@ import (
77
88// The purpose of the p_time package is to provide
99// 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.
1213
14+ // FormatTimeZone Given a standard time.Time struct returns
15+ // a string representation that matches the POSIX.1 TZ format.
1316func 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 )
1719 start , end := current .ZoneBounds ()
1820 result := ""
1921 if start .IsZero () {
@@ -44,6 +46,14 @@ func FormatTimeZone(current time.Time) string {
4446 return result
4547}
4648
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+
4757func getTransitionOrdinals (current time.Time ) (int , int , int , int ) {
4858 day := int (current .Weekday ())
4959 week := current .Day ()/ 7 + 1
0 commit comments