
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


$ include "seed7_05.s7i";
  include "time.s7i";
  include "duration.s7i";
  include "keybd.s7i";
 
const array string: watch is [] ("Middle", "Morning", "Forenoon", "Afternoon", "Dog", "First");
const array string: bells is [] ("One Bell", "Two Bells", "Three Bells", "Four Bells", "Five Bells", "Six Bells", "Seven Bells", "Eight Bells");
 
const func time: truncToHalfHour (in time: aTime) is func
  result
    var time: truncatedTime is time.value;
  begin
    truncatedTime := aTime;
    truncatedTime.minute := aTime.minute div 30 * 30;
    truncatedTime.second := 0;
    truncatedTime.micro_second := 0;
  end func;
 
const proc: main is func
  local
    var time: nextTime is time.value;
    var time: midnight is time.value;
    var integer: minutes is 0;
  begin
    writeln;
    nextTime := truncToHalfHour(time(NOW));
    midnight := truncToDay(nextTime);
    while TRUE do
      nextTime +:= 30 . MINUTES;
      await(nextTime);
      minutes := toMinutes(nextTime - midnight);
      writeln(str_hh_mm(nextTime, ":") <& " - " <&
              watch[succ((minutes - 30) mdiv 240 mod 6)] <& " watch - " <&
              bells[succ((minutes - 30) mdiv 30 mod 8)] <& " Gone.");
      flush(OUT);
    end while;
  end func;