Format date displayed in Releases section (#14183)
Closes #14177 I noticed a `formatDisplayDate` file being used in `twenty-website` and created the same one for `twenty-front` as well. Unit tests for the same have been added. <img width="1438" height="770" alt="image" src="https://github.com/user-attachments/assets/5aa6eef5-19c5-4108-bf3f-c582d0ca1b59" /> <img width="1275" height="785" alt="image" src="https://github.com/user-attachments/assets/20a87ba6-fca4-472c-a691-362901505303" /> --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
committed by
GitHub
parent
40251d34ec
commit
7a999c8476
+30
-1
@@ -1,4 +1,12 @@
|
||||
import { formatExpiration } from '@/settings/developers/utils/formatExpiration';
|
||||
import {
|
||||
formatExpiration,
|
||||
isExpired,
|
||||
} from '@/settings/developers/utils/formatExpiration';
|
||||
import { i18n } from '@lingui/core';
|
||||
import { messages as enMessages } from '~/locales/generated/en';
|
||||
|
||||
i18n.load('en', enMessages);
|
||||
i18n.activate('en');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
|
||||
|
||||
@@ -39,3 +47,24 @@ describe('formatExpiration', () => {
|
||||
expect(resultWithExpiresMention).toEqual('Expires in 8 years and 9 days');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isExpired', () => {
|
||||
it('should return false for future dates', () => {
|
||||
const expiresAt = '2024-01-10T00:00:00.000Z';
|
||||
expect(isExpired(expiresAt)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for past dates', () => {
|
||||
const expiresAt = '2023-12-01T00:00:00.000Z';
|
||||
expect(isExpired(expiresAt)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for null dates', () => {
|
||||
expect(isExpired(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for never expiring dates', () => {
|
||||
const expiresAt = '2044-01-10T00:00:00.000Z';
|
||||
expect(isExpired(expiresAt)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
@@ -12,17 +13,25 @@ export const doesNeverExpire = (expiresAt: string) => {
|
||||
return dateDiff.years > NEVER_EXPIRE_DELTA_IN_YEARS / 10;
|
||||
};
|
||||
|
||||
export const isExpired = (expiresAt: string | null) => {
|
||||
if (!isNonEmptyString(expiresAt) || doesNeverExpire(expiresAt)) {
|
||||
return false;
|
||||
}
|
||||
const dateDiff = beautifyDateDiff(expiresAt, undefined, true);
|
||||
return dateDiff.includes('-');
|
||||
};
|
||||
|
||||
export const formatExpiration = (
|
||||
expiresAt: string | null,
|
||||
withExpiresMention = false,
|
||||
short = true,
|
||||
) => {
|
||||
if (!isNonEmptyString(expiresAt) || doesNeverExpire(expiresAt)) {
|
||||
return withExpiresMention ? 'Never expires' : 'Never';
|
||||
return withExpiresMention ? t`Never expires` : t`Never`;
|
||||
}
|
||||
const dateDiff = beautifyDateDiff(expiresAt, undefined, short);
|
||||
if (dateDiff.includes('-')) {
|
||||
return 'Expired';
|
||||
return t`Expired`;
|
||||
}
|
||||
return withExpiresMention ? `Expires in ${dateDiff}` : `In ${dateDiff}`;
|
||||
return withExpiresMention ? t`Expires in ${dateDiff}` : t`In ${dateDiff}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user