Skip to content

Commit

Permalink
Merge pull request #74 from Dambakk/clock-with-timezone
Browse files Browse the repository at this point in the history
Add timezone to clock widget
  • Loading branch information
dnsmichi committed Oct 8, 2019
2 parents ed4bd04 + 1e344ed commit 99d1d00
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,23 @@ Example:
</li>
```


#### Clock

Show the time in a specific timezone. Enter the timezone as found in `/usr/share/zoneinfo` on Linux.

Example:

```html
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-view="Clock" data-title="UTC" data-timezone="UTC"></div>
</li>
<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
<div data-view="Clock" data-title="New York" data-timezone="America/New_York"></div>
</li>
```


### References

https://www.icinga.com/2016/01/28/awesome-dashing-dashboards-with-icinga-2/
Expand Down
29 changes: 19 additions & 10 deletions widgets/clock/clock.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
@set('time', time)
@set('date', date)
@set('title', @get('title'))
5 changes: 3 additions & 2 deletions widgets/clock/clock.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<h1 data-bind="date"></h1>
<h2 data-bind="time"></h2>
<h1 data-bind="title"></h1>
<h3 data-bind="date"></h3>
<h2 data-bind="time"></h2>

0 comments on commit 99d1d00

Please sign in to comment.