From cb35bd463a53383c06e60be4d843bdf1e7d9d68b Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 11 Aug 2025 15:09:08 -0400 Subject: fix: deadline wasn't parsing years --- README.md | 5 +-- src/soon.nim | 2 +- src/soon/conditionchecker.nim | 9 ++-- tests/tcolumnize.nim | 15 ++++++- tests/tparsetime.nim | 99 ++++++++++++++++++++++--------------------- 5 files changed, 70 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 6d1fb2d..4d6087c 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Attach a line with `+ Due: DATE` and it will show up in a list of upcoming deadl + Due: Aug 7 2025 ``` -You can delete finished todos from `soon i` or just from your text editor. +You can delete finished todos from `soon -i` or just from your text editor. # Archive File @@ -232,10 +232,7 @@ You might also be interested in these which are text based but have somewhat dif # Todo - Create tests for date ranges that start/end on DST changes. The condition checker treats every event as midnight, might be an edge case. -- Calendar output -- Open editor - Julian modulus calculator (`soon -j Jun 5 2025` > Outputs J and a table of common mod offsets) -- Color - TUI - CalDAV/.ics export? - Numerous CLI programs store calendars with .ics files directly, so it doesn't make much sense to use Soon if you need to sync to a "main" calendar. - Import? diff --git a/src/soon.nim b/src/soon.nim index 61ac16d..62dbfcf 100644 --- a/src/soon.nim +++ b/src/soon.nim @@ -11,7 +11,7 @@ Usage: soon [options] Options: -a print agenda --c print reference calendar +-c print reference calendar (using 'cal') -t print todos -d print deadlines -e open default calendar file in $EDITOR diff --git a/src/soon/conditionchecker.nim b/src/soon/conditionchecker.nim index f3eea22..eea5afb 100644 --- a/src/soon/conditionchecker.nim +++ b/src/soon/conditionchecker.nim @@ -31,8 +31,8 @@ proc weekdayToInt(w: string): int = let weekday = w.expandWeekday return find(weekdays, weekday) -# Returns MJD as if date was UTC proc modifiedJulianDay*(date: DateTime): int = +# Returns MJD as if date was UTC let dayZero = dateTime(1858, mNov, 17, 0, 0, 0, 0, utc()) let dateUTC = dateTime(date.year, date.month, date.monthday, 0, 0, 0, 0, utc()) return (dateUTC - dayZero).inDays @@ -44,8 +44,8 @@ proc getWeekFromEnd(date: DateTime): int = proc getWeek(date: DateTime): int = return int((date.monthDay - 1) / 7) + 1 -# Generically checks forwards (Mon-Fri) and backwards (Dec-Feb) ranges proc isInLoopingRange(left: int, right: int, date: int): bool = +# Generically checks forwards (Mon-Fri) and backwards (Dec-Feb) ranges if left <= right: return left <= date and right >= date else: @@ -115,14 +115,15 @@ proc conditionToInt(c: string): int = return parseInt(c) proc dateGroupStringToTable(s: string): Table[string, int] = - let conditions = s[1..s.len-2].splitWhitespace + # This used to be s.len-2 for some reason and I don't know why, but it left off the last condition + let conditions = s[1..s.len-1].splitWhitespace var t = initTable[string, int]() for c in conditions: t[typechecker.checkType(c)] = conditionToInt(c) return t -# comparisonDate is used for strings with no year like (Aug 15) proc dateGroupStringToDate*(s: string, comparisonDate: DateTime): DateTime = +# comparisonDate is used for strings with no year like (Aug 15) var t = dateGroupStringToTable(s) if not t.hasKey("year"): t["year"] = comparisonDate.year diff --git a/tests/tcolumnize.nim b/tests/tcolumnize.nim index 0e8e1c8..15f0171 100644 --- a/tests/tcolumnize.nim +++ b/tests/tcolumnize.nim @@ -3,6 +3,17 @@ import std/[unittest] test "Testing columnize": var table = newSeq[Line]() - table.add(Line(columns: @["Jan 1", "(OVERDUE)", "Do the thing"], attachments: @[])) - table.add(Line(columns: @["Feb 22", "(Due in 24 days)", "Do that other thing"], attachments: @[])) + + table.add(Line(columns: @[ + Column(text: "Jan 1", color: fgWhite), + Column(text: "(OVERDUE)", color: fgRed), + Column(text: "Do the thing", color: fgBlue) + ], attachments: @[])) + + table.add(Line(columns: @[ + Column(text: "Feb 22", color: fgWhite), + Column(text: "(Due in 24 days)", color: fgGreen), + Column(text: "Do that other thing", color: fgBlue) + ], attachments: @[])) + columnize.echo(table) diff --git a/tests/tparsetime.nim b/tests/tparsetime.nim index d60a5fa..aeb1b37 100644 --- a/tests/tparsetime.nim +++ b/tests/tparsetime.nim @@ -4,57 +4,58 @@ import std/[times] # Everything has +1.days to easily sort all-day events before scheduled ones -test "Parse single times": - check toDateTime("9") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9:00") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9:30") == parse("0930", "HHmm", utc()) + 1.days - check toDateTime("09:00") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("09:30") == parse("0930", "HHmm", utc()) + 1.days - check toDateTime("9:00am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9:30pm") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("09:00am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("09:00pm") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("09:30am") == parse("0930", "HHmm", utc()) + 1.days - check toDateTime("09:30pm") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("17") == parse("1700", "HHmm", utc()) + 1.days - check toDateTime("24") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("17:00") == parse("1700", "HHmm", utc()) + 1.days - check toDateTime("12:00") == parse("1200", "HHmm", utc()) + 1.days - check toDateTime("24:00") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("00:00") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("01:00") == parse("0100", "HHmm", utc()) + 1.days - +proc expectedTime(time: string): DateTime = + parse(time, "HHmm", utc()) + 1.days +test "Parse valid single time formats": + check toDateTime("9") == expectedTime("0900") + check toDateTime("9am") == expectedTime("0900") + check toDateTime("9:00") == expectedTime("0900") + check toDateTime("9:30") == expectedTime("0930") + check toDateTime("09:00") == expectedTime("0900") + check toDateTime("09:30") == expectedTime("0930") + check toDateTime("9:00am") == expectedTime("0900") + check toDateTime("9:30pm") == expectedTime("2130") + check toDateTime("09:00am") == expectedTime("0900") + check toDateTime("09:00pm") == expectedTime("2100") + check toDateTime("09:30am") == expectedTime("0930") + check toDateTime("09:30pm") == expectedTime("2130") + check toDateTime("17") == expectedTime("1700") + check toDateTime("24") == expectedTime("0000") + check toDateTime("17:00") == expectedTime("1700") + check toDateTime("12:00") == expectedTime("1200") + check toDateTime("24:00") == expectedTime("0000") + check toDateTime("00:00") == expectedTime("0000") + check toDateTime("01:00") == expectedTime("0100") test "Parse time ranges": - check toDateTime("9am-1am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9:00am-1:00am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9:30pm-01:00am") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("09:00am-01:00am") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("09:00pm-01:00am") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("09:30am-01:30am") == parse("0930", "HHmm", utc()) + 1.days - check toDateTime("09:30pm-01:30am") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("11:00-13:00") == parse("1100", "HHmm", utc()) + 1.days - check toDateTime("12:00-13:00") == parse("1200", "HHmm", utc()) + 1.days - check toDateTime("11:00-24:00") == parse("1100", "HHmm", utc()) + 1.days - check toDateTime("23:00-24:00") == parse("2300", "HHmm", utc()) + 1.days - check toDateTime("24:00-23:00") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("9pm-12am") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("17-1am") == parse("1700", "HHmm", utc()) + 1.days - check toDateTime("9-1am") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("9:00-1:00am") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("9:30-1:30am") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("09:00-01:00am") == parse("2100", "HHmm", utc()) + 1.days - check toDateTime("09:30-01:30am") == parse("2130", "HHmm", utc()) + 1.days - check toDateTime("17:00-1:00am") == parse("1700", "HHmm", utc()) + 1.days - check toDateTime("12:00-1:00am") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("12-1:00am") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("00:00-01:00am") == parse("0000", "HHmm", utc()) + 1.days - check toDateTime("11-12pm") == parse("1100", "HHmm", utc()) + 1.days - check toDateTime("11-12am") == parse("2300", "HHmm", utc()) + 1.days - check toDateTime("11-12") == parse("1100", "HHmm", utc()) + 1.days - check toDateTime("9-1700") == parse("0900", "HHmm", utc()) + 1.days - check toDateTime("9-1100") == parse("0900", "HHmm", utc()) + 1.days + check toDateTime("9am-1am") == expectedTime("0900") + check toDateTime("9:00am-1:00am") == expectedTime("0900") + check toDateTime("9:30pm-01:00am") == expectedTime("2130") + check toDateTime("09:00am-01:00am") == expectedTime("0900") + check toDateTime("09:00pm-01:00am") == expectedTime("2100") + check toDateTime("09:30am-01:30am") == expectedTime("0930") + check toDateTime("09:30pm-01:30am") == expectedTime("2130") + check toDateTime("11:00-13:00") == expectedTime("1100") + check toDateTime("12:00-13:00") == expectedTime("1200") + check toDateTime("11:00-24:00") == expectedTime("1100") + check toDateTime("23:00-24:00") == expectedTime("2300") + check toDateTime("24:00-23:00") == expectedTime("0000") + check toDateTime("9pm-12am") == expectedTime("2100") + check toDateTime("17-1am") == expectedTime("1700") + check toDateTime("9-1am") == expectedTime("2100") + check toDateTime("9:00-1:00am") == expectedTime("2100") + check toDateTime("9:30-1:30am") == expectedTime("2130") + check toDateTime("09:00-01:00am") == expectedTime("2100") + check toDateTime("09:30-01:30am") == expectedTime("2130") + check toDateTime("17:00-1:00am") == expectedTime("1700") + check toDateTime("12:00-1:00am") == expectedTime("0000") + check toDateTime("12-1:00am") == expectedTime("0000") + check toDateTime("00:00-01:00am") == expectedTime("0000") + check toDateTime("11-12pm") == expectedTime("1100") + check toDateTime("11-12am") == expectedTime("2300") + check toDateTime("11-12") == expectedTime("1100") + check toDateTime("9-1700") == expectedTime("0900") + check toDateTime("9-1100") == expectedTime("0900") -- cgit v1.2.3