aboutsummaryrefslogtreecommitdiff
path: root/challenge-028/athanasius/perl6/ch-2.p6
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-028/athanasius/perl6/ch-2.p6')
-rw-r--r--challenge-028/athanasius/perl6/ch-2.p657
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-028/athanasius/perl6/ch-2.p6 b/challenge-028/athanasius/perl6/ch-2.p6
new file mode 100644
index 0000000000..81ad6ea713
--- /dev/null
+++ b/challenge-028/athanasius/perl6/ch-2.p6
@@ -0,0 +1,57 @@
+use v6;
+
+################################################################################
+=begin comment
+
+Perl Weekly Challenge 028
+=========================
+
+Task #2
+-------
+Write a script to display *Digital Clock*. Feel free to be as creative as you
+can when displaying digits. We expect bare minimum something like *"14:10:11"*.
+
+=end comment
+################################################################################
+
+#--------------------------------------#
+# Copyright © 2019 PerlMonk Athanasius #
+#--------------------------------------#
+
+my UInt constant $TIMEZONE = +10; # Difference in hours from UTC/GMT
+my UInt constant $SECS-PER-HOUR = 60 * 60;
+my UInt constant $TZ-OFFSET = $TIMEZONE * $SECS-PER-HOUR;
+
+BEGIN say '';
+
+#===============================================================================
+sub MAIN()
+#===============================================================================
+{
+ my DateTime $dt = DateTime.now(timezone => $TZ-OFFSET);
+ my UInt $hour = $dt.hour;
+ my UInt $min = $dt.minute;
+ my UInt $sec = $dt.whole-second;
+
+ "%02d:%02d:%02d\r".printf($hour, $min, $sec);
+
+ while 1
+ {
+ sleep 1;
+
+ if ++$sec >= 60
+ {
+ $sec = 0;
+
+ if ++$min == 60
+ {
+ $min = 0;
+ $hour = 0 if ++$hour == 24;
+ }
+ }
+
+ "%02d:%02d:%02d\r".printf($hour, $min, $sec);
+ }
+}
+
+################################################################################