mirror of https://github.com/vector-im/riot-web
Add parameter `showTwelveHours` to formatTime
parent
5aa1bc4185
commit
f9152b205c
|
@ -16,7 +16,6 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import UserSettingsStore from './UserSettingsStore';
|
|
||||||
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||||
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||||
|
|
||||||
|
@ -24,13 +23,13 @@ function pad(n) {
|
||||||
return (n < 10 ? '0' : '') + n;
|
return (n < 10 ? '0' : '') + n;
|
||||||
}
|
}
|
||||||
|
|
||||||
function twentyFourHour(date) {
|
function twelveHourTime(date) {
|
||||||
let hours = date.getHours() % 12;
|
let hours = date.getHours() % 12;
|
||||||
let minutes = pad(date.getMinutes());
|
let minutes = pad(date.getMinutes());
|
||||||
const ampm = hours >= 12 ? 'PM' : 'AM';
|
const ampm = hours >= 12 ? 'PM' : 'AM';
|
||||||
hours = pad(hours ? hours : 12);
|
hours = pad(hours ? hours : 12);
|
||||||
minutes = pad(minutes);
|
minutes = pad(minutes);
|
||||||
return hours + ':' + minutes + ' ' + ampm;
|
return `${hours}:${minutes} ${ampm}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -54,9 +53,9 @@ module.exports = {
|
||||||
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + this.formatTime(date);
|
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + this.formatTime(date);
|
||||||
},
|
},
|
||||||
|
|
||||||
formatTime: function(date) {
|
formatTime: function(date, showTwelveHour=false) {
|
||||||
if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) {
|
if (showTwelveHour) {
|
||||||
return twentyFourHour(date);
|
return twelveHourTime(date);
|
||||||
}
|
}
|
||||||
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue