Nautical bell: Difference between revisions

Content added Content deleted
Line 809: Line 809:
en.wikipedia.org/wiki/Ship%27s_bell#Simpler_system.
en.wikipedia.org/wiki/Ship%27s_bell#Simpler_system.
Note the traditional time zone was determined by local sun position
Note the traditional time zone was determined by local sun position
and so should be close to local time rather than GMT.
and so should be local time without daylight savings time.
"""
"""
function nauticalbells(dt::DateTime)
function nauticalbells(dt::DateTime)
Line 828: Line 828:


function nauticalbelltask()
function nauticalbelltask()
untilnextbell = ceil(now(), Dates.Minute(30)) - now()
# parse for milliseconds til next hour, start timer with that delay
delay = untilnextbell.value / 1000
untilnexthour = now() - DateTime(match(r"^([^:]+)", string(now())).captures[1])
delay = untilnexthour.value / 1000
println("Nautical bell task starting -- next bell in $delay seconds.")
println("Nautical bell task starting -- next bell in $delay seconds.")
# The timer wakes its task every half hour. May drift very slightly so restart yearly.
# The timer wakes its task every half hour. May drift very slightly so restart yearly.
Line 837: Line 836:
wait(timer)
wait(timer)
gong = nauticalbells(now())
gong = nauticalbells(now())
@async(println("Nautical bell gong strikes $gong!")) # or do hardware dependent audible tones
@async(println("Nautical bell gong strikes $gong!")) # or do audible tones
end
end
end
end