From 1778eb81157bfaeb23881efce6f5e50ef6db25a7 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Thu, 4 Feb 2016 11:53:38 -0800 Subject: Fixed issue with on-hover timestamps --- web/react/components/time_since.jsx | 3 ++- web/react/utils/utils.jsx | 43 ++++++++++--------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) (limited to 'web') diff --git a/web/react/components/time_since.jsx b/web/react/components/time_since.jsx index ba8dbffcc..88d89017b 100644 --- a/web/react/components/time_since.jsx +++ b/web/react/components/time_since.jsx @@ -2,6 +2,7 @@ // See License.txt for license information. import Constants from '../utils/constants.jsx'; +import * as Utils from '../utils/utils.jsx'; import {FormattedRelative, FormattedDate} from 'mm-intl'; @@ -24,7 +25,7 @@ export default class TimeSince extends React.Component { if (this.props.sameUser) { return ( ); } diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 6bb7baa64..3a94c4f3d 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -14,6 +14,8 @@ import * as AsyncClient from './async_client.jsx'; import * as client from './client.jsx'; import Autolinker from 'autolinker'; +import {FormattedTime} from 'mm-intl'; + export function isEmail(email) { // writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378) // so we just do a simple check and rely on a verification email to tell if it's a real address @@ -209,40 +211,17 @@ export function displayDate(ticks) { return monthNames[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear(); } -export function displayTime(ticks, utc) { - const d = new Date(ticks); - let hours; - let minutes; - let ampm = ''; - let timezone = ''; - - if (utc) { - hours = d.getUTCHours(); - minutes = d.getUTCMinutes(); - timezone = ' UTC'; - } else { - hours = d.getHours(); - minutes = d.getMinutes(); - } - - if (minutes <= 9) { - minutes = '0' + minutes; - } - +export function displayTime(ticks) { const useMilitaryTime = PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time'); - if (!useMilitaryTime) { - ampm = ' AM'; - if (hours >= 12) { - ampm = ' PM'; - } - - hours = hours % 12; - if (!hours) { - hours = '12'; - } - } - return hours + ':' + minutes + ampm + timezone; + return ( + + ); } export function displayDateTime(ticks) { -- cgit v1.2.3-1-g7c22 From d416a04e52783460328f5e26295071d75d8897cd Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 5 Feb 2016 09:23:40 -0800 Subject: Separated displayTime functions for component/string form --- web/react/components/time_since.jsx | 2 +- web/react/utils/utils.jsx | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/react/components/time_since.jsx b/web/react/components/time_since.jsx index 88d89017b..1560d2469 100644 --- a/web/react/components/time_since.jsx +++ b/web/react/components/time_since.jsx @@ -25,7 +25,7 @@ export default class TimeSince extends React.Component { if (this.props.sameUser) { return ( ); } diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 3a94c4f3d..4beec8d64 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -211,7 +211,43 @@ export function displayDate(ticks) { return monthNames[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear(); } -export function displayTime(ticks) { +export function displayTime(ticks, utc) { + const d = new Date(ticks); + let hours; + let minutes; + let ampm = ''; + let timezone = ''; + + if (utc) { + hours = d.getUTCHours(); + minutes = d.getUTCMinutes(); + timezone = ' UTC'; + } else { + hours = d.getHours(); + minutes = d.getMinutes(); + } + + if (minutes <= 9) { + minutes = '0' + minutes; + } + + const useMilitaryTime = PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time'); + if (!useMilitaryTime) { + ampm = ' AM'; + if (hours >= 12) { + ampm = ' PM'; + } + + hours = hours % 12; + if (!hours) { + hours = '12'; + } + } + + return hours + ':' + minutes + ampm + timezone; +} + +export function displayTimeFormatted(ticks) { const useMilitaryTime = PreferenceStore.getBool(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time'); return ( -- cgit v1.2.3-1-g7c22