Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/amplify-component-lib",
"version": "9.9.1",
"version": "9.9.2",
"description": "Frontend Typescript components for the Amplify team",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
18 changes: 14 additions & 4 deletions src/atoms/utils/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
test('formatDate works as expected when not sending in a date', () => {
const formattedDate = formatDate(null);

expect(formattedDate).toBe('');
expect(formattedDate).toBe(undefined);
});

test('formatDate works as expected with default format', () => {
Expand Down Expand Up @@ -177,6 +177,11 @@ test('formatDate works as expected with format = "DD. month" and month = "short"
expect(formattedDate).toBe(testFormatted);
});

test('formatDate with null should be undefined', () => {
const formatted = formatDate(null);
expect(formatted).toBe(undefined);
});

test('formatDateTime works as expected', () => {
const today = new Date();
const fakeDate = faker.date.past({
Expand All @@ -196,7 +201,7 @@ test('formatDateTime works as expected', () => {

test('formatDateTime works as expected when not sending in a date', () => {
const formatted = formatDateTime(null);
expect(formatted).toBe('');
expect(formatted).toBe(undefined);
});

test('formatDateTime works as expected with options', () => {
Expand Down Expand Up @@ -234,9 +239,9 @@ test('formatDateTime works as expected when isGMT is set', () => {
expect(formatted).toBe(expectedResult);
});

test('formatRelativeDateTime with null should be empty string', () => {
test('formatRelativeDateTime with null should be undefined', () => {
const formatted = formatRelativeDateTime(null);
expect(formatted).toContain('');
expect(formatted).toBe(undefined);
});

test('formatRelativeDateTime with isGMT set should convert to local time', () => {
Expand Down Expand Up @@ -421,6 +426,11 @@ test('formatRelativeDateTime with date not in current year displays as full date
expect(formattedDateInNextYear).toBe(expectedNextYearResult);
});

test('formatRelativeDateTime with null should be undefined ', () => {
const formatted = formatDate(null);
expect(formatted).toBe(undefined);
});

test('isBetweenDates works as expected with null', () => {
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));
Expand Down
12 changes: 6 additions & 6 deletions src/atoms/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const formatDate = (
format: 'DD. month YYYY',
month: 'long',
}
): string => {
): string | undefined => {
if (date) {
const dateObj = new Date(date);
if (dateObj.getTime()) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export const formatDate = (
.padStart(2, '0')}.${year.toString().padStart(4, '0')}`;
}
}
return '';
return undefined;
};

// formatDateTime(new Date()) => 19. January 2022, 01:32
Expand All @@ -80,7 +80,7 @@ export const formatDateTime = (
hideYear: false,
isGMT: false,
}
): string => {
): string | undefined => {
if (date) {
const dateObj = new Date(date);
if (dateObj.getTime()) {
Expand All @@ -98,15 +98,15 @@ export const formatDateTime = (
})}`;
}
}
return '';
return undefined;
};

// formatRelativeDateTime(new Date()) => Today at 7:17
// formatRelativeDateTime(new Date(2018, 11, 24, 10, 33)) => 24. November 2018, 10:33
export const formatRelativeDateTime = (
date: Date | string | null | undefined,
isGMT = false
): string => {
): string | undefined => {
if (date) {
const dateObj = new Date(date);
const today = new Date();
Expand Down Expand Up @@ -150,7 +150,7 @@ export const formatRelativeDateTime = (
}
}
}
return '';
return undefined;
};

export const isBetweenDates = (
Expand Down