wmtools/fuzzytime.nim

93 lines
1.8 KiB
Nim
Raw Normal View History

2022-04-28 21:58:40 +02:00
import base
import std/[os,times]
2022-02-06 21:10:06 +01:00
const default_bg = lightblue
const default_fg = black
2022-02-06 21:10:06 +01:00
proc getHour(hr: int): string
proc getMinute(min: int): string
proc getFuzzyTime(): string =
2022-02-06 21:10:06 +01:00
let tm = now()
var hr = tm.hour()
let min = tm.minute()
var link = "past"
if min > 32 :
link = "to"
case hr:
of 23:
hr = 0
else:
hr = hr + 1
2022-02-06 21:10:06 +01:00
if min >= 58 or min <= 02:
return getHour(hr) & " " & getMinute(min)
2022-02-06 21:10:06 +01:00
else:
return getMinute(min) & " " & link & " " & getHour(hr)
2022-02-06 21:10:06 +01:00
proc getHour(hr: int): string =
2022-02-06 21:10:06 +01:00
case hr:
of 1, 13:
return "one"
of 2, 14:
return "two"
of 3, 15:
return "three"
of 4, 16:
return "four"
of 5, 17:
return "five"
of 6, 18:
return "six"
of 7, 19:
return "seven"
of 8, 20:
return "eight"
of 9, 21:
return "nine"
of 10, 22:
return "ten"
of 11, 23:
return "eleven"
of 0, 12, 24:
return "twelve"
else:
return "error"
proc getMinute(min: int): string =
2022-02-06 21:10:06 +01:00
case min:
of 58,59,0,1,2:
return "o'clock"
of 3,4,5,6,7,53,54,55,56,57:
return "five"
of 8,9,10,11,12,48,49,50,51,52:
return "ten"
of 13,14,15,16,17,43,44,45,46,47:
return "quarter"
of 18,19,20,21,22,38,39,40,41,42:
return "twenty"
of 23,24,25,26,27,33,34,35,36,37:
return "twenty-five"
of 28,29,30,31,32:
return "half"
else:
return "error"
2022-04-28 21:58:40 +02:00
proc getObject(time: string): Info =
var data = newInfo("Fuzzy Time")
data.full_text = time
data.selected_bg = default_bg
data.selected_fg = default_fg
#i3bar stuff
data.color = default_fg
data.border = default_fg
2022-02-06 21:10:06 +01:00
return data
proc main() =
let time = getFuzzyTime()
let data = getObject(time)
outputData(data)
2022-02-06 21:10:06 +01:00
if isMainModule:
main()