diff --git a/README.md b/README.md index 96bb001..047f75a 100644 --- a/README.md +++ b/README.md @@ -643,6 +643,23 @@ Example: ``` + +#### Clock + +Show the time in a specific timezone. Enter the timezone as found in `/usr/share/zoneinfo` on Linux. + +Example: + +```html +
  • +
    +
  • +
  • +
    +
  • +``` + + ### References https://www.icinga.com/2016/01/28/awesome-dashing-dashboards-with-icinga-2/ diff --git a/widgets/clock/clock.coffee b/widgets/clock/clock.coffee index cd6b116..c8b438e 100644 --- a/widgets/clock/clock.coffee +++ b/widgets/clock/clock.coffee @@ -4,15 +4,24 @@ class Dashing.Clock extends Dashing.Widget setInterval(@startTime, 500) startTime: => - today = new Date() + zone = @get('timezone') + optionsDate = { + timeZone: zone, + weekday: 'short', + year: 'numeric', + month: 'short', + day: 'numeric' + }; + optionsTime = { + timeZone: zone, + hour: '2-digit', + minute: '2-digit', + hour12: false + }; - h = today.getHours() - m = today.getMinutes() - s = today.getSeconds() - m = @formatTime(m) - s = @formatTime(s) - @set('time', h + ":" + m + ":" + s) - @set('date', today.toDateString()) + date = new Date().toLocaleDateString('en-US', optionsDate); + time = new Date().toLocaleTimeString('en-US', optionsTime); - formatTime: (i) -> - if i < 10 then "0" + i else i \ No newline at end of file + @set('time', time) + @set('date', date) + @set('title', @get('title')) diff --git a/widgets/clock/clock.html b/widgets/clock/clock.html index 06759d4..87a5f67 100644 --- a/widgets/clock/clock.html +++ b/widgets/clock/clock.html @@ -1,2 +1,3 @@ -

    -

    \ No newline at end of file +

    +

    +