Improve sleep-nag
This commit is contained in:
parent
08eb825fb8
commit
b1c9b70528
1 changed files with 14 additions and 7 deletions
|
@ -6,18 +6,25 @@ let
|
||||||
name = "sleep-nag";
|
name = "sleep-nag";
|
||||||
imports = [
|
imports = [
|
||||||
"Data.Time.LocalTime"
|
"Data.Time.LocalTime"
|
||||||
|
"Data.Time.Format"
|
||||||
|
"Data.Time.Clock"
|
||||||
"Control.Concurrent"
|
"Control.Concurrent"
|
||||||
"Data.Functor"
|
"Data.Functor"
|
||||||
];
|
];
|
||||||
bins = [ eventd ];
|
bins = [ eventd ];
|
||||||
} ''
|
} ''
|
||||||
main = go
|
main = forever $ do
|
||||||
where
|
time <- getZonedTime
|
||||||
go = do
|
let tod = localTimeOfDay . zonedTimeToLocalTime$ time
|
||||||
tod <- getZonedTime <&> localTimeOfDay . zonedTimeToLocalTime
|
hour = todHour tod
|
||||||
when (todHour tod < 6 || todHour tod >= 23) $ eventc "notification" "kassandra" "-d" ([i|title='Es ist #{todHour tod}:#{todMin tod} Uhr: Zeit ins Bett zu gehen!'|]::String) "-d" "message='Du kannst das hier auch morgen tun!'"
|
night = (hour < 6 || hour >= 23)
|
||||||
threadDelay 600000000
|
diff = diffUTCTime (zonedTimeToUTC time{zonedTimeToLocalTime = (zonedTimeToLocalTime time){localTimeOfDay = TimeOfDay 23 0 0}}) (zonedTimeToUTC time)
|
||||||
go
|
delay = toRational diff
|
||||||
|
if night then (do
|
||||||
|
eventc "notification" "kassandra" "-d" ([i|title='Es ist #{formatTime defaultTimeLocale "%H:%M" time} Uhr: Zeit ins Bett zu gehen!'|]::String) "-d" "message='Du kannst das hier auch morgen tun!'"
|
||||||
|
threadDelay 600000000)
|
||||||
|
else
|
||||||
|
threadDelay (floor $ delay * 1000000)
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue