diff --git a/CHANGELOG.md b/CHANGELOG.md index 83c171c3..c9cc3b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- A clock to show the time + ## [0.23.6] - 2024-05-23 ### Added diff --git a/playlet-lib/src/components/Clock/Clock.bs b/playlet-lib/src/components/Clock/Clock.bs new file mode 100644 index 00000000..cf923c70 --- /dev/null +++ b/playlet-lib/src/components/Clock/Clock.bs @@ -0,0 +1,62 @@ +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 = hours - 12 + end if + + hoursStr = hours.ToStr() + minutesStr = minutes.ToStr() + + if hours < 10 + hoursStr = "0" + hoursStr + end if + + if minutes < 10 + minutesStr = "0" + minutesStr + end if + + m.top.text = hoursStr + ":" + minutesStr + " " + ampm +end function diff --git a/playlet-lib/src/components/Clock/Clock.xml b/playlet-lib/src/components/Clock/Clock.xml new file mode 100644 index 00000000..ac81c668 --- /dev/null +++ b/playlet-lib/src/components/Clock/Clock.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/playlet-lib/src/components/MainScene.transpiled.xml b/playlet-lib/src/components/MainScene.transpiled.xml index b39b0314..61b28a11 100644 --- a/playlet-lib/src/components/MainScene.transpiled.xml +++ b/playlet-lib/src/components/MainScene.transpiled.xml @@ -35,6 +35,7 @@ + diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml index 30b3af31..3b383ccf 100644 --- a/playlet-lib/src/components/MainScene.xml +++ b/playlet-lib/src/components/MainScene.xml @@ -52,6 +52,7 @@ +