
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


import "os" for Process
import "timer" for Timer
import "/date" for Date
import "/fmt" for Fmt
 
var watches = ["First", "Middle", "Morning", "Forenoon", "Afternoon", "Dog", "First"]
 
var args = Process.arguments
if (args.count == 0) {
    System.print("Please enter current time in the format (24 hour clock): hh:mm:ss.")
    return
}
 
var now = Date.parse(args[0], Date.isoTime)
 
while (true) {
    var h = now.hour
    var m = now.minute
    var s = now.second
    if ((m == 0 || m == 30) && s == 0) {
        var bell = (m == 30) ? 1 : 0
        var bells = (h*2 + bell) % 8
        var watch = (h/4).floor + 1
        if (bells == 0) {
            bells = 8
            watch = watch - 1
        }
        var sound = "\a" * bells
        var pl = (bells != 1) ? "s" : "" 
        var w = watches[watch] + " watch"
        if (watch == 5) {
            if (bells < 5) {
                w = "First " + w
            } else {
                w = "Last " + w
            }
        }
        Fmt.lprint("$s$02d:$02d = $d bell$s : $s", [sound, h, m, bells, pl, w])
    }
    Timer.sleep(1000)
    now = now.addSeconds(1)
}