diff --git a/crates/iz-core/src/board.rs b/crates/iz-core/src/board.rs index 6ee3a53..2bbc3d2 100644 --- a/crates/iz-core/src/board.rs +++ b/crates/iz-core/src/board.rs @@ -178,12 +178,11 @@ impl TaskCard { !self.is_done() && !self.blocked_by.is_empty() } - /// Past its deadline and not finished. A deadline of today is not overdue. - pub fn is_overdue(&self, today: Date) -> bool { - match self.deadline { - Some(day) => !self.is_done() && day < today, - None => false, - } + /// Past its deadline and not finished — the shared + /// [`deadline_is_overdue`] decision, so a passed clock counts here even + /// though the card shows the clock rather than the day. + pub fn is_overdue(&self, now: OffsetDateTime) -> bool { + deadline_is_overdue(self.is_done(), self.deadline, self.clock_at, now) } pub fn is_assigned_to(&self, user_id: &str) -> bool { @@ -194,12 +193,14 @@ impl TaskCard { /// `Aug 21 · overdue`, `done Aug 14` or `no deadline`. English-only — /// kept for callers (mail, tests) that want the baked sentence; UI /// rendering should use [`TaskCard::deadline_parts`] and translate. - pub fn deadline_label(&self, today: Date) -> String { + pub fn deadline_label(&self, now: OffsetDateTime) -> String { if let Some(done) = self.done_at { return format!("done {}", day_label(done.date())); } match self.deadline { - Some(day) if day < today => format!("{} · overdue", day_label(day)), + Some(day) if deadline_is_overdue(false, Some(day), self.clock_at, now) => { + format!("{} · overdue", day_label(day)) + } Some(day) => day_label(day), None => "no deadline".to_string(), } @@ -208,7 +209,7 @@ impl TaskCard { /// The same chip as [`TaskCard::deadline_label`], split into a /// language-free date string and a state the caller translates. /// `None` when there's nothing to show (no deadline, not done). - pub fn deadline_parts(&self, today: Date) -> Option { + pub fn deadline_parts(&self, now: OffsetDateTime) -> Option { if let Some(done) = self.done_at { return Some(DeadlineParts { date: day_label(done.date()), @@ -217,7 +218,7 @@ impl TaskCard { } self.deadline.map(|day| DeadlineParts { date: day_label(day), - state: if day < today { + state: if deadline_is_overdue(false, Some(day), self.clock_at, now) { DeadlineState::Overdue } else { DeadlineState::OnTime @@ -241,6 +242,25 @@ pub enum DeadlineState { Done, } +/// The one overdue decision behind the card, the filter count and the task +/// detail. Done is never overdue. A clock beats the day: the instant itself +/// has to be reached — including a past day whose clock is still ahead. With +/// only a day, the day has to be strictly past; today is not overdue yet. +pub fn deadline_is_overdue( + done: bool, + deadline: Option, + clock_at: Option, + now: OffsetDateTime, +) -> bool { + if done { + return false; + } + match clock_at { + Some(at) => at <= now, + None => deadline.is_some_and(|day| day < now.date()), + } +} + /// A column with its cards already in it. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ColumnView { @@ -269,8 +289,8 @@ impl BoardView { } /// The `1 overdue` chip in the filter bar. - pub fn overdue_count(&self, today: Date) -> usize { - self.cards().filter(|card| card.is_overdue(today)).count() + pub fn overdue_count(&self, now: OffsetDateTime) -> usize { + self.cards().filter(|card| card.is_overdue(now)).count() } /// The `2 blocked` chip beside it. @@ -555,3 +575,269 @@ mod reads { ))) } } + +#[cfg(test)] +mod deadline_is_overdue_tests { + use super::*; + use crate::detail::TaskDetail; + use time::macros::{date, datetime}; + + /// The board's "now": mid-afternoon on the 15th. + fn now() -> OffsetDateTime { + datetime!(2026-09-15 15:00 UTC) + } + + fn at(day: Date, hour: u8) -> OffsetDateTime { + day.with_time(time::Time::from_hms(hour, 0, 0).unwrap()) + .assume_utc() + } + + fn card( + deadline: Option, + clock_at: Option, + done_at: Option, + ) -> TaskCard { + TaskCard { + id: String::new(), + task_key: String::new(), + title: String::new(), + column_id: String::new(), + deadline, + clock_at, + done_at, + position: 0.0, + assignees: Vec::new(), + comment_count: 0, + blocked_by: Vec::new(), + blocks: Vec::new(), + subtask_total: 0, + subtask_done: 0, + tag: None, + } + } + + fn detail( + deadline: Option, + clock_at: Option, + done_at: Option, + ) -> TaskDetail { + TaskDetail { + id: String::new(), + task_key: String::new(), + title: String::new(), + description: String::new(), + column: Column { + id: String::new(), + name: String::new(), + position: 0, + is_done: false, + }, + columns: Vec::new(), + tag: None, + deadline, + clock_at, + done_at, + assignees: Vec::new(), + assignable: Vec::new(), + blocked_by: Vec::new(), + blocks: Vec::new(), + comments: Vec::new(), + files: Vec::new(), + activity: Vec::new(), + parent: None, + subtasks: Vec::new(), + } + } + + #[test] + fn day_only_deadlines_follow_the_day() { + let now = now(); + // Yesterday is overdue, today is not yet, tomorrow is not. + assert!(deadline_is_overdue(false, Some(date!(2026 - 09 - 14)), None, now)); + assert!(!deadline_is_overdue(false, Some(date!(2026 - 09 - 15)), None, now)); + assert!(!deadline_is_overdue(false, Some(date!(2026 - 09 - 16)), None, now)); + // No deadline is never overdue. + assert!(!deadline_is_overdue(false, None, None, now)); + } + + #[test] + fn the_clock_wins_and_the_instant_decides() { + let now = now(); + // Earlier today: the instant has passed. + assert!(deadline_is_overdue( + false, + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 9)), + now + )); + // Later today: it has not. + assert!(!deadline_is_overdue( + false, + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 18)), + now + )); + // The exact instant counts as reached. + assert!(deadline_is_overdue( + false, + Some(date!(2026 - 09 - 15)), + Some(now), + now + )); + // A past day whose clock is still ahead waits for the clock. + assert!(!deadline_is_overdue( + false, + Some(date!(2026 - 09 - 13)), + Some(at(date!(2026 - 09 - 16), 9)), + now + )); + // A past day with a past clock is overdue. + assert!(deadline_is_overdue( + false, + Some(date!(2026 - 09 - 13)), + Some(at(date!(2026 - 09 - 13), 18)), + now + )); + // A future day is not, whatever the clock says. + assert!(!deadline_is_overdue( + false, + Some(date!(2026 - 09 - 16)), + Some(at(date!(2026 - 09 - 16), 18)), + now + )); + } + + #[test] + fn done_is_never_overdue() { + let now = now(); + let done_at = Some(at(date!(2026 - 09 - 14), 12)); + assert!(!deadline_is_overdue( + true, + Some(date!(2026 - 09 - 13)), + Some(at(date!(2026 - 09 - 13), 18)), + now + )); + let finished = card(Some(date!(2026 - 09 - 13)), Some(at(date!(2026 - 09 - 13), 18)), done_at); + assert!(!finished.is_overdue(now)); + // The card's Done arm: the chip says done, not overdue. + assert_eq!( + finished.deadline_parts(now).map(|parts| parts.state), + Some(DeadlineState::Done) + ); + } + + #[test] + fn card_and_detail_agree_on_the_same_facts() { + let now = now(); + let facts = [ + (Some(date!(2026 - 09 - 14)), None), + (Some(date!(2026 - 09 - 15)), None), + (Some(date!(2026 - 09 - 15)), Some(at(date!(2026 - 09 - 15), 9))), + (Some(date!(2026 - 09 - 15)), Some(at(date!(2026 - 09 - 15), 18))), + (Some(date!(2026 - 09 - 13)), Some(at(date!(2026 - 09 - 13), 18))), + (None, None), + ]; + for (deadline, clock_at) in facts { + assert_eq!( + card(deadline, clock_at, None).is_overdue(now), + detail(deadline, clock_at, None).is_overdue(now), + "{deadline:?} at {clock_at:?}" + ); + let overdue = detail(deadline, clock_at, None).is_overdue(now); + assert_eq!( + detail(deadline, clock_at, None) + .deadline_parts(now) + .map(|parts| parts.state == DeadlineState::Overdue), + deadline.map(|_| overdue), + "{deadline:?} at {clock_at:?}" + ); + let card_parts = card(deadline, clock_at, None).deadline_parts(now); + assert_eq!( + card_parts.map(|parts| parts.state == DeadlineState::Overdue), + deadline.map(|_| overdue), + "{deadline:?} at {clock_at:?}" + ); + } + } + + #[test] + fn labels_stay_day_grain_but_borrow_the_boolean() { + let now = now(); + // A passed clock prints the day, not the time; only `overdue` is new. + let clocked = card( + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 9)), + None, + ); + assert_eq!(clocked.deadline_label(now), "Sep 15 · overdue"); + // A clock still ahead prints the bare day. + let waiting = card( + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 18)), + None, + ); + assert_eq!(waiting.deadline_label(now), "Sep 15"); + // The detail agrees, and a finished task never wears the word. + assert_eq!( + detail( + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 9)), + None + ) + .deadline_label(now), + "Sep 15 · overdue" + ); + assert_eq!( + detail( + Some(date!(2026 - 09 - 13)), + Some(at(date!(2026 - 09 - 13), 18)), + Some(at(date!(2026 - 09 - 14), 12)) + ) + .deadline_label(now), + "Sep 13" + ); + } + + #[test] + fn the_filter_chip_counts_the_same_decision() { + let now = now(); + let view = BoardView { + board: BoardMeta { + id: String::new(), + name: String::new(), + task_prefix: String::new(), + }, + columns: vec![ColumnView { + column: Column { + id: String::new(), + name: String::new(), + position: 0, + is_done: false, + }, + cards: vec![ + // Overdue: yesterday. + card(Some(date!(2026 - 09 - 14)), None, None), + // Overdue: the clock passed earlier today. + card( + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 9)), + None, + ), + // Not overdue: the clock is still ahead. + card( + Some(date!(2026 - 09 - 15)), + Some(at(date!(2026 - 09 - 15), 18)), + None, + ), + // Not overdue: done. + card( + Some(date!(2026 - 09 - 13)), + Some(at(date!(2026 - 09 - 13), 18)), + Some(at(date!(2026 - 09 - 14), 12)), + ), + ], + }], + }; + assert_eq!(view.overdue_count(now), 2); + } +} diff --git a/crates/iz-core/src/detail.rs b/crates/iz-core/src/detail.rs index c6570cb..bb689b2 100644 --- a/crates/iz-core/src/detail.rs +++ b/crates/iz-core/src/detail.rs @@ -8,7 +8,9 @@ use serde::{Deserialize, Serialize}; use time::{Date, OffsetDateTime, UtcOffset}; -use crate::board::{Column, DeadlineParts, DeadlineState, Person, TagChip, day_label}; +use crate::board::{ + Column, DeadlineParts, DeadlineState, Person, TagChip, day_label, deadline_is_overdue, +}; /// The stored task, plus the two ids the reader needs to know it is allowed to /// see it. The description lives here rather than on @@ -442,19 +444,18 @@ impl TaskDetail { !self.is_done() && self.blocked_by.iter().any(|edge| !edge.is_cleared()) } - pub fn is_overdue(&self, today: Date) -> bool { - match self.deadline { - Some(day) => !self.is_done() && day < today, - None => false, - } + /// The same [`crate::board::deadline_is_overdue`] decision the card + /// makes, so a passed clock is overdue here and there alike. + pub fn is_overdue(&self, now: OffsetDateTime) -> bool { + crate::board::deadline_is_overdue(self.is_done(), self.deadline, self.clock_at, now) } /// The DEADLINE field's text: `Aug 21 · overdue`, `Sep 12`, `no deadline`. /// English-only — kept for non-UI callers; UI rendering should use /// [`TaskDetail::deadline_parts`] and translate. - pub fn deadline_label(&self, today: Date) -> String { + pub fn deadline_label(&self, now: OffsetDateTime) -> String { match self.deadline { - Some(day) if !self.is_done() && day < today => { + Some(day) if deadline_is_overdue(self.is_done(), Some(day), self.clock_at, now) => { format!("{} · overdue", day_label(day)) } Some(day) => day_label(day), @@ -465,10 +466,10 @@ impl TaskDetail { /// The same field as [`TaskDetail::deadline_label`], split into a /// language-free date string and a state the caller translates. `None` /// when there's no deadline set. - pub fn deadline_parts(&self, today: Date) -> Option { + pub fn deadline_parts(&self, now: OffsetDateTime) -> Option { self.deadline.map(|day| DeadlineParts { date: day_label(day), - state: if !self.is_done() && day < today { + state: if deadline_is_overdue(self.is_done(), Some(day), self.clock_at, now) { DeadlineState::Overdue } else { DeadlineState::OnTime diff --git a/crates/iz-core/tests/store.rs b/crates/iz-core/tests/store.rs index 90cea8f..08addfb 100644 --- a/crates/iz-core/tests/store.rs +++ b/crates/iz-core/tests/store.rs @@ -1342,10 +1342,10 @@ async fn a_card_carries_its_assignees_comments_and_dependency_keys() { assert_eq!(waiting.comment_count, 0); assert!(waiting.assignees.is_empty()); - let today = date!(2026 - 08 - 26); - assert_eq!(card.deadline_label(today), "Aug 21 · overdue"); - assert_eq!(waiting.deadline_label(today), "Oct 06"); - assert_eq!(board.overdue_count(today), 1); + let now = date!(2026 - 08 - 26).midnight().assume_utc(); + assert_eq!(card.deadline_label(now), "Aug 21 · overdue"); + assert_eq!(waiting.deadline_label(now), "Oct 06"); + assert_eq!(board.overdue_count(now), 1); assert_eq!(board.blocked_count(), 1); } diff --git a/crates/iz-web/src/board.rs b/crates/iz-web/src/board.rs index 0ea5320..81a3774 100644 --- a/crates/iz-web/src/board.rs +++ b/crates/iz-web/src/board.rs @@ -8,7 +8,7 @@ use iz_core::board::{DeadlineState, Moved, TaskCard, day_label}; use iz_core::store::{NewTask, User}; -use time::{Date, OffsetDateTime}; +use time::OffsetDateTime; use topcoat::Result; use topcoat::context::Cx; use topcoat::router::content::Form; @@ -350,6 +350,7 @@ fn sort_column_cards(cards: &mut [TaskCard], sort: &str) { /// The whole column list. async fn board_columns<'a>( cx: &'a Cx, + now: OffsetDateTime, sort: String, tag_filter: Option, assigned: Option, @@ -387,7 +388,6 @@ async fn board_columns<'a>( column.column.name = crate::i18n::column_name(lang, &column.column.name); sort_column_cards(&mut column.cards, &sort); } - let today = OffsetDateTime::now_utc().date(); let may_write = user.role.can_write_tasks(); let zone = iz_core::detail::parse_zone(&user.timezone); @@ -402,7 +402,7 @@ async fn board_columns<'a>( render_column( cx, column, - today, + now, zone, may_write, &all_columns, @@ -424,7 +424,7 @@ async fn board_columns<'a>( async fn render_column<'a>( cx: &'a Cx, column: iz_core::board::ColumnView, - today: Date, + now: OffsetDateTime, zone: time::UtcOffset, may_write: bool, all_columns: &[(String, String)], @@ -442,7 +442,7 @@ async fn render_column<'a>( render_card( cx, card, - today, + now, is_done_column, zone, &column_id, @@ -478,7 +478,7 @@ async fn render_column<'a>( async fn render_card<'a>( cx: &'a Cx, card: TaskCard, - today: Date, + now: OffsetDateTime, done_column: bool, zone: time::UtcOffset, column_id: &str, @@ -489,11 +489,9 @@ async fn render_card<'a>( ) -> Result { let blocks = card.blocks.join(", "); let blocked_by = card.blocked_by.join(", "); - let overdue = card.is_overdue(today); - let deadline_parts = card.deadline_parts(today); - // A clock is the meeting's exact instant, read in the viewer's own zone; - // when it exists it is the whole chip — the day-grain deadline keeps its - // own state machinery out of the way rather than standing next to it. + let overdue = card.is_overdue(now); + let deadline_parts = card.deadline_parts(now); + // Overdue is `is_overdue`; the clock only changes the label text. let clock = card.clock_at.map(|at| { let at = at.to_offset(zone); format!( @@ -506,6 +504,7 @@ async fn render_card<'a>( let has_clock = clock.is_some(); let dated = deadline_parts.is_some() || has_clock; let deadline = match clock { + Some(label) if overdue => format!("{label} · {}", t(lang, Key::Overdue)), Some(label) => label, None => match deadline_parts { Some(parts) => match parts.state { @@ -548,7 +547,7 @@ async fn render_card<'a>(
// Overdue is a comparison against today, so a tab left open // over midnight is wrong until something re-renders it. - + (deadline) if let Some(tag) = &card.tag { @@ -800,8 +799,8 @@ pub async fn board_page<'a>(cx: &'a Cx, user: &'a User) -> Result = view_data @@ -951,7 +950,7 @@ pub async fn board_page<'a>(cx: &'a Cx, user: &'a User) -> Result

