1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Add basic date formatter

This commit is contained in:
Jake McDermott 2019-10-03 20:02:14 -04:00
parent 275765b8fc
commit 9421781cc7
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F
2 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,6 @@
/* eslint-disable import/prefer-default-export */
import { getLanguage } from './language';
export function formatDateString(dateString, lang = getLanguage(navigator)) {
return new Date(dateString).toLocaleString(lang);
}

View File

@ -0,0 +1,13 @@
import { formatDateString } from './dates';
describe('formatDateString', () => {
test('it returns the expected value', () => {
const lang = 'en-US';
expect(formatDateString('', lang)).toEqual('Invalid Date');
expect(formatDateString({}, lang)).toEqual('Invalid Date');
expect(formatDateString(undefined, lang)).toEqual('Invalid Date');
expect(formatDateString('2018-01-31T01:14:52.969227Z', lang)).toEqual(
'1/31/2018, 1:14:52 AM'
);
});
});