
Task
Write a small program that emulates a nautical bell producing a ringing bell pattern at certain times throughout the day.

The bell timing should be in accordance with Greenwich Mean Time, unless locale dictates otherwise.

It is permissible for the program to daemonize, or to slave off a scheduler, and it is permissible to use alternative notification methods (such as producing a written notice "Two Bells Gone"), if these are more usual for the system type.



Related task

 Sleep


with javascript_semantics
constant watches = {"First","Middle","Morning","Forenoon","Afternoon","First dog","Last dog","First"},
         watch_ends = {"00:00", "04:00", "08:00", "12:00", "16:00", "18:00", "20:00", "23:59"},
         bells = {"One","Two","Three","Four","Five","Six","Seven","Eight"},
         ding = "ding!"
 
procedure nb(integer h,m)
    integer bell = mod(floor((h*60+m)/30),8)
    if bell==0 then bell = 8 end if
    string hm = sprintf("%02d:%02d",{h,m})
    integer watch=1
    while hm>watch_ends[watch] do watch += 1 end while
    string plural = iff(bell==1?" ":"s")
    string dings = ding
    for i=2 to bell do dings &= iff(mod(i,2)?" ":"")&ding end for
    printf(1,"%s %9s watch %5s bell%s  %s\n",
             {hm,watches[watch],bells[bell],plural,dings})
end procedure 
 
procedure simulate1day()
    for h=0 to 23 do
      for m=0 to 30 by 30 do
        nb(h,m)
      end for
    end for
    nb(0,0) -- (again)
end procedure
 
simulate1day()
 
if platform()!=JS then -- (no sleep() function)
    while 1 do
        sequence d = date(DT_GMT)
        integer m = d[DT_SECOND] + mod(d[DT_MINUTE],30)*60
        if m=0 then
            nb(d[DT_HOUR],d[DT_MINUTE])
        end if
        sleep(30*60-m)
    end while
end if