(t(lang, Key::NoMatches))

} else {
- (topcoat::view::Child::new(board_columns(cx, sort.clone(), tag_filter.clone(), assigned_filter.clone(), search.clone(), default_tag_id).await?)) + (topcoat::view::Child::new(board_columns(cx, now, sort.clone(), tag_filter.clone(), assigned_filter.clone(), search.clone(), default_tag_id).await?))
} diff --git a/crates/iz-web/src/detail.rs b/crates/iz-web/src/detail.rs index 66fc7e8..f4e1eec 100644 --- a/crates/iz-web/src/detail.rs +++ b/crates/iz-web/src/detail.rs @@ -1370,14 +1370,14 @@ async fn description_control<'a>( async fn deadline_control<'a>( cx: &'a Cx, task: &'a TaskDetail, - today: Date, + now: time::OffsetDateTime, zone: UtcOffset, may_write: bool, lang: Lang, ) -> Result { - let overdue = task.is_overdue(today); + let overdue = task.is_overdue(now); let local = task.clock_at.map(|at| at.to_offset(zone)); - let label = match (&local, task.deadline_parts(today)) { + let label = match (&local, task.deadline_parts(now)) { (Some(at), Some(parts)) if parts.state == DeadlineState::Overdue => { format!( "{} {:02}:{:02} · {}", @@ -2096,7 +2096,7 @@ pub async fn task_modal<'a>( let DetailSnapshot { detail, me, - today, + today: _, zone, linkable, adoptable, @@ -2256,7 +2256,7 @@ pub async fn task_modal<'a>(
(t(lang, Key::Deadline)) - (topcoat::view::Child::new(deadline_control(cx, &detail, today, zone, may_write, lang).await?)) + (topcoat::view::Child::new(deadline_control(cx, &detail, time::OffsetDateTime::now_utc(), zone, may_write, lang).await?))
(format!("{} — {}", t(lang, Key::Assignees), detail.assignees.len())) diff --git a/crates/iz-web/tests/http.rs b/crates/iz-web/tests/http.rs index 1c6cef7..278491c 100644 --- a/crates/iz-web/tests/http.rs +++ b/crates/iz-web/tests/http.rs @@ -9132,6 +9132,110 @@ async fn a_card_wears_the_clock_chip_in_the_viewers_zone_instead_of_the_deadline ); } +/// A clock that has passed makes the card overdue the same way the detail +/// already is: the chip carries ` · overdue` and the overdue class, the +/// filter count counts it, and the detail field keeps its own +/// `day time · overdue` shape. A future clock on the same board stays clean. +#[tokio::test] +async fn a_past_clock_reads_overdue_on_the_card_like_the_detail() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + + // The viewer is pinned to UTC, so the typed 18:00 is the stored instant. + app.store + .sync_member("im-ada", "ada@iz.sh", "Ada Lovelace", true, 0, "UTC") + .await + .unwrap(); + + let column = first_column(&app).await; + let yesterday = time::OffsetDateTime::now_utc() - time::Duration::days(1); + let ymd = format!( + "{:04}-{:02}-{:02}", + yesterday.year(), + yesterday.month() as u8, + yesterday.day() + ); + let answer = app + .post( + "/api/create_task", + Some(&admin_cookie), + &[ + ("title", "Standup"), + ("column_id", &column), + ("deadline", &ymd), + ("clock_hour", "18"), + ("clock_minute", "00"), + ], + ) + .await; + assert!( + !answer + .location + .as_deref() + .unwrap_or_default() + .contains("refusal="), + "{:?}", + answer.location + ); + + // A same-request control: a clock still ahead of now never reads overdue. + let later = app + .post( + "/api/create_task", + Some(&admin_cookie), + &[ + ("title", "Kickoff later"), + ("column_id", &column), + ("deadline", "2027-09-02"), + ("clock_hour", "18"), + ("clock_minute", "00"), + ], + ) + .await; + assert!( + !later + .location + .as_deref() + .unwrap_or_default() + .contains("refusal="), + "{:?}", + later.location + ); + + let workspace_id = app.workspace_id().await; + let board = iz_core::board::load(app.store.as_ref(), &workspace_id) + .await + .unwrap() + .unwrap(); + let task = board + .cards() + .find(|card| card.title == "Standup") + .expect("the overdue task is not on the board") + .id + .clone(); + + let day = iz_core::board::day_label(yesterday.date()); + let page = app.get("/", Some(&admin_cookie)).await; + let html = String::from_utf8_lossy(&page.bytes); + assert!( + html.contains(&format!( + r#"data-tick="" class="card-deadline card-deadline-overdue">{day} · 18:00 · overdue<"# + )), + "{html}" + ); + assert!( + html.contains(r#"data-tick="" class="card-deadline">Sep 02 · 18:00<"#), + "the future clock picked up an overdue mark: {html}" + ); + + // The detail keeps its own shape: `day time · overdue`, no middle dot + // between day and time. + let page = app.get(&format!("/?task={task}"), Some(&admin_cookie)).await; + let html = String::from_utf8_lossy(&page.bytes); + assert!(html.contains("detail-overdue"), "{html}"); + assert!(html.contains(&format!("{day} 18:00 · overdue")), "{html}"); +} + #[tokio::test] async fn a_time_set_on_an_existing_day_writes_both_columns() { let app = App::open().await;