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:
parent
275765b8fc
commit
9421781cc7
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'
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user