wmtools/i3bar_fuzzytime.nim

91 lines
1.7 KiB
Nim
Raw Normal View History

2022-02-06 21:10:06 +01:00
import std/times
import std/os
import i3bar_base
proc get_hour(hr: int): string
proc get_minute(min: int): string
proc get_fuzzytime(): string =
let tm = now()
var hr = tm.hour()
let min = tm.minute()
var link = "past"
if min > 32 :
link = "to"
hr = hr + 1
if min >= 58 or min <= 02:
return get_hour(hr) & " " & get_minute(min)
else:
return get_minute(min) & " " & link & " " & get_hour(hr)
proc get_hour(hr: int): string =
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 get_minute(min: int): string =
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"
proc getObject(time: string): i3barData =
let data = i3barData(
full_text: time,
color: foreground,
border: lightblue,
)
return data
proc main() =
2022-02-12 16:19:43 +01:00
var last_time = ""
2022-02-06 21:10:06 +01:00
while true:
let time = get_fuzzytime()
2022-02-12 16:19:43 +01:00
if time != last_time:
let data = getObject(time)
outputJSON(data)
last_time = time
2022-02-06 21:10:06 +01:00
2022-02-12 16:19:43 +01:00
sleep(2000)
2022-02-06 21:10:06 +01:00
main()