mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-15 07:48:38 -05:00
Add basic date formatter
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
@@ -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