MCPcopy Create free account
hub / github.com/github/gh-aw / NormalizeUTCOffset

Function NormalizeUTCOffset

pkg/workflow/utc_offset.go:19–43  ·  view source on GitHub ↗

NormalizeUTCOffset validates and normalizes a numeric UTC offset.

(raw string)

Source from the content-addressed store, hash-verified

17
18// NormalizeUTCOffset validates and normalizes a numeric UTC offset.
19func NormalizeUTCOffset(raw string) (string, error) {
20 trimmed := strings.TrimSpace(raw)
21 matches := utcOffsetPattern.FindStringSubmatch(trimmed)
22 if matches == nil {
23 utcOffsetLog.Printf("UTC offset %q does not match expected +HH:MM/-HH:MM format", trimmed)
24 return "", errors.New("must be a numeric UTC offset like +00:00 or -08:00")
25 }
26
27 hours, err := strconv.Atoi(matches[2])
28 if err != nil {
29 return "", errors.New("must be a numeric UTC offset like +00:00 or -08:00")
30 }
31 minutes, err := strconv.Atoi(matches[3])
32 if err != nil {
33 return "", errors.New("must be a numeric UTC offset like +00:00 or -08:00")
34 }
35 if hours > 14 || minutes > 59 || (hours == 14 && minutes != 0) {
36 utcOffsetLog.Printf("UTC offset %q out of range (hours=%d, minutes=%d)", trimmed, hours, minutes)
37 return "", errors.New("must be a numeric UTC offset like +00:00 or -08:00")
38 }
39
40 normalized := fmt.Sprintf("%s%02d:%02d", matches[1], hours, minutes)
41 utcOffsetLog.Printf("Normalized UTC offset %q to %q", trimmed, normalized)
42 return normalized, nil
43}
44
45// ParseUTCOffsetLocation converts a numeric UTC offset to a fixed time.Location.
46func ParseUTCOffsetLocation(raw string) (*time.Location, error) {

Callers 3

defaultsValidateFileFunction · 0.92
validateRepoConfigValuesFunction · 0.85
ParseUTCOffsetLocationFunction · 0.85

Calls 1

PrintfMethod · 0.45

Tested by

no test coverage detected