Skip to content

Instantly share code, notes, and snippets.

@zyth0s
Created August 3, 2020 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyth0s/4e167d0242680ea9866c0db0e2ba4f22 to your computer and use it in GitHub Desktop.
Save zyth0s/4e167d0242680ea9866c0db0e2ba4f22 to your computer and use it in GitHub Desktop.
Coffee alarm at the office.
using Dates: DateTime, issaturday, issunday, now, tonext, Hour, hour, Minute
isweekend(dt::DateTime) = issaturday(dt) || issunday(dt)
# Step from now on by 1 hour lapses until the next coffee time is found.
next_coffee_t = tonext(floor(now(),Hour), step=Hour(1)) do dt
!isweekend(dt) && # We do not work at the office on weekends.
(hour(dt) == 13 || # After lunch, or
hour(dt) == 17) # in the evening.
end
# Exactly how much time is left [milliseconds].
t_left = next_coffee_t - now()
# Notification:
if t_left < Minute(10)
println("Let's prepare some ☕!")
else
hours_left = round(t_left, Hour)
mins_left = round(t_left, Minute) - Minute(hours_left)
if mins_left < Minute(0)
hours_left -= Hour(1)
mins_left += Minute(60)
end
println(hours_left, " ", mins_left , " left for ☕.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment