Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
A daily reminder at nine stays at nine when the clocks change
Yashwanth Kamireddi2c47c70b5743
diff --git a/crates/quince-core/src/reminders.rs b/crates/quince-core/src/reminders.rsindex 6e74ffd..3e3677e 100644--- a/crates/quince-core/src/reminders.rs+++ b/crates/quince-core/src/reminders.rs@@ -56,6 +56,10 @@ pub struct Reminder {/// reminder by its guid and the record is read back from the library on this side.#[serde(default, skip_serializing)]pub raw: Option<String>,+ /// The named zone Apple keeps beside the due date. Nine in the morning is nine in the+ /// morning wherever the person is, and that is not something a timestamp can say.+ #[serde(default)]+ pub timezone: Option<String>,}/// What every entry in the sidebar is holding.@@ -127,9 +131,16 @@ impl Reminder {3 => jiff::Span::new().years(interval),_ => return None,};- let mut zoned = jiff::Timestamp::from_second(due)- .ok()?- .to_zoned(jiff::tz::TimeZone::UTC);+ // Stepped in the reminder's own zone, not in UTC. A day in UTC is always exactly+ // twenty-four hours, so on the two days a year a clock moves, stepping there carried a+ // nine o'clock reminder to ten and six months later back to nine. In a real zone a day+ // is whatever that day is, and the hour holds.+ let zone = self+ .timezone+ .as_deref()+ .and_then(|name| jiff::tz::TimeZone::get(name).ok())+ .unwrap_or_else(jiff::tz::TimeZone::system);+ let mut zoned = jiff::Timestamp::from_second(due).ok()?.to_zoned(zone);// The cap stops a daily reminder abandoned a decade ago from spinning; eleven// years of daily steps is far past any real backlog.@@ -232,7 +243,7 @@ impl Library {let mut stmt = self.conn.prepare("SELECT r.guid, r.list_guid, r.title, r.notes, r.due_at, r.completed_at,r.priority, r.flagged, r.parent_guid, r.recur_frequency, r.recur_interval,- r.etag+ r.etag, r.timezoneFROM reminders rJOIN reminder_lists l ON l.guid = r.list_guidWHERE l.enabled = 1 AND r.due_at IS NOT NULL@@ -255,6 +266,7 @@ impl Library {recur_interval: row.get(10)?,etag: row.get(11)?,raw: None,+ timezone: row.get(12)?,})})?;Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?)@@ -330,7 +342,7 @@ impl Library {let sql = format!("SELECT r.guid, r.list_guid, r.title, r.notes, r.due_at, r.completed_at,r.priority, r.flagged, r.parent_guid, r.recur_frequency, r.recur_interval,- r.etag+ r.etag, r.timezoneFROM reminders rJOIN reminder_lists l ON l.guid = r.list_guidWHERE l.enabled = 1 AND {clause}@@ -353,6 +365,7 @@ impl Library {recur_interval: row.get(10)?,etag: row.get(11)?,raw: None,+ timezone: row.get(12)?,})})?;Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?)@@ -449,8 +462,8 @@ impl Library {let mut stmt = tx.prepare("INSERT INTO reminders (guid, list_guid, title, notes, due_at, completed_at,priority, flagged, parent_guid, recur_frequency,- recur_interval, etag, raw, updated_at)- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14)+ recur_interval, etag, raw, timezone, updated_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15)ON CONFLICT(guid) DO UPDATE SETlist_guid = excluded.list_guid, title = excluded.title,notes = excluded.notes, due_at = excluded.due_at,@@ -459,6 +472,7 @@ impl Library {recur_frequency = excluded.recur_frequency,recur_interval = excluded.recur_interval,etag = excluded.etag, raw = excluded.raw,+ timezone = excluded.timezone,updated_at = excluded.updated_at",)?;let stamp = now();@@ -477,6 +491,7 @@ impl Library {r.recur_interval,r.etag,r.raw,+ r.timezone,stamp])?;}@@ -510,7 +525,7 @@ impl Library {pub fn reminders_in(&self, list_guid: &str, include_done: bool) -> Result<Vec<Reminder>> {let mut stmt = self.conn.prepare("SELECT guid, list_guid, title, notes, due_at, completed_at, priority, flagged,- parent_guid, recur_frequency, recur_interval, etag+ parent_guid, recur_frequency, recur_interval, etag, timezoneFROM remindersWHERE list_guid = ?1 AND (?2 = 1 OR completed_at IS NULL)ORDER BY completed_at IS NOT NULL,@@ -536,6 +551,7 @@ impl Library {recur_interval: row.get(10)?,etag: row.get(11)?,raw: None,+ timezone: row.get(12)?,})},)?;@@ -573,6 +589,7 @@ mod tests {recur_interval: None,etag: None,raw: None,+ timezone: None,}}@@ -760,6 +777,7 @@ mod smart_tests {recur_interval: None,etag: None,raw: None,+ timezone: None,}}@@ -899,6 +917,7 @@ mod count_tests {recur_interval: None,etag: None,raw: None,+ timezone: None,}}@@ -995,6 +1014,7 @@ mod payload_tests {recur_interval: None,etag: Some("e1".into()),raw: Some(apples_record),+ timezone: None,};let sent = serde_json::to_string(&reminder).unwrap();@@ -1029,6 +1049,7 @@ mod payload_tests {recur_interval: None,etag: Some(format!("e{i}")),raw: Some("y".repeat(5_000)),+ timezone: None,}).collect();let bytes = serde_json::to_vec(&many).unwrap().len();@@ -1058,6 +1079,7 @@ mod raw_column_tests {recur_interval: None,etag: Some("e1".into()),raw: Some("z".repeat(5_000)),+ timezone: None,}}@@ -1137,6 +1159,7 @@ mod bound_tests {recur_interval: None,etag: None,raw: None,+ timezone: None,}).collect();lib.put_reminders(&rows).unwrap();@@ -1186,3 +1209,100 @@ mod bound_tests {assert_eq!(lib.reminders_due_between(0, i64::MAX).unwrap().len(), 40);}}++/// Repeating reminders where the clock moves.+#[cfg(test)]+mod recurrence_daylight_tests {+ use super::*;++ fn at(zone: &str, y: i16, m: i8, d: i8, h: i8, min: i8) -> i64 {+ jiff::civil::DateTime::new(y, m, d, h, min, 0, 0)+ .unwrap()+ .to_zoned(jiff::tz::TimeZone::get(zone).unwrap())+ .unwrap()+ .timestamp()+ .as_second()+ }++ fn wall(zone: &str, seconds: i64) -> String {+ jiff::Timestamp::from_second(seconds)+ .unwrap()+ .to_zoned(jiff::tz::TimeZone::get(zone).unwrap())+ .strftime("%Y-%m-%d %H:%M")+ .to_string()+ }++ fn daily(zone: &str, due: i64) -> Reminder {+ Reminder {+ guid: "Reminder/1".into(),+ list_guid: "List/1".into(),+ title: "Take the tablets".into(),+ notes: None,+ due_at: Some(due),+ completed_at: None,+ priority: 0,+ flagged: false,+ parent_guid: None,+ recur_frequency: Some(0),+ recur_interval: Some(1),+ etag: None,+ raw: None,+ timezone: Some(zone.into()),+ }+ }++ /// Nine in the morning every day means nine in the morning on the day the clocks go+ /// forward too. Stepping a whole number of hours instead of a day moves it to ten, and+ /// back to nine six months later — twice a year, for everyone who does not live somewhere+ /// that keeps one offset all year. This account's zone is one of the few that does, which+ /// is why it was never seen.+ #[test]+ fn a_daily_reminder_keeps_its_hour_across_a_spring_forward() {+ let zone = "America/New_York";+ let before = at(zone, 2026, 3, 7, 9, 0);+ let next = daily(zone, before)+ .next_occurrence_after(before)+ .expect("a daily reminder has a next occurrence");+ assert_eq!(wall(zone, next), "2026-03-08 09:00");+ }++ /// And on the day they go back.+ #[test]+ fn a_daily_reminder_keeps_its_hour_across_a_fall_back() {+ let zone = "America/New_York";+ let before = at(zone, 2026, 10, 31, 9, 0);+ let next = daily(zone, before).next_occurrence_after(before).unwrap();+ assert_eq!(wall(zone, next), "2026-11-01 09:00");+ }++ /// Southern hemisphere, and a zone whose clock moves by half an hour rather than a whole+ /// one — the case that catches anything reasoning in whole hours.+ #[test]+ fn the_hour_holds_in_the_awkward_zones_too() {+ for (zone, y, m, d) in [+ ("Australia/Sydney", 2026, 10, 3),+ ("Australia/Lord_Howe", 2026, 10, 3),+ ("Europe/London", 2026, 3, 28),+ ("Pacific/Chatham", 2026, 9, 26),+ ] {+ let before = at(zone, y, m, d, 9, 0);+ let next = daily(zone, before).next_occurrence_after(before).unwrap();+ assert!(+ wall(zone, next).ends_with("09:00"),+ "{zone}: {} became {}",+ wall(zone, before),+ wall(zone, next)+ );+ }+ }++ /// A reminder that never said where it was must still advance, in this machine's own zone.+ #[test]+ fn a_reminder_with_no_zone_still_advances_a_whole_day() {+ let mut r = daily("UTC", 1_789_000_000);+ r.timezone = None;+ let next = r.next_occurrence_after(1_789_000_000).unwrap();+ assert!(next > 1_789_000_000);+ assert!((next - 1_789_000_000 - 86_400).abs() <= 3_600);+ }+}diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rsindex 238e152..c919f7c 100644--- a/crates/quince-core/src/schema.rs+++ b/crates/quince-core/src/schema.rs@@ -254,4 +254,15 @@ pub const MIGRATIONS: &[&str] = &[r#"ALTER TABLE note_folders ADD COLUMN parent_guid TEXT;"#,+ // 17 — where a reminder's time is kept.+ //+ // Apple records a named zone beside the due date, because nine in the morning means nine+ // in the morning wherever the person is rather than a fixed instant. Without it a+ // repeating reminder was stepped in UTC, where a day is always exactly twenty-four hours —+ // so on the two days a year a clock moves, a daily reminder at nine moved to ten and six+ // months later back again. This account is in one of the few zones that keeps a single+ // offset all year, which is why it was never visible here.+ r#"+ ALTER TABLE reminders ADD COLUMN timezone TEXT;+ "#,];diff --git a/crates/quince-icloud/src/calendar.rs b/crates/quince-icloud/src/calendar.rsindex 24e4a03..f684804 100644--- a/crates/quince-icloud/src/calendar.rs+++ b/crates/quince-icloud/src/calendar.rs@@ -1006,3 +1006,98 @@ mod other_calendars_tests {assert!(parsed.iter().all(|c| !c.writable));}}++/// Clocks that move, which this account's never does.+///+/// Asia/Kolkata has no daylight saving and never has, so every path through these conversions+/// had only ever been exercised on a zone with one fixed offset. Most of the world is not like+/// that, and the two hours a year when a clock jumps are exactly where date code fails: one+/// local time never happens, and another happens twice.+#[cfg(test)]+mod daylight_tests {+ use super::*;+ use serde_json::json;++ fn apple(y: i64, m: i64, d: i64, h: i64, min: i64) -> Value {+ json!([y * 10_000 + m * 100 + d, y, m, d, h, min, h * 60 + min])+ }++ fn read(raw: &Value, zone: &str) -> i64 {+ parse_apple_date(raw, Some(zone)).unwrap_or_else(|e| panic!("{zone}: {e}"))+ }++ /// In New York on 8 March 2026 the clock goes straight from 01:59 to 03:00, so 02:30 is a+ /// local time that never happens. Apple can still send it — a repeating event lands there,+ /// or another device wrote it. It has to become some real instant rather than fail a sync.+ #[test]+ fn a_local_time_that_never_happens_still_becomes_an_instant() {+ let at = read(&apple(2026, 3, 8, 2, 30), "America/New_York");+ let back = jiff::Timestamp::from_second(at)+ .unwrap()+ .to_zoned(TimeZone::get("America/New_York").unwrap());+ assert_eq!(back.date().to_string(), "2026-03-08");+ assert!(+ back.hour() == 3 || back.hour() == 1,+ "it has to land either side of the gap, not inside it: {back}"+ );+ }++ /// And on 1 November the clock goes from 01:59 back to 01:00, so 01:30 happens twice.+ /// Either instant is defensible; silently producing something on another day is not.+ #[test]+ fn a_local_time_that_happens_twice_picks_one_and_stays_on_the_day() {+ let at = read(&apple(2026, 11, 1, 1, 30), "America/New_York");+ let back = jiff::Timestamp::from_second(at)+ .unwrap()+ .to_zoned(TimeZone::get("America/New_York").unwrap());+ assert_eq!(back.date().to_string(), "2026-11-01");+ assert_eq!((back.hour(), back.minute()), (1, 30));+ }++ /// Nine in the morning is nine in the morning on both sides of a clock change. An event+ /// written on one side and read on the other must not drift an hour.+ #[test]+ fn an_ordinary_morning_survives_the_round_trip_on_both_sides_of_a_change() {+ for zone in [+ "America/New_York",+ "Europe/London",+ "Australia/Sydney",+ "Australia/Lord_Howe",+ "Asia/Kolkata",+ "Pacific/Chatham",+ ] {+ for (m, d) in [(1, 15), (3, 20), (7, 4), (11, 15)] {+ let sent = apple(2026, m, d, 9, 0);+ let at = read(&sent, zone);+ let written = format_apple_date(at, Some(zone));+ assert_eq!(+ written, sent,+ "{zone} on {m}/{d}: what was read did not come back the same"+ );+ }+ }+ }++ /// Half-hour and three-quarter-hour offsets are real places, and Lord Howe's clock moves+ /// by thirty minutes rather than an hour.+ #[test]+ fn zones_that_are_not_whole_hours_round_trip_too() {+ for zone in ["Asia/Kathmandu", "Australia/Eucla", "Australia/Lord_Howe"] {+ let sent = apple(2026, 6, 10, 14, 45);+ assert_eq!(+ format_apple_date(read(&sent, zone), Some(zone)),+ sent,+ "{zone}"+ );+ }+ }++ /// A zone this machine has never heard of must keep the event visible rather than fail the+ /// whole sync — someone's calendar carrying one bad zone is not a reason to show them+ /// nothing.+ #[test]+ fn an_unknown_zone_falls_back_instead_of_failing_the_sync() {+ assert!(parse_apple_date(&apple(2026, 6, 10, 9, 0), Some("Mars/Olympus_Mons")).is_ok());+ assert!(parse_apple_date(&apple(2026, 6, 10, 9, 0), None).is_ok());+ }+}diff --git a/crates/quince-icloud/src/reminders.rs b/crates/quince-icloud/src/reminders.rsindex a2daf20..63d5213 100644--- a/crates/quince-icloud/src/reminders.rs+++ b/crates/quince-icloud/src/reminders.rs@@ -57,6 +57,7 @@ fn reminder_from(v: &Value) -> Option<Reminder> {// Keep Apple's payload verbatim: a write echoes the whole task back, and// reconstructing one from parsed columns would drop fields we do not model.raw: serde_json::to_string(v).ok(),+ timezone: None,})}@@ -445,6 +446,10 @@ fn reminder_from_record(record: &Value) -> Option<Reminder> {.and_then(Value::as_str).map(ToString::to_string),raw: serde_json::to_string(record).ok(),+ // Apple keeps a named zone beside the due date, because nine in the morning means+ // nine in the morning wherever the person is. A repeating reminder stepped without it+ // moves an hour on each of the two days a year a clock changes.+ timezone: field::string(record, "TimeZone"),})}@@ -1702,6 +1707,7 @@ mod write_tests {recur_interval: None,etag: Some("tag-3".into()),raw: None,+ timezone: None,};delete_cloudkit(&reqwest::Client::new(), &server.uri(), vec![], &reminder).await@@ -1780,6 +1786,7 @@ mod edit_tests {recur_interval: None,etag: Some("tag-1".into()),raw: None,+ timezone: None,}}@@ -2262,6 +2269,7 @@ mod recurring_tick_tests {recur_interval: Some(interval),etag: Some("tag".into()),raw: None,+ timezone: None,}}@@ -2459,6 +2467,7 @@ mod priority_and_move_tests {recur_interval: None,etag: Some("tag".into()),raw: None,+ timezone: None,}}@@ -2637,6 +2646,7 @@ mod tombstone_tests {recur_interval: None,etag: None,raw: None,+ timezone: None,}]).unwrap();library@@ -2769,6 +2779,7 @@ mod recurrence_write_tests {recur_interval: None,etag: Some("tag".into()),raw: None,+ timezone: None,}}diff --git a/probe/examples/at_scale.rs b/probe/examples/at_scale.rsindex 41400a4..a6fec97 100644--- a/probe/examples/at_scale.rs+++ b/probe/examples/at_scale.rs@@ -52,6 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {etag: Some(format!("e{i}")),// What Apple actually stores per reminder on a real account: about five KB.raw: Some("z".repeat(5_000)),+ timezone: None,}).collect();let t = Instant::now();diff --git a/probe/src/main.rs b/probe/src/main.rsindex 6134bab..a16fd83 100644--- a/probe/src/main.rs+++ b/probe/src/main.rs@@ -1361,6 +1361,7 @@ async fn main() -> Result<()> {recur_interval: None,etag: None,raw: None,+ timezone: None,};// Subtasks: nest one reminder under another, read it back, free it.