diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/then.nim | 55 |
1 files changed, 34 insertions, 21 deletions
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) = |
