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

Function parseTime

pkg/parser/schedule_time_utils.go:86–110  ·  view source on GitHub ↗

parseTime converts a time string to minute and hour, with optional UTC offset Supports formats: HH:MM, midnight, noon, 3pm, 1am, HH:MM utc+N, HH:MM utc+HH:MM, HH:MM utc-N, 3pm utc+9

(timeStr string)

Source from the content-addressed store, hash-verified

84// parseTime converts a time string to minute and hour, with optional UTC offset
85// Supports formats: HH:MM, midnight, noon, 3pm, 1am, HH:MM utc+N, HH:MM utc+HH:MM, HH:MM utc-N, 3pm utc+9
86func parseTime(timeStr string) (minute string, hour string) {
87 scheduleTimeUtilsLog.Printf("Parsing time string: %q", timeStr)
88 baseTime, utcOffset := splitBaseTimeAndUTCOffset(timeStr)
89 baseMinute, baseHour, ok := parseBaseTime(baseTime)
90 if !ok {
91 return "0", "0"
92 }
93
94 // Apply UTC offset (convert from local time to UTC)
95 // If utc+9, we subtract 9 hours to get UTC time
96 totalMinutes := baseHour*60 + baseMinute - utcOffset
97
98 // Handle wrap-around (keep within 0-1439 minutes, which is 0:00-23:59)
99 for totalMinutes < 0 {
100 totalMinutes += 24 * 60
101 }
102 for totalMinutes >= 24*60 {
103 totalMinutes -= 24 * 60
104 }
105
106 finalHour := totalMinutes / 60
107 finalMinute := totalMinutes % 60
108
109 return strconv.Itoa(finalMinute), strconv.Itoa(finalHour)
110}
111
112func splitBaseTimeAndUTCOffset(timeStr string) (string, int) {
113 parts := strings.Split(timeStr, " ")

Callers 5

TestParseTimeFunction · 0.85
parseDailyBetweenMethod · 0.85
parseDailyAroundMethod · 0.85
parseWeeklyBaseMethod · 0.85

Calls 3

parseBaseTimeFunction · 0.85
PrintfMethod · 0.45

Tested by 1

TestParseTimeFunction · 0.68