3 Commits
0.3.0 ... 0.5.0

Author SHA1 Message Date
3cf76ef382 Add --this-week, --last-week options 2016-10-21 15:42:48 -05:00
e0618f6520 Add some alternate time formats. 2016-10-13 06:31:51 -05:00
915c5b1ea1 Added --today flag. 2016-10-12 16:30:32 -05:00
3 changed files with 32 additions and 9 deletions

33
ptk.nim
View File

@ -23,7 +23,8 @@ const ISO_TIME_FORMAT = "yyyy:MM:dd'T'HH:mm:ss"
const TIME_FORMATS = @[
"H:mm", "HH:mm", "H:mm:ss", "HH:mm:ss",
"yyyy:MM:dd'T'HH:mm:ss", "yyyy:MM:dd'T'HH:mm"]
"yyyy:MM:dd'T'HH:mm:ss", "yyyy:MM:dd'T'HH:mm",
"yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm"]
#proc `$`*(mark: Mark): string =
#return (($mark.uuid)[
@ -99,10 +100,11 @@ proc writeMarks(timeline: Timeline, indices: seq[int], includeNotes = false): vo
var idxs = indices.sorted(
proc(a, b: int): int = cmp(marks[a].time, marks[b].time))
let largestInterval = now - marks[idxs.first].time
let timeFormat =
if now - marks[idxs.first].time > 1.years: "yyyy-MM-dd HH:mm"
elif now - marks[idxs.first].time > 7.days: "MMM dd HH:mm"
elif now - marks[idxs.first].time > 1.days: "ddd HH:mm"
if largestInterval > 1.years: "yyyy-MM-dd HH:mm"
elif largestInterval > 7.days: "MMM dd HH:mm"
elif largestInterval > 1.days: "ddd HH:mm"
else: "HH:mm"
var toWrite: seq[WriteData] = @[]
@ -254,6 +256,24 @@ proc filterMarkIndices(timeline: Timeline, args: Table[string, Value]): seq[int]
"invalid value for --before: " & getCurrentExceptionMsg())
result = result.filterIt(marks[it].time < endTime)
if args["--today"]:
let now = getLocalTime(getTime())
let b = now.startOfDay
let e = b + 1.days
result = result.filterIt(marks[it].time >= b and marks[it].time < e)
if args["--this-week"]:
let now = getLocalTime(getTime())
let b = now.startOfWeek(dSun)
let e = b + 7.days
result = result.filterIt(marks[it].time >= b and marks[it].time < e)
if args["--last-week"]:
let now = getLocalTime(getTime())
let e = now.startOfWeek(dSun)
let b = e - 7.days
result = result.filterIt(marks[it].time >= b and marks[it].time < e)
if args["--tags"]:
let tags = (args["--tags"] ?: "").split({',', ';'})
result = result.filter(proc (i: int): bool =
@ -300,6 +320,9 @@ Options:
-m --matching <pattern> Restric the selection to marks matching <pattern>.
-n --notes <notes> For add and amend, set the notes for a time mark.
-t --time <time> For add and amend, use this time instead of the current time.
-T --today Restrict the selection to marks during today.
-w --this-week Restrict the selection to marks during this week.
-W --last-week Restrict the selection to marks during the last week.
-v --verbose Include notes in timeline entry output.
"""
@ -309,7 +332,7 @@ Options:
let now = getLocalTime(getTime())
# Parse arguments
let args = docopt(doc, version = "ptk 0.3.0")
let args = docopt(doc, version = "ptk 0.5.0")
if args["--echo-args"]: echo $args

View File

@ -1,6 +1,6 @@
# Package
version = "0.3.0"
version = "0.5.0"
author = "Jonathan Bernard"
description = "Personal Time Keeper"
license = "MIT"
@ -8,5 +8,5 @@ bin = @["ptk"]
# Dependencies
requires @["nim >= 0.15.0", "docopt >= 0.6.4", "uuids", "langutils", "tempfile", "timeutils"]
requires @["nim >= 0.15.0", "docopt >= 0.6.4", "uuids", "langutils", "tempfile", "timeutils >= 0.2.0"]

View File

@ -1,3 +1,3 @@
template first*(s: seq): auto = s[0]
template first*(a: openarray): auto = a[0]
template last*(s: seq): auto = s[len(s)-1]
template last*(a: openarray): auto = a[len(a)-1]