Skip to content

Commit

Permalink
fix: use try/catch when parsing utc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Feb 24, 2020
1 parent 5314017 commit ace8cb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion i18n/module/i18n_module_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,5 @@ no=No
password_changed_successfully=Password changed successfully
login_again=You need to login again to continue using the application.
login=Login
not_applicable=N/A
never=Never
invalid_date=Invalid date
32 changes: 18 additions & 14 deletions src/aboutPage/AboutPage.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import PropTypes from 'prop-types';
import AboutSection from './AboutSection.component';

const parseDateFromUTCString = (utcString, d2) => {
if (!utcString) {
return d2.i18n.getTranslation('not_applicable')
try {
if (!utcString) {
return d2.i18n.getTranslation('never')
}

const locale = d2.currentUser.userSettings.settings.keyUiLocale;
const date = new Date(utcString);
const options = {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
};
return new Intl.DateTimeFormat(locale, options).format(date);
} catch (error) {
return d2.i18n.getTranslation('invalid_date')
}

const locale = d2.currentUser.userSettings.settings.keyUiLocale;
const date = new Date(utcString);
const options = {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
};
return new Intl.DateTimeFormat(locale, options).format(date);
};

const attributes = {
Expand Down

0 comments on commit ace8cb5

Please sign in to comment.