2015-12-01 02:11:04 +08:00
|
|
|
/*
|
2016-01-07 12:06:39 +08:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-12-01 02:11:04 +08:00
|
|
|
|
|
|
|
Licensed 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
|
|
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
formatDate: function(date) {
|
|
|
|
// date.toLocaleTimeString is completely system dependent.
|
|
|
|
// just go 24h for now
|
|
|
|
function pad(n) {
|
|
|
|
return (n < 10 ? '0' : '') + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
var now = new Date();
|
|
|
|
if (date.toDateString() === now.toDateString()) {
|
|
|
|
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
|
|
|
}
|
|
|
|
else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
|
|
|
|
return days[date.getDay()] + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
|
|
|
}
|
2016-03-19 10:37:18 +08:00
|
|
|
else /* if (now.getFullYear() === date.getFullYear()) */ {
|
2016-01-03 08:40:05 +08:00
|
|
|
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
2015-12-01 02:11:04 +08:00
|
|
|
}
|
2016-03-19 10:37:18 +08:00
|
|
|
/*
|
2015-12-01 02:11:04 +08:00
|
|
|
else {
|
2016-01-03 08:40:05 +08:00
|
|
|
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
2015-12-01 02:11:04 +08:00
|
|
|
}
|
2016-03-19 10:37:18 +08:00
|
|
|
*/
|
2016-08-16 22:01:01 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
formatTime: function(date) {
|
|
|
|
//return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
|
|
|
return ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2);
|
2015-12-01 02:11:04 +08:00
|
|
|
}
|
2017-01-20 22:22:27 +08:00
|
|
|
};
|
2015-12-01 02:11:04 +08:00
|
|
|
|