Skip to content
Open
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
35 changes: 35 additions & 0 deletions js/test/util/current_date.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from 'chai';
import sinon from 'sinon';

import currentDate from '../../util/current_date';

describe('current_date', () => {
const { getCurrentDate } = currentDate;

let clock;

afterEach(() => {
if (clock) {
clock.restore();
clock = null;
}
});

it('zero-pads a single-digit day of month', () => {
// June 7, 2026
clock = sinon.useFakeTimers(new Date(2026, 5, 7).getTime());
expect(getCurrentDate('-')).to.equal('2026-06-07');
});

it('zero-pads single-digit month and day together', () => {
// January 5, 2026
clock = sinon.useFakeTimers(new Date(2026, 0, 5).getTime());
expect(getCurrentDate('-')).to.equal('2026-01-05');
});

it('leaves a two-digit day unchanged', () => {
// June 15, 2026
clock = sinon.useFakeTimers(new Date(2026, 5, 15).getTime());
expect(getCurrentDate('-')).to.equal('2026-06-15');
});
});
2 changes: 1 addition & 1 deletion js/util/current_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function getCurrentDate(separator = '') {
const month = newDate.getMonth() + 1;
const year = newDate.getFullYear();

return `${year}${separator}${month < 10 ? `0${month}` : `${month}`}${separator}${date}`;
return `${year}${separator}${month < 10 ? `0${month}` : `${month}`}${separator}${date < 10 ? `0${date}` : `${date}`}`;
}

export default {
Expand Down