summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/src/shared/date-helper.ts4
-rw-r--r--gui/test/unit/date-helper.spec.ts1
2 files changed, 5 insertions, 0 deletions
diff --git a/gui/src/shared/date-helper.ts b/gui/src/shared/date-helper.ts
index 25f5144539..017b2048f5 100644
--- a/gui/src/shared/date-helper.ts
+++ b/gui/src/shared/date-helper.ts
@@ -133,6 +133,10 @@ export const formatTimeLeft = (fromDate: DateType, toDate: DateType): string =>
const years = Math.abs(diff.years);
const days = Math.abs(diff.days);
+ if (days < 1) {
+ return messages.gettext('less than a day left');
+ }
+
if (days < 730) {
return sprintf(messages.ngettext('1 day left', '%d days left', days), days);
}
diff --git a/gui/test/unit/date-helper.spec.ts b/gui/test/unit/date-helper.spec.ts
index 5ed0cfa6da..5f44c53a2d 100644
--- a/gui/test/unit/date-helper.spec.ts
+++ b/gui/test/unit/date-helper.spec.ts
@@ -151,6 +151,7 @@ describe('Date helper', () => {
});
it('should format time left correctly', () => {
+ expect(date.formatTimeLeft('2022-09-01', '2022-09-01')).to.equal('less than a day left');
expect(date.formatTimeLeft('2022-09-01', '2022-09-02')).to.equal('1 day left');
expect(date.formatTimeLeft('2022-09-01', '2022-09-05')).to.equal('4 days left');
expect(date.formatTimeLeft('2022-09-01', '2022-09-30')).to.equal('29 days left');