From 9b45854f12ca77276953204ee96643e0670f2588 Mon Sep 17 00:00:00 2001 From: nishupr Date: Sun, 21 Jun 2026 21:11:34 +0530 Subject: [PATCH] fix(validations): use UTC year for streak/wrapped year validation upper bound Replaces new Date().getFullYear() (server-local time) with new Date().getUTCFullYear() in both streakParamsSchema and wrappedParamsSchema year validation, removing server-timezone dependency from the upper bound check. Also updates the corresponding test file (lib/validations.year.test.ts) to compute CURRENT_YEAR via getUTCFullYear() for consistency with the schema's new behaviour. Closes #6244 --- lib/validations.ts | 4 ++-- lib/validations.year.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/validations.ts b/lib/validations.ts index 744c84a47..01d096533 100644 --- a/lib/validations.ts +++ b/lib/validations.ts @@ -321,7 +321,7 @@ const baseStreakParamsSchema = z.object({ (val) => { if (!val) return true; const yearNum = parseInt(val, 10); - const currentYear = new Date().getFullYear(); + const currentYear = new Date().getUTCFullYear(); return /^\d{4}$/.test(val) && yearNum >= 2008 && yearNum <= currentYear; }, { @@ -672,7 +672,7 @@ export const wrappedParamsSchema = z.object({ (val) => { if (!val) return true; const yearNum = parseInt(val, 10); - const currentYear = new Date().getFullYear(); + const currentYear = new Date().getUTCFullYear(); return /^\d{4}$/.test(val) && yearNum >= 2008 && yearNum <= currentYear; }, { diff --git a/lib/validations.year.test.ts b/lib/validations.year.test.ts index 5830012d0..d33c8ec07 100644 --- a/lib/validations.year.test.ts +++ b/lib/validations.year.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from 'vitest'; import { streakParamsSchema, wrappedParamsSchema } from './validations'; -const CURRENT_YEAR = new Date().getFullYear(); +const CURRENT_YEAR = new Date().getUTCFullYear(); const EXPECTED_ERROR = 'GitHub was founded in 2008. Please provide a year of 2008 or later.'; function getYearError(result: {