mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
* fix: humanize-date * fix: improve notification handling and enhance date validation
This commit is contained in:
@@ -151,7 +151,15 @@ export const relativeDate = (dateString) => {
|
||||
export const humanizeDate = (dateString) => {
|
||||
// See this discussion for why .split is necessary
|
||||
// https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off
|
||||
const date = new Date(dateString.split('-'));
|
||||
|
||||
if (!dateString || typeof dateString !== 'string') {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
const date = new Date(dateString);
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
|
||||
@@ -58,6 +58,18 @@ describe('common utils', () => {
|
||||
it('should return invalid date if the date is invalid', () => {
|
||||
expect(humanizeDate('9999-99-99')).toBe('Invalid Date');
|
||||
});
|
||||
|
||||
it('should return "Invalid Date" if the date is null', () => {
|
||||
expect(humanizeDate(null)).toBe('Invalid Date');
|
||||
});
|
||||
|
||||
it('should return a humanized date for a valid date in ISO format', () => {
|
||||
expect(humanizeDate('2024-11-28T00:00:00Z')).toBe('November 28, 2024');
|
||||
});
|
||||
|
||||
it('should return "Invalid Date" for a non-date string', () => {
|
||||
expect(humanizeDate('some random text')).toBe('Invalid Date');
|
||||
});
|
||||
});
|
||||
|
||||
describe('relativeDate', () => {
|
||||
|
||||
Reference in New Issue
Block a user