Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Kierangould/12hourtimestamp #903

Merged
merged 5 commits into from
May 26, 2017

Conversation

Kieran-Gould
Copy link
Contributor

Added support for 12 hour timestamps. Option for 12/24hr is pulled from UserSettings.

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@Kieran-Gould Kieran-Gould changed the base branch from master to develop May 18, 2017 21:24
src/DateUtils.js Outdated
let ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0'+minutes : minutes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest just using the pad(n) function defined above :)

src/DateUtils.js Outdated

function pad(n) {
return (n < 10 ? '0' : '') + n;
}

function twentyfourhour(date) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please indent consistently as per the code-style (i.e. 4 spaces). The function probably should be twentyFourHour() too for consistent casing.

@@ -65,7 +65,6 @@ const SETTINGS_LABELS = [
id: 'dontSendTypingNotifications',
label: "Don't send typing notifications",
},
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay! \o/

@@ -479,24 +481,31 @@ module.exports = WithMatrixClient(React.createClass({
);

var e2e;
let e2e_style;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Changing the whole CSS to make room for 24h timestamps feels a bit worrying, although I see why you're doing it...

A nicer bet here would be to just put the mx_EventTile_12h class onto the EventTile itself, and then in the CSS have a selector like:

.mx_EventTile_12h .mx_EventTile_e2eIcon {
    padding-left: 5px;
}

.mx_EventTile_12h .mx_EventTile_line {
    padding-left: 100px;
}

...or whatever the tweaks are. And then you don't need all these overrides of the e2e_style, which are quite confusing at first as it makes it sound like the e2e icon is somehow very explicitly being changed by the timestamp(!) rather than just for layout purposes.

TL;DR: cascading stylesheets cascade; let's make the most of that :)

src/DateUtils.js Outdated
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;
Copy link
Member

@t3chguy t3chguy May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be being blind but where is time referenced?

src/DateUtils.js Outdated
function twentyfourhour(date) {
let hours = date.getHours();
let minutes = date.getMinutes();
let ampm = hours >= 12 ? 'PM' : 'AM';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be const

@@ -16,6 +16,8 @@ limitations under the License.

'use strict';

import UserSettingsStore from '../../../UserSettingsStore';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be potentially be better being passed into the EventTile as a prop so it is not triggering a parse for each tile

// cosmetic padlocks:
if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take a look at the classnames lib, would allow you to do this all in one line -ish

src/DateUtils.js Outdated
},

formatTime: function(date) {
if (UserSettingsStore.getSyncedSetting('showTwelveHourTimestamps')) {
return twentyfourhour(date);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 spaces please :)

src/DateUtils.js Outdated
let ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0'+minutes : minutes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a template literal might be more readable here or at least on the line below

@ara4n
Copy link
Member

ara4n commented May 18, 2017

tests are failing - my guess (untested) is that you need mkStubRoom() in test/test-utils.js to return a valid event for getAccountData(), like createTestClient() does. Atm it returns null, hence the NPE. You'll want to run npm run test to see it go up in a ball of flame (and to check that you've fixed the tests)

I'm also slightly having second thoughts about whether EventTile should be using a prop for this (which is set by the room itself) rather than querying the js-sdk from the depths of its render() method. If it was set by the room, then we'd have the advantage of being able to listen for Room.accountData events and update the prop when that happens, thus responding to synced settings changes in realtime rather than waiting for the page to be reloaded...

@ara4n
Copy link
Member

ara4n commented May 26, 2017

lgtm! sorry for slow review; we're drowning.

@ara4n ara4n merged commit fde553a into matrix-org:develop May 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants