Skip to content

Fix DST-aware midnight release handling for PT/ET platforms - #1

Merged
x-n2o merged 2 commits into
mainfrom
fix-time-offset-issue
May 10, 2026
Merged

x-n2o merged 2 commits into
mainfrom
fix-time-offset-issue

Conversation

@x-n2o

@x-n2o x-n2o commented May 10, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Platform strategies that mapped global midnight to a fixed UTC time caused off-by-one-day and incorrect-hour behavior around DST transitions.
  • The change ensures midnight in PT/ET is converted to the correct UTC instant for the episode air date instead of using a constant UTC offset.

Description

  • Add a strategyTimezone mapping and use it in resolveDateTime to detect when a platform strategy requires a local-timezone conversion.
  • Implement localMidnightToUtc which computes the correct UTC timestamp for local midnight on the given air_date.
  • Implement getTimezoneOffsetMinutes using Intl.DateTimeFormat.formatToParts to compute the date-specific offset (handles DST).
  • Update tests to add a regression case (uses DST-aware PT midnight conversion) and keep existing behavior for exactRelease, explicit releaseTime, and non-midnight strategies; modified files: src/release.ts, tests/release.test.ts.

Testing

  • Ran unit tests with pnpm test -- --run tests/release.test.ts tests/tmdb.test.ts.
  • All tests passed: total 28 tests passed (no failures).

Copilot AI review requested due to automatic review settings May 10, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates release-time resolution so that “global midnight” platform strategies (PT/ET) convert local midnight on the episode’s air_date into the correct UTC instant, including DST-aware offsets.

Changes:

  • Added a strategyTimezone mapping and updated resolveDateTime to route select strategies through a local-time conversion.
  • Implemented localMidnightToUtc + getTimezoneOffsetMinutes using Intl.DateTimeFormat.formatToParts to compute date-specific timezone offsets (DST-aware).
  • Added a regression test asserting PT-local midnight maps to the correct UTC time for a winter date.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/release.ts Adds timezone-aware conversion logic for PT/ET “global midnight” strategies using Intl offset computation.
tests/release.test.ts Adds a DST-focused regression test for PT midnight → UTC conversion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/release.ts
Comment on lines +74 to +77
const utcMidday = Date.UTC(year, month - 1, day, 12, 0, 0);
const offsetMinutes = getTimezoneOffsetMinutes(utcMidday, timezone);
const utcMillis = Date.UTC(year, month - 1, day, 0, 0, 0) - offsetMinutes * 60 * 1000;

Comment thread tests/release.test.ts
it("uses DST-aware PT midnight conversion", () => {
expect(resolveDateTime({ ...baseShow, network: "Netflix" }, { ...baseEpisode, air_date: "2026-01-15" })).toBe(
"2026-01-15T08:00:00Z",
);
Comment thread src/release.ts
Comment on lines +81 to +91
function getTimezoneOffsetMinutes(timestamp: number, timezone: string): number {
const dtf = new Intl.DateTimeFormat("en-US", {
timeZone: timezone,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hourCycle: "h23",
});
@x-n2o
x-n2o merged commit 2dd34f9 into main May 10, 2026
2 checks passed
@x-n2o
x-n2o deleted the fix-time-offset-issue branch May 10, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants