streams/Code/Widget/Clock.php

59 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2022-10-23 21:18:44 +00:00
class Clock implements WidgetInterface
2021-12-02 23:02:31 +00:00
{
2022-10-23 21:18:44 +00:00
public function widget(array $arr): string
2021-12-02 23:02:31 +00:00
{
$miltime = ((isset($arr['military']) && $arr['military']) ? intval($arr['military']) : false);
2022-09-04 05:51:24 +00:00
return <<< EOT
<div class="widget">
<h3 class="clockface"></h3>
<script>
2022-09-04 05:51:24 +00:00
let timerID = null
let timerRunning = false
function stopclock(){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function startclock(){
stopclock()
showtime()
}
2019-09-11 02:31:08 +00:00
function showtime() {
2022-09-04 05:51:24 +00:00
let now = new Date()
let hours = now.getHours()
let minutes = now.getMinutes()
let seconds = now.getSeconds()
let military = $miltime
let timeValue = ""
if(military)
timeValue = hours
else
timeValue = ((hours > 12) ? hours - 12 : hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
// timeValue += ((seconds < 10) ? ":0" : ":") + seconds
if(! military)
timeValue += (hours >= 12) ? " P.M." : " A.M."
$('.clockface').html(timeValue)
timerID = setTimeout("showtime()",1000)
timerRunning = true
}
$(document).ready(function() {
startclock();
});
</script>
</div>
EOT;
2021-12-02 23:02:31 +00:00
}
}