Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: Adjust Date and Time; the viewer follows its photo when the list moves

Yashwanth Kamireddibad11b41a457
diff --git a/.uiverify/photos-date.mjs b/.uiverify/photos-date.mjs
new file mode 100644
index 0000000..e391fd8
--- /dev/null
+++ b/.uiverify/photos-date.mjs
@@ -0,0 +1,42 @@
+// Adjust Date and Time, as icloud.com's: from Info's Adjust, the photo, the zone the times are
+// in, the original, and the new date to the second; Save only once it differs; the photo moves
+// to its new month at once; Escape closes the sheet and nothing else.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 }, timezoneId: "Asia/Kolkata" });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(400);
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+await page.locator(".px-tile").nth(1).dblclick();
+await page.waitForTimeout(600);
+await page.keyboard.press("i");
+await page.locator(".px-adjust").click();
+const sheet = page.getByRole("dialog", { name: "Adjust Date and Time" });
+ok((await sheet.count()) === 1 && /All times are GMT\+05:30/.test(await sheet.innerText()), "the sheet says what zone the times are in");
+ok(await page.getByRole("button", { name: "Save" }).isDisabled(), "Save waits for a different date");
+await page.getByLabel("Adjusted:").fill("2025-03-14T09:30:15");
+ok((await page.evaluate(() => (window.__flags ?? []).length)) === 0, "typing in it touches nothing else");
+await page.getByRole("button", { name: "Save" }).click();
+await page.waitForTimeout(300);
+const sent = await page.evaluate(() => window.__dates?.at(-1));
+ok(sent?.id === "p2" && sent.takenAt === Date.UTC(2025, 2, 14, 4, 0, 15) / 1000, `Save sends the new moment ${JSON.stringify(sent)}`);
+ok((await sheet.count()) === 0 && (await page.locator(".px-viewer-when strong").innerText()) === "March 14, 2025", "the photo shows its new date at once");
+await page.keyboard.press("Escape");
+await page.waitForTimeout(650);
+ok((await page.locator(".px-month-title").allInnerTexts()).includes("March 2025"), "and stands in its new month");
+await page.locator(".px-tile").nth(0).dblclick();
+await page.waitForTimeout(600);
+await page.keyboard.press("i");
+await page.locator(".px-adjust").click();
+await page.keyboard.press("Escape");
+await page.waitForTimeout(150);
+ok((await sheet.count()) === 0 && (await page.locator(".px-viewer").count()) === 1, "Escape closes the sheet, the photo stays open");
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 75e5ded..230a4fc 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -372,6 +372,12 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
if (p) p.keywords = args.keywords;
return p;
}
+ case "photo_set_date": {
+ (window.__dates ??= []).push(args);
+ const p = (window.__photos ?? []).find((x) => x.id === args.id);
+ if (p) p.takenAt = args.takenAt;
+ return p;
+ }
case "photo_open_map": (window.__maps ??= []).push(args.id); return null;
case "photo_set_rating": {
(window.__ratings ??= []).push(args);
diff --git a/check.sh b/check.sh
index c203a1c..279c40b 100755
--- a/check.sh
+++ b/check.sh
@@ -69,6 +69,7 @@ step "viewer, real sizes" node .uiverify/photos-viewer-real.mjs
step "filmstrip" node .uiverify/photos-strip.mjs
step "place & keywords" node .uiverify/photos-info.mjs
step "download options" node .uiverify/photos-download.mjs
+step "adjust date" node .uiverify/photos-date.mjs
step "notes delete" node .uiverify/notes-delete.mjs
step "empty today" node .uiverify/reminders-empty.mjs
step "calendar keys" node .uiverify/calendar-keys.mjs
@@ -121,6 +122,7 @@ step "webkit: viewer sizes" env ENGINE=webkit node .uiverify/photos-viewer-real.
step "webkit: filmstrip" env ENGINE=webkit node .uiverify/photos-strip.mjs
step "webkit: place & keywords" env ENGINE=webkit node .uiverify/photos-info.mjs
step "webkit: downloads" env ENGINE=webkit node .uiverify/photos-download.mjs
+step "webkit: adjust date" env ENGINE=webkit node .uiverify/photos-date.mjs
step "webkit: delete" env ENGINE=webkit node .uiverify/notes-delete.mjs
step "webkit: row hover" env ENGINE=webkit node .uiverify/row-hover.mjs
step "webkit: fold" env ENGINE=webkit node .uiverify/sidebar-fold.mjs
diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rs
index 332eeee..49840cc 100644
--- a/crates/quince-icloud/src/photos.rs
+++ b/crates/quince-icloud/src/photos.rs
@@ -494,6 +494,29 @@ pub async fn set_keywords(
.await
}
+/// When a photo was taken, changed, as icloud.com's Adjust Date and Time changes it: `assetDate`,
+/// the moment in milliseconds, against the asset's change tag. (With Advanced Data Protection
+/// icloud.com writes `assetDateEnc` too; his account does not use it.) Answers the asset.
+pub async fn set_date(
+ http: &reqwest::Client,
+ ckdatabasews_root: &str,
+ params: Vec<(String, String)>,
+ asset: &str,
+ change_tag: Option<&str>,
+ millis: i64,
+) -> Result<Value> {
+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
+ client
+ .update_record(
+ ZONE,
+ asset,
+ "CPLAsset",
+ change_tag,
+ serde_json::json!({ "assetDate": { "value": millis } }),
+ )
+ .await
+}
+
/// An album's name as Photos writes it: base64 of its UTF-8 bytes, untyped.
fn album_name(name: &str) -> String {
base64::engine::general_purpose::STANDARD.encode(name.as_bytes())
diff --git a/probe/examples/photos_date_roundtrip.rs b/probe/examples/photos_date_roundtrip.rs
new file mode 100644
index 0000000..9007be1
--- /dev/null
+++ b/probe/examples/photos_date_roundtrip.rs
@@ -0,0 +1,47 @@
+//! Live, on a wallpaper he named as a throwaway: its date moved a day later through Quince's own
+//! set_date, read back from Apple, then put back exactly as it was.
+use anyhow::{anyhow, Result};
+use quince_icloud::photos::{self, CONTAINER, ZONE};
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let asset = std::env::args().nth(1).ok_or_else(|| anyhow!("asset id"))?;
+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
+ let mut client = quince_auth::Client::new(&dir)?;
+ if !client.resume().await? {
+ return Err(anyhow!("no session"));
+ }
+ let ck = client
+ .session()
+ .service_url("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ck"))?;
+ let (http, p) = (client.http().clone(), client.service_params());
+ let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &ck, CONTAINER, p.clone());
+ let date = |r: &serde_json::Value| {
+ r.pointer("/fields/assetDate/value")
+ .and_then(|v| v.as_i64())
+ };
+ let before = zc
+ .lookup_record(ZONE, &asset)
+ .await?
+ .ok_or_else(|| anyhow!("gone"))?;
+ let was = date(&before).ok_or_else(|| anyhow!("no date"))?;
+ println!("before: {was}");
+ let tag = before.get("recordChangeTag").and_then(|t| t.as_str());
+ photos::set_date(&http, &ck, p.clone(), &asset, tag, was + 86_400_000).await?;
+ let now = zc.lookup_record(ZONE, &asset).await?.unwrap();
+ println!(
+ "moved: {:?} (a day later: {})",
+ date(&now),
+ date(&now) == Some(was + 86_400_000)
+ );
+ let tag = now.get("recordChangeTag").and_then(|t| t.as_str());
+ photos::set_date(&http, &ck, p.clone(), &asset, tag, was).await?;
+ let back = zc.lookup_record(ZONE, &asset).await?.unwrap();
+ println!(
+ "back: {:?} (as it was: {})",
+ date(&back),
+ date(&back) == Some(was)
+ );
+ Ok(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index a87dc2c..385e0d7 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -3787,6 +3787,7 @@ fn main() {
photos::photo_set_rating,
photos::photo_set_keywords,
photos::photo_open_map,
+ photos::photo_set_date,
photos::photo_download,
note_table_add_row,
note_table_remove,
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index beaa63d..b32a0c0 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -682,6 +682,52 @@ pub async fn photo_set_keywords(
Ok(photo)
}
+/// When a photo was taken, as Adjust Date and Time sets it (unix seconds): Apple's answer taken
+/// at once.
+#[tauri::command]
+pub async fn photo_set_date(
+ id: String,
+ taken_at: i64,
+ auth: State<'_, Auth>,
+ data: State<'_, Data>,
+) -> UiResult<Photo> {
+ // Photos takes nothing before 1900 or past the end of 9999 — and neither does a camera.
+ if !(-2_208_988_800..253_402_300_800).contains(&taken_at) {
+ return Err("That date is out of range.".into());
+ }
+ let _one = crate::PHOTOS_PASS.lock().await;
+ let mut photo = data
+ .0
+ .lock()
+ .await
+ .photo(&id)
+ .map_err(|e| e.to_string())?
+ .ok_or("That photo is no longer in the library.")?;
+ let (http, root, params) = crate::cloudkit_context(&auth).await?;
+ let answer = quince_icloud::photos::set_date(
+ &http,
+ &root,
+ params,
+ &id,
+ photo.change_tag.as_deref(),
+ taken_at * 1000,
+ )
+ .await
+ .map_err(|e| e.to_string())?;
+ photo.taken_at = taken_at;
+ photo.change_tag = answer
+ .get("recordChangeTag")
+ .and_then(serde_json::Value::as_str)
+ .map(str::to_string)
+ .or(photo.change_tag);
+ data.0
+ .lock()
+ .await
+ .put_photos(std::slice::from_ref(&photo))
+ .map_err(|e| e.to_string())?;
+ Ok(photo)
+}
+
/// Where a photo was taken, opened in a map in the browser: OpenStreetMap at its coordinates.
/// Apple's place names come from Apple Maps, which is not here; the place itself is.
#[tauri::command]
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index 6b5da3e..54778a1 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -108,6 +108,8 @@ export const api = {
photoSetRating: (id: string, rating: number) => invoke<Photo>("photo_set_rating", { id, rating }),
photoSetKeywords: (id: string, keywords: string[]) => invoke<Photo>("photo_set_keywords", { id, keywords }),
photoOpenMap: (id: string) => invoke<void>("photo_open_map", { id }),
+ /** When it was taken, in unix seconds. */
+ photoSetDate: (id: string, takenAt: number) => invoke<Photo>("photo_set_date", { id, takenAt }),
/** Photos and videos (or folders of them) into the library. Answers the batch; progress
* arrives as PHOTO_UPLOAD events, in the same shape as Drive's. */
/** Into the library, and into `album` too when one is open. */
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 3c6398d..2dfd3ef 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -24,6 +24,7 @@ import { UploadPanel } from "./photos/UploadPanel";
import { RowMenu, type MenuEntry } from "../components/RowMenu";
import { Slideshow } from "./photos/Slideshow";
import { DownloadOptions, type Want } from "./photos/DownloadOptions";
+import { AdjustDate } from "./photos/AdjustDate";
/** The sidebar, in Photos' order, each with the symbol Photos gives it. */
const VIEWS: { key: PhotoView; label: string; Icon: LucideIcon }[] = [
@@ -426,6 +427,28 @@ export function PhotosView() {
}, [photos, sort?.by, drawn]);
const shown = open !== null ? photos?.[open] ?? null : null;
+ // The viewer follows the photo, not its place: when the list moves under it — its date
+ // changed, a sync reordered the library — it finds the photo again rather than showing
+ // whichever came to stand where it was.
+ const openId = useRef<string | null>(null);
+ const lastList = useRef(photos);
+ useLayoutEffect(() => {
+ const moved = lastList.current !== photos;
+ lastList.current = photos;
+ if (open === null || !photos) {
+ openId.current = null;
+ return;
+ }
+ // Only a list that changed sends it looking; a step to another photo is a new photo.
+ if (moved && openId.current && photos[open]?.id !== openId.current) {
+ const again = photos.findIndex((p) => p.id === openId.current);
+ if (again >= 0) {
+ setOpen(again);
+ return;
+ }
+ }
+ openId.current = photos[open]?.id ?? null;
+ }, [open, photos]);
/*
* The viewer opens as Photos opens a photo: it grows out of its tile while the dark comes up
@@ -1212,6 +1235,21 @@ export function PhotosView() {
}
};
+ /** Adjust Date and Time open for this photo. */
+ const [adjusting, setAdjusting] = useState<Photo | null>(null);
+ const redate = async (p: Photo, takenAt: number) => {
+ setAdjusting(null);
+ const before = photos;
+ setPhotos((all) => (all ?? []).map((x) => (x.id === p.id ? { ...x, takenAt } : x)));
+ try {
+ await api.photoSetDate(p.id, takenAt);
+ read().catch(() => {});
+ } catch (e) {
+ setPhotos(before);
+ setError(messageOf(e));
+ }
+ };
+
/** Download Options open for these photos. */
const [options, setOptions] = useState<Photo[] | null>(null);
const downloadAs = async (list: Photo[], want: Want) => {
@@ -1876,7 +1914,12 @@ export function PhotosView() {
<dt>Name</dt>
<dd>{shown.filename ?? "—"}</dd>
<dt>Taken</dt>
- <dd>
+ <dd className="px-taken">
+ {view !== "recentlyDeleted" && (
+ <button className="px-link px-adjust" onClick={() => setAdjusting(shown)}>
+ Adjust
+ </button>
+ )}
{new Date(shown.takenAt * 1000).toLocaleDateString(undefined, { dateStyle: "full" })} at{" "}
{new Date(shown.takenAt * 1000).toLocaleTimeString(undefined, { timeStyle: "short" })}
</dd>
@@ -1956,6 +1999,7 @@ export function PhotosView() {
)}
{menu && <RowMenu at={menu.at} entries={menu.entries} onClose={() => setMenu(null)} />}
{show && <Slideshow photos={show.list} start={show.start} onClose={() => setShow(null)} />}
+ {adjusting && <AdjustDate photo={adjusting} onSave={(t) => void redate(adjusting, t)} onClose={() => setAdjusting(null)} />}
{options && <DownloadOptions photos={options} onPick={(w) => void downloadAs(options, w)} onClose={() => setOptions(null)} />}
<UploadPanel uploads={[...uploads.values()]} onDismiss={dismissUploads} cancel={api.photosUploadCancel} />
</div>
diff --git a/src/screens/photos/AdjustDate.tsx b/src/screens/photos/AdjustDate.tsx
new file mode 100644
index 0000000..5be0999
--- /dev/null
+++ b/src/screens/photos/AdjustDate.tsx
@@ -0,0 +1,82 @@
+/**
+ * Adjust Date and Time, as icloud.com's: the photo, the timezone the times are in, the original
+ * date, and the one to give it — to the second. Save only once it is a different, real date.
+ */
+import { useEffect, useState } from "react";
+import { X } from "lucide-react";
+import { pictureSrc, type Photo } from "../../lib/ipc";
+
+const pad = (n: number) => String(n).padStart(2, "0");
+/** A moment as the field takes it, in this computer's own time: 2026-06-30T21:26:54. */
+const local = (seconds: number) => {
+ const d = new Date(seconds * 1000);
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
+};
+/** "GMT+05:30", as icloud.com names the zone. */
+const zone = () => {
+ const m = -new Date().getTimezoneOffset();
+ return `GMT${m >= 0 ? "+" : "−"}${pad(Math.floor(Math.abs(m) / 60))}:${pad(Math.abs(m) % 60)}`;
+};
+
+export function AdjustDate({ photo, onSave, onClose }: { photo: Photo; onSave: (takenAt: number) => void; onClose: () => void }) {
+ const [value, setValue] = useState(() => local(photo.takenAt));
+ useEffect(() => {
+ const key = (e: KeyboardEvent) => {
+ if (e.key !== "Escape") return;
+ e.preventDefault();
+ e.stopPropagation();
+ onClose();
+ };
+ window.addEventListener("keydown", key, true);
+ return () => window.removeEventListener("keydown", key, true);
+ }, [onClose]);
+ const ms = Date.parse(value);
+ const next = Number.isNaN(ms) ? null : Math.floor(ms / 1000);
+ const changed = next !== null && next !== photo.takenAt && next > -2_208_988_800 && next < 253_402_300_800;
+ const shown = new Date(photo.takenAt * 1000).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "medium" });
+ return (
+ <div className="px-sheet-scrim" role="presentation" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>
+ <form
+ className="px-sheet"
+ role="dialog"
+ aria-modal="true"
+ aria-label="Adjust Date and Time"
+ onSubmit={(e) => {
+ e.preventDefault();
+ if (changed && next !== null) onSave(next);
+ }}
+ >
+ <button type="button" className="px-sheet-x" aria-label="Close" onClick={onClose}>
+ <X size={16} strokeWidth={2.2} aria-hidden="true" />
+ </button>
+ <h2>Adjust Date and Time</h2>
+ <div className="px-dl-pics" aria-hidden="true">
+ <img src={pictureSrc(photo.id, "thumb")} alt="" />
+ </div>
+ <p className="px-date-zone">All times are {zone()}</p>
+ <div className="px-date-grid">
+ <span>Original:</span>
+ <output className="px-date-was">{shown}</output>
+ <label htmlFor="px-adjusted">Adjusted:</label>
+ <input
+ id="px-adjusted"
+ className="px-date-field"
+ type="datetime-local"
+ step={1}
+ value={value}
+ autoFocus
+ onChange={(e) => setValue(e.target.value)}
+ />
+ </div>
+ <div className="px-sheet-buttons">
+ <button type="button" className="px-sheet-button" onClick={onClose}>
+ Cancel
+ </button>
+ <button type="submit" className="px-sheet-button is-primary" disabled={!changed}>
+ Save
+ </button>
+ </div>
+ </form>
+ </div>
+ );
+}
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 21e641f..1eb016a 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -803,3 +803,40 @@
}
.px-dl-go:hover { background: color-mix(in srgb, var(--text) 14%, transparent); }
.px-dl-go:active { transform: scale(0.92); }
+
+/* Adjust Date and Time. */
+.px-taken { display: block; }
+.px-adjust { float: right; margin-left: 8px; font-size: var(--t-12, 12px); }
+.px-date-zone { margin: 8px 0 14px; text-align: center; color: var(--text-2); font-size: var(--t-12, 12px); }
+.px-date-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 10px; align-items: center; font-size: var(--t-13); }
+.px-date-grid > span, .px-date-grid > label { text-align: right; }
+.px-date-was, .px-date-field {
+ padding: 7px 10px;
+ border-radius: 8px;
+ background: var(--field, transparent);
+ box-shadow: inset 0 0 0 1px var(--field-edge, var(--separator));
+ color: var(--text);
+ font: inherit;
+ font-variant-numeric: tabular-nums;
+}
+.px-date-was { color: var(--text-2); }
+.px-date-field { border: 0; outline: none; }
+.px-date-field:focus { box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-ring); }
+.px-sheet-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
+.px-sheet-button {
+ height: 34px;
+ border: 0;
+ border-radius: 9px;
+ background: color-mix(in srgb, var(--text) 10%, transparent);
+ color: var(--text);
+ font: inherit;
+ font-size: var(--t-13);
+ font-weight: 600;
+ cursor: default;
+ transition: transform 140ms var(--spring-quick);
+}
+.px-sheet-button:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 15%, transparent); }
+.px-sheet-button:active:not(:disabled) { transform: scale(0.97); }
+.px-sheet-button.is-primary { background: var(--accent); color: #fff; }
+.px-sheet-button.is-primary:hover:not(:disabled) { background: var(--accent-strong); }
+.px-sheet-button:disabled { opacity: 0.45; }