summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorReed Garmsen <rgarmsen2295@gmail.com>2016-02-05 09:23:40 -0800
committerReed Garmsen <rgarmsen2295@gmail.com>2016-02-05 09:23:40 -0800
commitd416a04e52783460328f5e26295071d75d8897cd (patch)
treec47aa7c3eaf7cda11faac10b818da63d44c1ae8c /web
parent1778eb81157bfaeb23881efce6f5e50ef6db25a7 (diff)
downloadchat-d416a04e52783460328f5e26295071d75d8897cd.tar.gz
chat-d416a04e52783460328f5e26295071d75d8897cd.tar.bz2
chat-d416a04e52783460328f5e26295071d75d8897cd.zip
Separated displayTime functions for component/string form
Diffstat (limited to 'web')
-rw-r--r--web/react/components/time_since.jsx2
-rw-r--r--web/react/utils/utils.jsx38
2 files changed, 38 insertions, 2 deletions
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 (
<time className='post__time'>
- {Utils.displayTime(this.props.eventTime)}
+ {Utils.displayTimeFormatted(this.props.eventTime)}
</time>
);
}
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 (