aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/then.nim55
-rw-r--r--test.nim12
3 files changed, 35 insertions, 34 deletions
diff --git a/README.md b/README.md
index 247ee5f..8d8c276 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,7 @@ Julian date modulus is definitely weird, but it's a concise way to express multi
# Why would I use this?
-Then was created to adapt existing CLI calendars to my personal workflow. Then is not only for the niche of people who use their terminal for scheduling, but for a sub-niche who prefer to edit a file over using a TUI which is why concise, legible syntax is so important. This is a very small group of people virtually exclusively using [Remind](https://dianne.skoll.ca/projects/remind/). If you're happy with a web or phone calendar, Then probably won't change your mind.
+Then was created to adapt existing CLI calendars to my personal workflow. Then is not only for the niche of people who use their terminal for scheduling, but for a sub-niche who prefer to edit a file over using a TUI which is why concise, legible syntax is so important. This is a very small group of people who virtually exclusively use [Remind](https://dianne.skoll.ca/projects/remind/). If you're happy with a web or phone calendar, Then probably won't change your mind.
Then has a few benefits over similar text file calendars:
diff --git a/src/then.nim b/src/then.nim
index 4e878b5..44a7076 100644
--- a/src/then.nim
+++ b/src/then.nim
@@ -61,11 +61,23 @@ proc checkType(c: string): string =
if find(cond, re"^\d{1,2}$") > -1: return "day"
if cond in DefaultLocale.MMM.toHashSet or cond in DefaultLocale.MMMM.toHashSet: return "month"
if cond in DefaultLocale.ddd.toHashSet or cond in DefaultLocale.dddd.toHashSet: return "dayofweek"
- if find(cond, re"\d{1,2}:\d{2}") > -1: return "time"
+ if find(cond, re"^\d{1,2}:\d{2}(-\d{1,2}:\d{2})?$") > -1: return "time"
if find(cond, re"^\dw$") > -1: return "firstweek"
if find(cond, re"^\dl$") > -1: return "lastweek"
if find(cond, re"^\(?\s*J\s*%\s*\d\s*([-+]\d)?\s*\)?$") > -1: return "julian"
if find(cond, re"^\(.*\)$") > -1: return "dategroup"
+ if find(cond, re"^\d{4}-\d{4}$") > -1: return "rangeyear"
+ if find(cond, re"^\d{1,2}-\d{1,2}$") > -1: return "rangeday"
+
+ var cs = cond.split("-", maxsplit = 1)
+ if cs.len != 2: return "unknown"
+ if (cs[0] in DefaultLocale.MMM.toHashSet or cs[0] in DefaultLocale.MMMM.toHashSet) and
+ (cs[1] in DefaultLocale.MMM.toHashSet or cs[1] in DefaultLocale.MMMM.toHashSet):
+ return "rangemonth"
+ if (cs[0] in DefaultLocale.ddd.toHashSet or cs[0] in DefaultLocale.dddd.toHashSet) and
+ (cs[1] in DefaultLocale.ddd.toHashSet or cs[1] in DefaultLocale.dddd.toHashSet):
+ return "rangedayofweek"
+ if find(cs[0], re"^\(.*\)$") > -1 and find(cs[1], re"^\(.*\)$") > -1: return "rangedategroup"
return "unknown"
proc getWeekFromEnd(date: DateTime): int =
@@ -73,7 +85,7 @@ proc getWeekFromEnd(date: DateTime): int =
return int((daysInMonth - date.monthday) / 7) + 1
proc getWeek(date: DateTime): int =
- return int((date.monthDay -1) / 7) + 1
+ return int((date.monthDay - 1) / 7) + 1
proc checkCond(cond: string, date: DateTime): bool =
case checkType(cond):
@@ -90,10 +102,10 @@ proc checkCond(cond: string, date: DateTime): bool =
if cond == date.format("dddd"): return true
of "time":
return true
- of "firstweek":
- if cond[0] == getWeek(date): return true
- of "lastweek":
- if cond[0] == getWeekFromEnd(date): return true
+ #of "firstweek":
+ # if cond[0] == getWeek(date): return true
+ #of "lastweek":
+ # if cond[0] == getWeekFromEnd(date): return true
of "unknown":
echo "ERROR: Unknown condition: ", cond
return false
@@ -107,8 +119,9 @@ proc splitWhitespaceExceptParens(str:string): seq[string] =
result.add(result.pop & ' ' & token)
else:
result.add(token)
- if token.contains('('): inParens = true
- if token.contains(')'): inParens = false
+ for c in token:
+ if c == '(': inParens = true
+ if c == ')': inParens = false
return result
# Returns Table[conditionType, seq of conditions]
@@ -131,19 +144,19 @@ proc getEvents(cal: seq[string], date: DateTime): seq[string] =
date.strip
event.strip
let conditions = parseDateToTable(date)
- var match = true
- # This logic no longer works for how we've made the table
- for k,cs in conditions:
- for c in cs:
- var cond = c.toLower.capitalizeAscii
- if checkCond(cond, date) == false:
- match = false
- break
- if match:
- events.add(event)
- break
- else:
- echo "WARNING: Cannot parse line: ", line
+ echo conditions
+ # var match = true
+ # for k,cs in conditions:
+ # for c in cs:
+ # var cond = c.toLower.capitalizeAscii
+ # #if checkCond(cond, date) == false:
+ # # match = false
+ # # break
+ # if match:
+ # events.add(event)
+ # break
+ #else:
+ # echo "WARNING: Cannot parse line: ", line
return events
proc printEvents(cal: seq[string], date: DateTime) =
diff --git a/test.nim b/test.nim
deleted file mode 100644
index 7333396..0000000
--- a/test.nim
+++ /dev/null
@@ -1,12 +0,0 @@
-import std/[times, os, strutils, strbasics, strscans, sets, re, tables], parseopt
-
-proc getWeekNumber(date: DateTime): int =
- return int((date.monthDay - 1) / 7) + 1
-
-proc getWeekNumberFromEnd(date: DateTime): int =
- let daysInMonth = getDaysInMonth(date.month, date.year)
- let day = date.monthday
- return int((daysInMonth - day) / 7) + 1
-
-var d = now() - 21.days
-echo getWeekNumber(d)