ParseUTCOffsetLocation converts a numeric UTC offset to a fixed time.Location.
(raw string)
| 44 | |
| 45 | // ParseUTCOffsetLocation converts a numeric UTC offset to a fixed time.Location. |
| 46 | func ParseUTCOffsetLocation(raw string) (*time.Location, error) { |
| 47 | normalized, err := NormalizeUTCOffset(raw) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | hours, err := strconv.Atoi(normalized[1:3]) |
| 53 | if err != nil { |
| 54 | return nil, fmt.Errorf("invalid UTC offset format: %w", err) |
| 55 | } |
| 56 | minutes, err := strconv.Atoi(normalized[4:6]) |
| 57 | if err != nil { |
| 58 | return nil, fmt.Errorf("invalid UTC offset format: %w", err) |
| 59 | } |
| 60 | offsetSeconds := hours*60*60 + minutes*60 |
| 61 | if normalized[0] == '-' { |
| 62 | offsetSeconds = -offsetSeconds |
| 63 | } |
| 64 | |
| 65 | return time.FixedZone("UTC"+normalized, offsetSeconds), nil |
| 66 | } |
no test coverage detected