import "pkg:/source/utils/Types.bs" function Init() m.top.font.size = 18 m.top.horizAlign = "right" m.top.translation = [1034, 34] m.top.width = 200 m.dateTime = CreateObject("roDateTime") Update() seconds = m.dateTime.GetSeconds() m.timer = CreateObject("roSGNode", "Timer") ' add 2 seconds delay between real clock time and the displayed time to in case of inaccuracy of the timer m.timer.duration = 60 - seconds + 2 m.timer.repeat = false m.timer.ObserveField("fire", FuncName(FirstUpdate)) m.timer.control = "start" end function function FirstUpdate() m.timer.control = "stop" m.timer.unobserveField("fire") m.timer.ObserveField("fire", FuncName(Update)) m.timer.duration = 60 m.timer.repeat = true m.timer.control = "start" Update() end function ' format time HH:MM AM/PM function Update() m.dateTime.Mark() m.dateTime.ToLocalTime() hours = m.dateTime.GetHours() minutes = m.dateTime.GetMinutes() if hours >= 12 ampm = "PM" else ampm = "AM" end if if hours > 12 hours -= 12 end if hoursStr = hours.ToStr("%02d") minutesStr = minutes.ToStr("%02d") m.top.text = hoursStr + ":" + minutesStr + " " + ampm end function function OnDispose() m.timer.control = "stop" m.timer.unobserveField("fire") end function