(recurrenceText: string | undefined)
| 503 | } |
| 504 | |
| 505 | private static parseRecurrence(recurrenceText: string | undefined): RecurrenceParseResult { |
| 506 | const raw = recurrenceText?.trim(); |
| 507 | if (!raw) { |
| 508 | return {}; |
| 509 | } |
| 510 | |
| 511 | const whenDoneMatch = raw.match(/\s+when\s+done$/iu); |
| 512 | const recurrenceAnchor: RecurrenceAnchor | undefined = whenDoneMatch |
| 513 | ? "completion" |
| 514 | : undefined; |
| 515 | const text = raw.replace(/\s+when\s+done$/iu, "").trim(); |
| 516 | const existingRule = this.normalizeExistingRRule(text); |
| 517 | const recurrence = existingRule || this.parseTextToRRule(text) || this.parseSimpleRecurrence(text); |
| 518 | |
| 519 | if (!recurrence) { |
| 520 | return { |
| 521 | recurrenceData: { |
| 522 | frequency: "custom", |
| 523 | raw, |
| 524 | }, |
| 525 | }; |
| 526 | } |
| 527 | |
| 528 | return { |
| 529 | recurrence, |
| 530 | recurrenceAnchor, |
| 531 | recurrenceData: this.buildRecurrenceData(recurrence, raw), |
| 532 | }; |
| 533 | } |
| 534 | |
| 535 | private static normalizeExistingRRule(text: string): string | undefined { |
| 536 | const normalized = text.trim().replace(/^RRULE:/iu, ""); |
no test coverage detected