-
Notifications
You must be signed in to change notification settings - Fork 2
/
time-display.html
65 lines (50 loc) · 1.48 KB
/
time-display.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="lib-fecha.html">
<!--
`time-display`
Display time in human readable format
@demo demo/index.html
-->
<dom-module id="time-display">
<template>
<time datetime$="[[ISOString]]">[[value]]</time>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'time-display',
properties: {
/* datetime in ISO 8601 format */
datetime: {
type: String,
value: 'now'
},
/* datetime converted to Javascript Date object */
_datetime: Date,
/* ISO 8601 formatted datetime */
ISOString: String,
/* formatted datetime */
value: String,
/* display format string to use */
format: {
type: String,
value: 'default'
}
},
observers: [
'_update(datetime, format)'
],
_update: function(datetime, format) {
this._datetime = (datetime === 'now') ? this._nowUTC() : new Date(datetime);
this.ISOString = this._datetime.toISOString();
this.value = fecha.format(this._datetime, format);
},
_nowUTC: function() {
var now = new Date();
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()));
}
});
})();
</script>
</dom-module>