extractTimeWithWeekdays extracts time specification, handling optional "on weekdays" suffix
(startPos int, hasWeekdaysSuffix bool)
| 577 | |
| 578 | // extractTimeWithWeekdays extracts time specification, handling optional "on weekdays" suffix |
| 579 | func (p *ScheduleParser) extractTimeWithWeekdays(startPos int, hasWeekdaysSuffix bool) (string, error) { |
| 580 | if startPos >= len(p.tokens) { |
| 581 | return "", errors.New("expected time specification") |
| 582 | } |
| 583 | |
| 584 | // Check for "at" keyword |
| 585 | if p.tokens[startPos] == "at" { |
| 586 | startPos++ |
| 587 | if startPos >= len(p.tokens) { |
| 588 | return "", errors.New("expected time after 'at'") |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | endPos := len(p.tokens) |
| 593 | if hasWeekdaysSuffix { |
| 594 | endPos -= 2 |
| 595 | } |
| 596 | |
| 597 | timeTokens := []string{p.tokens[startPos]} |
| 598 | nextIndex := startPos + 1 |
| 599 | if nextIndex < endPos && isAMPMToken(p.tokens[nextIndex]) { |
| 600 | timeTokens = append(timeTokens, p.tokens[nextIndex]) |
| 601 | nextIndex++ |
| 602 | } |
| 603 | if nextIndex < endPos { |
| 604 | timezoneToken := strings.ToLower(p.tokens[nextIndex]) |
| 605 | if strings.HasPrefix(timezoneToken, "utc") { |
| 606 | timeTokens = append(timeTokens, timezoneToken) |
| 607 | } else if normalized, ok := normalizeTimezoneAbbreviation(timezoneToken); ok { |
| 608 | timeTokens = append(timeTokens, normalized) |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | return normalizeTimeTokens(timeTokens), nil |
| 613 | } |
no test coverage detected