mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
Add basic date formatter
This commit is contained in:
6
awx/ui_next/src/util/dates.jsx
Normal file
6
awx/ui_next/src/util/dates.jsx
Normal 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);
|
||||||
|
}
|
||||||
13
awx/ui_next/src/util/dates.test.jsx
Normal file
13
awx/ui_next/src/util/dates.test.jsx
Normal 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'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user