From ba57e40f860c6c0d0dc1f343d335070a5c6d2a24 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Mon, 29 Jun 2026 11:11:25 +0900 Subject: [PATCH] Zero-pad day of month in getCurrentDate getCurrentDate zero-pads the month but emits the day raw, so on the 1st through 9th of a month it returns dates like 2026-06-7 instead of 2026-06-07. That value feeds the agency-finder rep_start date filter in report.js and quarterly_report.js, so the YYYY-MM-DD contract breaks on those days. Apply the same single-digit guard to the day, and add a focused unit test covering single-digit day, single-digit month and day, and a two-digit day control. Signed-off-by: Arpit Jain --- js/test/util/current_date.test.js | 35 +++++++++++++++++++++++++++++++ js/util/current_date.js | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 js/test/util/current_date.test.js diff --git a/js/test/util/current_date.test.js b/js/test/util/current_date.test.js new file mode 100644 index 000000000..b324ad148 --- /dev/null +++ b/js/test/util/current_date.test.js @@ -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'); + }); +}); diff --git a/js/util/current_date.js b/js/util/current_date.js index f8843549b..8e083c8fd 100644 --- a/js/util/current_date.js +++ b/js/util/current_date.js @@ -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 {