| 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 |
235
1
1
1
1
140
1
1
1
49
25
74
27
47
47
47
47
3
44
44
2
42
44
50
50
50
50
1
49
22
22
27
27
27
77
1
76
76
76
76
10
66
66
66
66
66
66
66
66
66
66
66
66
66
66
66
66
66
66
66
37
37
37
37
37
37
2
66
235
235
59
59
235
3
3
2
1
2
3
| 'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { Eif (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
;require.register("utils/date/date", function (exports, require, module) {
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var validator = require('utils/validator');
var App = require('app');
module.exports = {
/**
* List of monthes short names
* @type {string[]}
*/
dateMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
/**
* List of days short names
* @type {string[]}
*/
dateDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
/**
* Add leading zero
*
* @param {string} time
* @returns {string}
* @method dateFormatZeroFirst
*/
dateFormatZeroFirst: function dateFormatZeroFirst(time) {
return (time < 10 ? '0' : '') + time;
},
/**
* Convert timestamp to date-string
* default format - 'DAY_OF_THE_WEEK, MONTH DAY, YEAR HOURS:MINUTES'
*
* @param {number} timestamp
* @param {bool} format
* @return {*} date
* @method dateFormat
*/
dateFormat: function dateFormat(timestamp, format) {
Iif (!validator.isValidInt(timestamp)) {
return timestamp;
}
format = format || 'ddd, MMM DD, YYYY HH:mm';
return moment(new Date(timestamp)).format(format);
},
/**
* Convert timestamp to date-string 'DAY_OF_THE_WEEK MONTH DAY YEAR'
*
* @param {string} timestamp
* @return {string}
* @method dateFormatShort
*/
dateFormatShort: function dateFormatShort(timestamp) {
if (!validator.isValidInt(timestamp)) {
return timestamp;
}
var format = 'ddd MMM DD YYYY';
var date = moment(new Date(timestamp)).format(format);
var today = moment(new Date()).format(format);
if (date === today) {
return 'Today ' + new Date(timestamp).toLocaleTimeString();
}
return date;
},
startTime: function startTime(startTimestamp) {
return this._time(startTimestamp, 'Not started');
},
endTime: function endTime(endTimestamp) {
return this._time(endTimestamp, 'Not finished');
},
/**
* Convert timestamp to 'DAY_OF_THE_WEEK, MONTH DAY, YEAR HOURS:MINUTES', except for the case: year equals 1969
*
* @param {string} timestamp
* @param {string} msg
* @return {string} TimeSummary
*/
_time: function _time(timestamp, msg) {
if (!validator.isValidInt(timestamp)) {
return '';
}
var startDate = new Date(timestamp);
var months = this.dateMonths;
var days = this.dateDays;
if (startDate.getFullYear() === 1969 || timestamp < 1) {
return msg;
}
var startTimeSummary = '';
if (new Date(timestamp).setHours(0, 0, 0, 0) === new Date().setHours(0, 0, 0, 0)) {
//today
startTimeSummary = 'Today ' + this.dateFormatZeroFirst(startDate.getHours()) + ':' + this.dateFormatZeroFirst(startDate.getMinutes());
} else {
startTimeSummary = days[startDate.getDay()] + ' ' + months[startDate.getMonth()] + ' ' + this.dateFormatZeroFirst(startDate.getDate()) + ' ' + startDate.getFullYear() + ' ' + this.dateFormatZeroFirst(startDate.getHours()) + ':' + this.dateFormatZeroFirst(startDate.getMinutes());
}
return startTimeSummary;
},
/**
* Provides the duration between the given start and end timestamp. If start time
* not valid, duration will be ''. If end time is not valid, duration will
* be till now, showing 'Lasted for xxx secs'.
*
* @param {string} startTimestamp
* @param {string} endTimestamp
* @return {string} durationSummary
* @method durationSummary
*/
durationSummary: function durationSummary(startTimestamp, endTimestamp) {
// generate duration
var durationSummary = '';
var startDate = new Date(startTimestamp);
var endDate = new Date(endTimestamp);
if (startDate.getFullYear() == 1969 || startTimestamp < 1) {
// not started
return Em.I18n.t('common.na');
}
if (endDate.getFullYear() != 1969 && endTimestamp > 0) {
durationSummary = '' + this.timingFormat(endTimestamp - startTimestamp);
return durationSummary.contains('-') ? Em.I18n.t('common.na') : durationSummary; //lasted for xx secs
} else {
// still running, duration till now
var time = App.dateTimeWithTimeZone() - startTimestamp < 0 ? 0 : App.dateTimeWithTimeZone() - startTimestamp;
durationSummary = '' + this.timingFormat(time);
}
return durationSummary.contains('-') ? Em.I18n.t('common.na') : durationSummary;
},
/**
* Format: "{#days}d {#hours}h {#minutes}m {#seconds}s"
* Example: "1d 3h 46m"
*
* Display optimization rules:
* if time more than a day then hide time lower than minute
* if time more than a minute and less than an hour then hide time lower than second
* @param {number|string} time
* @return {string|null} formatted date
* @method timingFormat
*/
timingFormat: function timingFormat(time) {
if (Em.isNone(time)) {
return null;
}
time = parseInt(time);
var fullTime = time;
var duration = '';
if (time === 0) {
return '0s';
}
var oneSecMs = 1000;
var oneMinMs = 60000;
var oneHourMs = 3600000;
var oneDayMs = 86400000;
var days = void 0,
hours = void 0,
minutes = void 0,
seconds = void 0;
var _extractTimeUnit = this.extractTimeUnit(time, oneDayMs, 'd');
var _extractTimeUnit2 = _slicedToArray(_extractTimeUnit, 2);
days = _extractTimeUnit2[0];
time = _extractTimeUnit2[1];
var _extractTimeUnit3 = this.extractTimeUnit(time, oneHourMs, 'h');
var _extractTimeUnit4 = _slicedToArray(_extractTimeUnit3, 2);
hours = _extractTimeUnit4[0];
time = _extractTimeUnit4[1];
var _extractTimeUnit5 = this.extractTimeUnit(time, oneMinMs, 'm');
var _extractTimeUnit6 = _slicedToArray(_extractTimeUnit5, 2);
minutes = _extractTimeUnit6[0];
time = _extractTimeUnit6[1];
duration += days + hours + minutes;
if (fullTime < oneDayMs) {
var _extractTimeUnit7 = this.extractTimeUnit(time, oneSecMs, 's');
var _extractTimeUnit8 = _slicedToArray(_extractTimeUnit7, 2);
seconds = _extractTimeUnit8[0];
time = _extractTimeUnit8[1];
duration += seconds;
if (fullTime < oneSecMs) {
duration += '1s';
}
}
return duration.trim();
},
extractTimeUnit: function extractTimeUnit(time, unitValue, unitSuffix) {
var result = '';
if (time >= unitValue) {
result = Math.floor(time / unitValue) + (unitSuffix + ' ');
time -= Math.floor(time / unitValue) * unitValue;
}
return [result, time];
},
/**
* Provides the duration between the given start and end time. If start time
* is not given, duration will be 0. If end time is not given, duration will
* be till now.
*
* @param {Number} startTime Start time from epoch
* @param {Number} endTime End time from epoch
* @return {Number} duration
* @method duration
*/
duration: function duration(startTime, endTime) {
var duration = 0;
if (startTime && startTime > 0) {
if (!endTime || endTime < 1) {
endTime = App.dateTime();
}
duration = endTime - startTime;
}
return duration;
}
};
}); |