Accept date shortcuts in the Work day field
Adding work to a day you forgot to track meant typing its full date. The Work day field now also takes 09-14 (this year), today, yesterday, -3 (three days ago) and weekday names like mon or friday (the most recent one). The editor shows the date it understood next to the field. The parsing lives in time::format::parse_date, next to parse_time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9257181a77
commit
fe5e2d9a7f
4 files changed
+81
-8
No files matched your search
@@ -16,7 +16,7 @@ use ratatui::widgets::Paragraph;
|
||||
use super::{field_line, message_line, window};
|
||||
use crate::action::Action;
|
||||
use crate::domain::{Segment, WorkDay};
|
||||
use crate::time::format::parse_time;
|
||||
use crate::time::format::{parse_date, parse_time};
|
||||
use crate::time::resolve::{nearest, next_after};
|
||||
use crate::ui::keymap::{self, Binding, Command};
|
||||
use crate::ui::widgets::text_input::{InputEvent, TextInput};
|
||||
@@ -88,11 +88,12 @@ impl SegmentEditor {
|
||||
}
|
||||
}
|
||||
|
||||
/// The work day the segment is filed under (the Work day field).
|
||||
fn work_day(&self) -> Result<Date, String> {
|
||||
/// The work day the segment is filed under (the Work day field, which
|
||||
/// also takes shortcuts like "yesterday", "-3" or "mon").
|
||||
fn work_day(&self, ctx: &Context) -> Result<Date, String> {
|
||||
match self.target {
|
||||
Target::Running { day, .. } => Ok(day),
|
||||
_ => self.day.text().trim().parse().map_err(|_| "work day: write it like 2026-09-24".to_string()),
|
||||
_ => parse_date(self.day.text(), ctx.now.date()).map_err(|error| format!("work day: {error}")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +123,7 @@ impl SegmentEditor {
|
||||
}
|
||||
|
||||
fn resolve(&self, ctx: &Context) -> Result<Resolved, String> {
|
||||
let day = self.work_day()?;
|
||||
let day = self.work_day(ctx)?;
|
||||
let start_time = parse_time(self.start.text()).map_err(|error| format!("start: {error}"))?;
|
||||
let start = nearest(start_time, &self.reference(day, ctx));
|
||||
let end = match self.end.text().trim() {
|
||||
@@ -221,7 +222,11 @@ impl Component for SegmentEditor {
|
||||
),
|
||||
];
|
||||
if !self.is_running() {
|
||||
let note = Span::styled("the day it counts for", ctx.theme.muted());
|
||||
// Which date the field means ("yesterday" → Wed Sep 23).
|
||||
let note = match self.work_day(ctx) {
|
||||
Ok(day) => Span::styled(ctx.fmt.date_short(day), ctx.theme.accent()),
|
||||
Err(_) => Span::styled("a date, yesterday, -3, mon...", ctx.theme.muted()),
|
||||
};
|
||||
lines.push(field_line("Work day", &self.day, self.field == 2, self.inserting, note, ctx.theme));
|
||||
}
|
||||
lines.push(Line::default());
|
||||
|
||||
Reference in new issue
Block a user