Add parameter showTwelveHours
to formatTime
This commit is contained in:
parent
5aa1bc4185
commit
f9152b205c
1 changed files with 5 additions and 6 deletions
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
import UserSettingsStore from './UserSettingsStore';
|
||||
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
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;
|
||||
}
|
||||
|
||||
function twentyFourHour(date) {
|
||||
function twelveHourTime(date) {
|
||||
let hours = date.getHours() % 12;
|
||||
let minutes = pad(date.getMinutes());
|
||||
const ampm = hours >= 12 ? 'PM' : 'AM';
|
||||
hours = pad(hours ? hours : 12);
|
||||
minutes = pad(minutes);
|
||||
return hours + ':' + minutes + ' ' + ampm;
|
||||
return `${hours}:${minutes} ${ampm}`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -54,9 +53,9 @@ module.exports = {
|
|||
return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + this.formatTime(date);
|
||||
},
|
||||
|
||||
formatTime: function(date) {
|
||||
if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) {
|
||||
return twentyFourHour(date);
|
||||
formatTime: function(date, showTwelveHour=false) {
|
||||
if (showTwelveHour) {
|
||||
return twelveHourTime(date);
|
||||
}
|
||||
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue