package calendar import ( "fmt" "strings" "time" ) // ReminderUIDPrefix namespaces every event maven publishes. Two reasons it is a // fixed prefix and not a random UUID: the render is idempotent (the same // reminder always lands on the same UID, so re-rendering overwrites instead of // duplicating), and everything maven owns in the target collection is // identifiable at a glance — she never touches a file she did not create. const ReminderUIDPrefix = "maven-reminder-" // DefaultReminderDuration — how long a rendered reminder occupies. A reminder // is an instant, a calendar entry is a span, so one has to be invented; 30 // minutes reads as a block in a calendar app without swallowing the afternoon. const DefaultReminderDuration = 30 * time.Minute // ReminderEvent maps a reminder to the event that represents it. id and fire // come from the store; payload is the RU text as the owner said it, rendered // verbatim as the summary — the calendar is a view of sqlite, not a place to // rephrase. func ReminderEvent(id int64, fire time.Time, payload string, dur time.Duration) Event { if dur <= 0 { dur = DefaultReminderDuration } summary := strings.TrimSpace(payload) if summary == "" { summary = "напоминание" } return Event{ UID: fmt.Sprintf("%s%d", ReminderUIDPrefix, id), Summary: summary, Start: fire, End: fire.Add(dur), } } // ReminderPath is the collection-relative filename for a rendered reminder. // One event per resource, per the CalDAV convention. func ReminderPath(id int64) string { return fmt.Sprintf("%s%d.ics", ReminderUIDPrefix, id) }