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

Force chat export to use 24-hour timestamp format #9724

Closed

Conversation

19-444-P2
Copy link

@19-444-P2 19-444-P2 commented Dec 8, 2022

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Notes: First open-source contribution and initial PR, addressing issue 23838 in the Element repo. Working on checklist.


Here's what your changelog entry will look like:

✨ Features

  • First open-source contribution and initial PR, addressing issue [23838](https (#9724). Contributed by @19-444-P2.

@19-444-P2 19-444-P2 requested a review from a team as a code owner December 8, 2022 01:06
@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Dec 8, 2022
@richvdh richvdh changed the title PlainTextExport.ts: Add code changes to force 24-hour timestamp format Force chat export to use 24-hour timestamp format Dec 8, 2022
@richvdh richvdh added the T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements label Dec 8, 2022
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Thanks for this! Please do have a read through https://github.com/vector-im/element-web/blob/develop/CONTRIBUTING.md and make sure that you've done everything it asks.

Also note that the CI is currently failing for a number of different reasons. Please make sure you address the issues it has flagged up.

Comment on lines +122 to +134
let date_time_string = new Date(event.getTs()).toLocaleString();

// regex for dissecting the 12-hour timestamp
const TIMESTAMP_REGEX = /(\d*\/\d*\/[0-9]*), ([0-9]*:[0-9]*:[0-9]*) (AM|PM|am|pm|a\.m\.|p\.m\.)/;
const timestampRegexResult = TIMESTAMP_REGEX.match(date_time_string);

// ignore if the format happens to be in the 24-hour format
if (timestampRegexResult) {
const current_date = timestampRegexResult[1];
const timestamp = timestampRegexResult[2];
const am_or_pm = timestampRegexResult[3];

if (am_or_pm === "am" || am_or_pm === "AM" || am_or_pm === "a.m.") {
Copy link
Member

Choose a reason for hiding this comment

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

there are easier ways of splitting up a Date than using a regexp; see for example Date.getHours.

Comment on lines +124 to +161
// regex for dissecting the 12-hour timestamp
const TIMESTAMP_REGEX = /(\d*\/\d*\/[0-9]*), ([0-9]*:[0-9]*:[0-9]*) (AM|PM|am|pm|a\.m\.|p\.m\.)/;
const timestampRegexResult = TIMESTAMP_REGEX.match(date_time_string);

// ignore if the format happens to be in the 24-hour format
if (timestampRegexResult) {
const current_date = timestampRegexResult[1];
const timestamp = timestampRegexResult[2];
const am_or_pm = timestampRegexResult[3];

if (am_or_pm === "am" || am_or_pm === "AM" || am_or_pm === "a.m.") {
if (timestamp.substring(0,2) === "12") {
date_time_string = `${current_date}, 00${timestamp.substring(2)}`;
} else if (timestamp.length == 7) {
date_time_string = `${current_date}, 0${timestamp}`;
} else {
date_time_string = `${current_date}, ${timestamp}`;
}
} else {
let hour = timestamp.substring(0,2);

if (hour === "12") {
date_time_string = `${current_date}, ${timestamp}`;
} else {

let substring_start_index = 2;
if (hour[1] === ":") {
hour = timestamp[0];
substring_start_index = 1;
}

let new_hour = (+hour + 12).toString();

date_time_string = `${current_date}, ${new_hour}${timestamp.substring(substring_start_index)}`;
}
}

}
Copy link
Member

Choose a reason for hiding this comment

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

please could you factor the Date processing out to a separate function, and add some tests for it.

@t3chguy
Copy link
Member

t3chguy commented Dec 12, 2022

Why wouldn't we want the chat export to match your own preference of 12/24hr instead of ignoring it?

@t3chguy
Copy link
Member

t3chguy commented Aug 7, 2023

Thanks for your contribution but this is not desirable, the export should match your user preference for time format as per element-hq/element-web#23838

@t3chguy t3chguy closed this Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants