Skip to content

Commit b105f07

Browse files
VIA-629 SB/EO Change date format from YYYYMMDD to YYYY-MM-DD
1 parent 342735f commit b105f07

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PROFILE_PERFORMANCE=true
77
DEPLOY_ENVIRONMENT=local
88

99
# Vaccs campaigns
10-
CAMPAIGNS='{"COVID_19": [{ "start": "20251112", "end": "20260131" }, { "start": "20261101", "end": "20270131" }]}'
10+
CAMPAIGNS='{"COVID_19": [{ "start": "2025-11-12", "end": "2026-01-31" }, { "start": "2026-11-01", "end": "2027-01-31" }]}'
1111

1212
# content cache hydrator
1313
CONTENT_API_ENDPOINT=http://localhost:8081/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "20251112", "end": "20260131" },
4-
{ "start": "20261101", "end": "20270131" }
3+
{ "start": "2025-11-12", "end": "2026-01-31" },
4+
{ "start": "2026-11-01", "end": "2027-01-31" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "20251112", "end": "20260131" },
4-
{ "start": "20261101", "end": "20270131" }
3+
{ "start": "2025-11-12", "end": "2026-01-31" },
4+
{ "start": "2026-11-01", "end": "2027-01-31" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "20251112", "end": "20260131" },
4-
{ "start": "20261101", "end": "20270131" }
3+
{ "start": "2025-11-12", "end": "2026-01-31" },
4+
{ "start": "2026-11-01", "end": "2027-01-31" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "20251112", "end": "20260131" },
4-
{ "start": "20261101", "end": "20270131" }
3+
{ "start": "2025-11-12", "end": "2026-01-31" },
4+
{ "start": "2026-11-01", "end": "2027-01-31" }
55
]
66
}

src/services/content-api/parsers/custom/covid-19.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
66
describe("buildFilteredContentForCovid19Vaccine", () => {
77
process.env.CAMPAIGNS = JSON.stringify({
88
COVID_19: [
9-
{ start: "20251101", end: "20260131" },
10-
{ start: "20261101", end: "20270131" },
9+
{ start: "2025-11-01", end: "2026-01-31" },
10+
{ start: "2026-11-01", end: "2027-01-31" },
1111
],
1212
});
1313
jest.useFakeTimers();

src/utils/campaigns/types.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ describe("Campaigns", () => {
77
it("should convert json to a Campaigns ", async () => {
88
const jsonString = JSON.stringify({
99
COVID_19: [
10-
{ start: "20251112", end: "20260301" },
11-
{ start: "20260901", end: "20270301" },
10+
{ start: "2025-11-12", end: "2026-03-01" },
11+
{ start: "2026-09-01", end: "2027-03-01" },
1212
],
1313
FLU_FOR_ADULTS: [
14-
{ start: "20251112", end: "20260301" },
15-
{ start: "20260901", end: "20270301" },
14+
{ start: "2025-11-12", end: "2026-03-01" },
15+
{ start: "2026-09-01", end: "2027-03-01" },
1616
],
1717
});
1818

@@ -30,7 +30,7 @@ describe("Campaigns", () => {
3030
});
3131

3232
describe("isActive", () => {
33-
const jsonString = JSON.stringify({ COVID_19: [{ start: "20251112", end: "20260301" }] });
33+
const jsonString = JSON.stringify({ COVID_19: [{ start: "2025-11-12", end: "2026-03-01" }] });
3434
const campaigns = Campaigns.fromJson(jsonString)!;
3535

3636
it.each([

src/utils/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("lazyConfig", () => {
8989

9090
it("should convert CAMPAIGNS to a Campaigns ", async () => {
9191
setupTestEnvVars("test/");
92-
process.env.CAMPAIGNS = JSON.stringify({ COVID_19: [{ start: "20251112", end: "20260301" }] });
92+
process.env.CAMPAIGNS = JSON.stringify({ COVID_19: [{ start: "2025-11-12", end: "2026-03-01" }] });
9393

9494
const actual = await config.CAMPAIGNS;
9595

@@ -128,7 +128,7 @@ describe("lazyConfig", () => {
128128
it("should throw for CAMPAIGNS with invalid date", async () => {
129129
setupTestEnvVars("test/");
130130
process.env.CAMPAIGNS = JSON.stringify({
131-
covid: [{ start: "20251312", end: "20260301" }],
131+
covid: [{ start: "2025-13-12", end: "2026-03-01" }],
132132
});
133133

134134
await expect(async () => {

src/utils/date.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ import { UtcDateFromStringSchema } from "@src/utils/date";
22

33
describe("UtcDateFromStringSchema", () => {
44
it("should parse winter date", () => {
5-
const actual = UtcDateFromStringSchema.parse("20260101");
5+
const actual = UtcDateFromStringSchema.parse("2026-01-01");
66

77
expect(actual).toEqual(new Date("2026-01-01"));
88
});
99

1010
it("should parse summer date", () => {
11-
const actual = UtcDateFromStringSchema.parse("20260601");
11+
const actual = UtcDateFromStringSchema.parse("2026-06-01");
1212

1313
expect(actual).toEqual(new Date("2026-06-01"));
1414
});
1515

1616
it("should throw on invalid date", () => {
17+
const given = "2026-13-01";
18+
19+
expect(() => {
20+
UtcDateFromStringSchema.parse(given);
21+
}).toThrow();
22+
});
23+
24+
it("should throw on date without dashes", () => {
1725
const given = "20261301";
1826

1927
expect(() => {

src/utils/date.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { z } from "zod";
22

33
export const UtcDateFromStringSchema = z
44
.string()
5-
.regex(/^\d{8}$/, "Date must be in YYYYMMDD format")
5+
.regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format")
66
.transform((str, ctx) => {
77
const year = parseInt(str.slice(0, 4));
8-
const month = parseInt(str.slice(4, 6)); // 1-indexed (01 = Jan)
9-
const day = parseInt(str.slice(6, 8));
8+
const month = parseInt(str.slice(5, 7)); // 1-indexed (01 = Jan)
9+
const day = parseInt(str.slice(8, 10));
1010
const utcTimestamp = Date.UTC(year, month - 1, day);
1111
const date = new Date(utcTimestamp);
1212
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {

0 commit comments

Comments
 (0)