From 17bd110aec07e5f4f31bd5ef6422d371907e8066 Mon Sep 17 00:00:00 2001 From: Maxwell Kepler Date: Thu, 18 May 2017 22:00:44 +0100 Subject: [PATCH] Add 12 hour support --- src/DateUtils.js | 34 +++++++++++++++-------- src/components/structures/UserSettings.js | 2 +- src/components/views/rooms/EventTile.js | 19 +++++++++---- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/DateUtils.js b/src/DateUtils.js index c58c09d4dec8..f787fc0e2036 100644 --- a/src/DateUtils.js +++ b/src/DateUtils.js @@ -16,27 +16,37 @@ 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"]; +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"]; +let time; function pad(n) { return (n < 10 ? '0' : '') + n; } +function twentyfourhour(date) { + let hours = date.getHours(); + let minutes = date.getMinutes(); + let ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; + minutes = minutes < 10 ? '0'+minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; + return strTime; +} + module.exports = { formatDate: function(date) { - // date.toLocaleTimeString is completely system dependent. - // just go 24h for now - var now = new Date(); if (date.toDateString() === now.toDateString()) { - return pad(date.getHours()) + ':' + pad(date.getMinutes()); + return this.formatTime(date); } else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { - return days[date.getDay()] + " " + pad(date.getHours()) + ':' + pad(date.getMinutes()); + return days[date.getDay()] + " " + this.formatTime(date); } else if (now.getFullYear() === date.getFullYear()) { - return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes()); + return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + this.formatTime(date); } else { return this.formatFullDate(date); @@ -44,11 +54,13 @@ module.exports = { }, formatFullDate: function(date) { - return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + pad(date.getHours()) + ':' + pad(date.getMinutes()); + return days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear() + " " + this.formatTime(date); }, formatTime: function(date) { + if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) { + return twentyfourhour(date); + } return pad(date.getHours()) + ':' + pad(date.getMinutes()); - } + }, }; - diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 2c1f17ee3e03..45774d7a6aba 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -65,7 +65,6 @@ const SETTINGS_LABELS = [ id: 'dontSendTypingNotifications', label: "Don't send typing notifications", }, -/* { id: 'alwaysShowTimestamps', label: 'Always show message timestamps', @@ -74,6 +73,7 @@ const SETTINGS_LABELS = [ id: 'showTwelveHourTimestamps', label: 'Show timestamps in 12 hour format (e.g. 2:30pm)', }, +/* { id: 'useCompactLayout', label: 'Use compact timeline layout', diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index 44c40519958c..6ec076ba959b 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -16,6 +16,8 @@ limitations under the License. 'use strict'; +import UserSettingsStore from '../../../UserSettingsStore'; + var React = require('react'); var classNames = require("classnames"); var Modal = require('../../../Modal'); @@ -479,24 +481,31 @@ module.exports = WithMatrixClient(React.createClass({ ); var e2e; + let e2e_style; // cosmetic padlocks: + if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) { + e2e_style = "mx_EventTile_e2eIcon mx_EventTile_e2eIcon_12hr"; + } + else { + e2e_style = "mx_EventTile_e2eIcon"; + } if ((e2eEnabled && this.props.eventSendStatus) || this.props.mxEvent.getType() === 'm.room.encryption') { - e2e = Encrypted by verified device; + e2e = Encrypted by verified device; } // real padlocks else if (this.props.mxEvent.isEncrypted() || (e2eEnabled && this.props.eventSendStatus)) { if (this.props.mxEvent.getContent().msgtype === 'm.bad.encrypted') { - e2e = Undecryptable; + e2e = Undecryptable; } else if (this.state.verified == true || (e2eEnabled && this.props.eventSendStatus)) { - e2e = Encrypted by verified device; + e2e = Encrypted by verified device; } else { - e2e = Encrypted by unverified device; + e2e = Encrypted by unverified device; } } else if (e2eEnabled) { - e2e = Unencrypted message; + e2e = Unencrypted message; } const timestamp = this.props.mxEvent.getTs() ? : null;