forked from predixdesignsystem/px-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-vis-behavior-datetime.html
103 lines (94 loc) · 2.8 KB
/
px-vis-behavior-datetime.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<link rel="import" href="../px-datetime-common/px-datetime-imports.html" />
<script>
var PxVisBehaviorTime = PxVisBehaviorTime || {};
/*
Name:
PxVisBehaviorTime.datetime
Description:
Polymer behavior that provides the momentjs, moment-timezone, and a variety of datetime formating options and methods to px-vis and associated sub components.
Docs to Momentjs: http://momentjs.com/docs/
Docs to Moment-Timezone: http://momentjs.com/timezone/
Dependencies:
- momentjs
- moment-timezone
@polymerBehavior PxVisBehaviorTime.datetime
*/
PxVisBehaviorTime.datetime = {
properties: {
/**
* Defines the format for the first datetime string. The first datetime is shown in normal font weight.
*
* Default is the first datetime string is TIME presented as "15:00:00 +0000"
*
* For valid string formats, see: http://momentjs.com/docs/#/displaying/
*
*/
firstDateTimeFormat:{
type:String,
value: 'HH:mm:ss ZZ'
},
/**
* Defines the format for the second datetime string. The second datetime is shown in bold font weight.
*
* Default is the second datetime string is DATE presented as "12 Feb 2016"
*
* For valid string formats, see: http://momentjs.com/docs/#/displaying/
*
* @property secondDateTimeFormat
* @type string
* @default DD MMM YYYY
*/
secondDateTimeFormat:{
type:String,
value:'DD MMM YYYY'
},
/**
* Defines a separator character between the two datetime strings.
*
* @property separator
* @type string
* @default |
*/
separator:{
type:String,
value:'|'
},
/**
* Sets what timezone the event time should display in.
*
* Timezone defaults to UTC time. If a valid timezone is specified, then times include daylight savings time if applicable.
*
* For a list of valid timezones, see: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
*
* For more details on timezones, see: http://momentjs.com/timezone/
*
* @property timezone
* @type String
* @default utc
*/
timezone:{
type:String,
value:"utc"
},
},
/**
* Method that takes a datetime string, timezone string, and a formatting string. Returns a formated datetime string.
*
* @method formatTimestamp
* @param {datetime}
* @param {timezone}
* @param {format}
* @return {formatedDatetimeString}
*/
formatTimestamp: function(datetime,timezone,format){
if(timezone.toLowerCase() !== 'utc'){
if(Px.moment.tz.zone(timezone)){
return Px.moment.tz(datetime, timezone).format(format);
} else {
console.warn("Invalid timezone specified; defaulting to UTC");
}
}
return Px.moment.utc(datetime).format(format);
}
}
</script>