String implements the Stringer interface.
()
| 168 | |
| 169 | // String implements the Stringer interface. |
| 170 | func (t TimeTZ) String() string { |
| 171 | tTime := t.ToTime() |
| 172 | timeComponent := tTime.Format("15:04:05.999999") |
| 173 | // 24:00:00 gets returned as 00:00:00, which is incorrect. |
| 174 | if t.TimeOfDay == timeofday.Time2400 { |
| 175 | timeComponent = "24:00:00" |
| 176 | } |
| 177 | timeZoneComponent := tTime.Format("Z07") |
| 178 | // If it is UTC, .Format converts it to "Z". |
| 179 | // Fully expand this component. |
| 180 | if t.OffsetSecs == 0 { |
| 181 | timeZoneComponent = "+00" |
| 182 | } else if 0 < t.OffsetSecs && t.OffsetSecs < 60 { |
| 183 | // Go's time.Format functionality does not work for offsets which |
| 184 | // in the range -0s < offsetSecs < -60s, e.g. -22s offset prints as 00:00:-22. |
| 185 | // Manually correct for this. |
| 186 | timeZoneComponent = fmt.Sprintf("-00:00:%02d", t.OffsetSecs) |
| 187 | } else if t.OffsetSecs%60 != 0 { |
| 188 | timeZoneComponent = tTime.Format("Z07:00:00") |
| 189 | } else if t.OffsetSecs%3600 != 0 { |
| 190 | timeZoneComponent = tTime.Format("Z07:00") |
| 191 | } |
| 192 | |
| 193 | return timeComponent + timeZoneComponent |
| 194 | } |
| 195 | |
| 196 | // ToTime converts a DTimeTZ to a time.Time, corrected to the given location. |
| 197 | func (t TimeTZ) ToTime() time.Time { |