Implement fading alarm
This commit is contained in:
parent
3e33e489aa
commit
6b73e32cda
3 changed files with 26 additions and 7 deletions
|
|
@ -6,11 +6,21 @@ type PartOfDay =
|
|||
| Day
|
||||
| Night
|
||||
|
||||
let private startOfDay = TimeSpan.FromHours 6
|
||||
let private endOfDay = TimeSpan.FromHours 20.5
|
||||
|
||||
let getPartOfDay (dateTime: DateTime) =
|
||||
match dateTime with
|
||||
| _ when
|
||||
dateTime.TimeOfDay >= TimeSpan.FromHours 6
|
||||
&& dateTime.TimeOfDay < TimeSpan.FromHours 20.5
|
||||
->
|
||||
Day
|
||||
| _ when dateTime.TimeOfDay >= startOfDay && dateTime.TimeOfDay < endOfDay -> Day
|
||||
| _ -> Night
|
||||
|
||||
let getAlarmWeight (dateTime: DateTime) =
|
||||
let currentTime = dateTime.TimeOfDay
|
||||
let alarmEnd = startOfDay + TimeSpan(0, 15, 0)
|
||||
let totalSeconds = (alarmEnd - startOfDay).TotalSeconds
|
||||
|
||||
if startOfDay <= currentTime && currentTime <= alarmEnd then
|
||||
let elapsedSeconds = (currentTime - startOfDay).TotalSeconds
|
||||
elapsedSeconds / totalSeconds
|
||||
else
|
||||
1.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue