This commit is contained in:
parent
46bb29a3af
commit
d419c42a4f
73 changed files with 4660 additions and 639 deletions
|
@ -15,9 +15,36 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
'use strict';
|
||||
import _t from 'counterpart-riot';
|
||||
|
||||
var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
function getDaysArray() {
|
||||
var days = [];
|
||||
days.push(_t('Sun'));
|
||||
days.push(_t('Mon'));
|
||||
days.push(_t('Tue'));
|
||||
days.push(_t('Wed'));
|
||||
days.push(_t('Thu'));
|
||||
days.push(_t('Fri'));
|
||||
days.push(_t('Sat'));
|
||||
return days;
|
||||
}
|
||||
|
||||
function getMonthsArray() {
|
||||
var months = [];
|
||||
months.push(_t('Jan'));
|
||||
months.push(_t('Feb'));
|
||||
months.push(_t('Mar'));
|
||||
months.push(_t('Apr'));
|
||||
months.push(_t('May'));
|
||||
months.push(_t('Jun'));
|
||||
months.push(_t('Jul'));
|
||||
months.push(_t('Aug'));
|
||||
months.push(_t('Sep'));
|
||||
months.push(_t('Oct'));
|
||||
months.push(_t('Nov'));
|
||||
months.push(_t('Dec'));
|
||||
return months;
|
||||
}
|
||||
|
||||
function pad(n) {
|
||||
return (n < 10 ? '0' : '') + n;
|
||||
|
@ -27,16 +54,22 @@ module.exports = {
|
|||
formatDate: function(date) {
|
||||
// date.toLocaleTimeString is completely system dependent.
|
||||
// just go 24h for now
|
||||
const days = getDaysArray();
|
||||
const months = getMonthsArray();
|
||||
|
||||
// TODO: use standard date localize function provided in counterpart
|
||||
var hoursAndMinutes = pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
var now = new Date();
|
||||
if (date.toDateString() === now.toDateString()) {
|
||||
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
return hoursAndMinutes;
|
||||
}
|
||||
else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
|
||||
return days[date.getDay()] + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
// TODO: use standard date localize function provided in counterpart
|
||||
return _t('%(weekDayName)s %(time)s', {weekDayName: days[date.getDay()], time: hoursAndMinutes});
|
||||
}
|
||||
else if (now.getFullYear() === date.getFullYear()) {
|
||||
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
// TODO: use standard date localize function provided in counterpart
|
||||
return _t('%(weekDayName)s, %(monthName)s %(day)s %(time)s', {weekDayName: days[date.getDay()], monthName: months[date.getMonth()], day: date.getDate(), time: hoursAndMinutes});
|
||||
}
|
||||
else {
|
||||
return this.formatFullDate(date);
|
||||
|
@ -44,11 +77,13 @@ module.exports = {
|
|||
},
|
||||
|
||||
formatFullDate: function(date) {
|
||||
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
const days = getDaysArray();
|
||||
const months = getMonthsArray();
|
||||
var hoursAndMinutes = pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s', {weekDayName: days[date.getDay()], monthName: months[date.getMonth()], day: date.getDate(), fullYear: date.getFullYear(),time: hoursAndMinutes});
|
||||
},
|
||||
|
||||
formatTime: function(date) {
|
||||
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue