From f7d74edaddf674193ae10c1070ca9913a29f5659 Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 14 Nov 2026 10:25:38 +0800 Subject: [PATCH 1/2] fix: correct access log timezone offsets --- src/date.ts | 16 ++++++------- test/date.test.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/date.ts b/src/date.ts index f3dae43..71dcd2e 100644 --- a/src/date.ts +++ b/src/date.ts @@ -3,15 +3,12 @@ import { LRU } from 'ylru'; const lru = new LRU(1000); export function resetTimezone(date: Date) { - let TIMEZONE: string = ''; const offsetInMinutes = date.getTimezoneOffset(); - const _hourOffset: number = Math.floor(-offsetInMinutes / 60); - const _minuteOffset: number = Math.abs(offsetInMinutes % 60); - - TIMEZONE += _hourOffset >= 0 ? '+' : '-'; - TIMEZONE += `${String(Math.abs(_hourOffset)).padStart(2, '0')}${String(_minuteOffset).padStart(2, '0')}`; - - return TIMEZONE; + const sign = offsetInMinutes <= 0 ? '+' : '-'; + const absoluteOffset = Math.abs(offsetInMinutes); + const hours = Math.floor(absoluteOffset / 60); + const minutes = absoluteOffset % 60; + return `${sign}${String(hours).padStart(2, '0')}${String(minutes).padStart(2, '0')}`; } const MONTHS: Record = { @@ -33,7 +30,8 @@ const MONTHS: Record = { }; export function getTimezone(d: Date) { - const key = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`; + // The offset can change within a day, including during a repeated local hour. + const key = d.getTimezoneOffset(); const timeZone = lru.get(key); if (timeZone === undefined) { // Cache for 24 hours diff --git a/test/date.test.ts b/test/date.test.ts index c6f348b..b97c63a 100644 --- a/test/date.test.ts +++ b/test/date.test.ts @@ -200,6 +200,63 @@ describe('test/date.test.ts', () => { }); describe('accessLogDate()', () => { + describe('timezone offsets', () => { + let originalTimezone: string | undefined; + + beforeEach(() => { + originalTimezone = process.env.TZ; + }); + + afterEach(() => { + if (originalTimezone === undefined) { + delete process.env.TZ; + } else { + process.env.TZ = originalTimezone; + } + }); + + const transitions = [ + { + name: 'spring forward', + dates: [ '2026-03-08T06:59:59Z', '2026-03-08T07:00:00Z' ], + expected: [ '08/Mar/2026:01:59:59 -0500', '08/Mar/2026:03:00:00 -0400' ], + }, + { + name: 'fall back', + dates: [ '2026-11-01T05:30:00Z', '2026-11-01T06:30:00Z' ], + expected: [ '01/Nov/2026:01:30:00 -0400', '01/Nov/2026:01:30:00 -0500' ], + }, + ]; + + for (const { name, dates, expected } of transitions) { + for (const order of [ [ 0, 1 ], [ 1, 0 ] ]) { + it(`should use each date's offset during ${name} in order ${order}`, () => { + process.env.TZ = 'America/New_York'; + for (const index of order) { + const date = new Date(dates[index]); + assert.equal(utility.accessLogDate(date), expected[index]); + assert.equal(utility.getDateFromMilliseconds(date.getTime(), utility.DateFormat.DateTimeWithTimeZone), expected[index]); + } + }); + } + } + + const timezones = [ + [ 'America/St_Johns', '15/Jan/2026:08:30:00 -0330' ], + [ 'Pacific/Marquesas', '15/Jan/2026:02:30:00 -0930' ], + [ 'Asia/Kolkata', '15/Jan/2026:17:30:00 +0530' ], + [ 'Asia/Kathmandu', '15/Jan/2026:17:45:00 +0545' ], + [ 'UTC', '15/Jan/2026:12:00:00 +0000' ], + ]; + + for (const [ timezone, expected ] of timezones) { + it(`should format the offset in ${timezone}`, () => { + process.env.TZ = timezone; + assert.equal(utility.accessLogDate(new Date('2026-01-15T12:00:00Z')), expected); + }); + } + }); + it('accessLogDate() should return an access log format date string', () => { // 16/Apr/2013:16:40:09 +0800 assert.match(utility.accessLogDate(new Date()), /^(0[1-9]|[12]\d|3[01])\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4}:\d{2}:\d{2}:\d{2} [+-](0[0-9]|1[0-3])\d{2}$/); From 4f5a29184cab361f11e94fb8ec5ae20d8c653061 Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 14 Nov 2026 10:44:30 +0800 Subject: [PATCH 2/2] fix: pin compatible CI tool dependencies --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2270095..7ef6712 100644 --- a/package.json +++ b/package.json @@ -29,13 +29,18 @@ "moment": "^2.22.2", "object-assign": "^4.1.1", "optimized": "^1.2.0", - "oxlint": "^1.11.1", + "oxlint": "1.11.1", "time-require": "^0.1.2", "tsd": "^0.28.1", "tshy": "^3.0.2", "tshy-after": "^1.0.0", "typescript": "^5.2.2" }, + "overrides": { + "@arethetypeswrong/core@0.17.4": { + "fflate": "0.8.2" + } + }, "homepage": "https://github.com/node-modules/utility", "repository": { "type": "git",