Skip to content

fix: timezone-aware date fetching and added Imsak column#23

Open
lyra-alishaikh wants to merge 2 commits intoahmadawais:mainfrom
lyra-alishaikh:fix/timings-timezone-and-sehar
Open

fix: timezone-aware date fetching and added Imsak column#23
lyra-alishaikh wants to merge 2 commits intoahmadawais:mainfrom
lyra-alishaikh:fix/timings-timezone-and-sehar

Conversation

@lyra-alishaikh
Copy link
Copy Markdown

Improvements\n\n1. Timezone-Aware Fetching: Updated the date formatting logic to use the target location's timezone. This prevents the 'Midnight Bug' where users in eastern timezones (like UAE) would see yesterday's timings during the early morning hours if the server is running in UTC.\n2. Added Imsak Column: Included an Imsak column (10m before Fajr) in the table output, which is a common safety practice in many regions.\n3. UAE Method Refinement: Updated recommendations to use Umm Al-Qura (Method 4) as the default for UAE, while maintaining Method 16 specifically for Dubai/Sharjah to better match local Awqaf timings.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses timezone handling issues and enhances the Ramadan prayer times display by adding timezone-aware date fetching and an Imsak column. The changes fix the "Midnight Bug" where users in eastern timezones would see incorrect prayer times during early morning hours when the server operates in UTC.

Changes:

  • Implemented timezone-aware date formatting in API calls to ensure date calculations use the target location's timezone
  • Added Imsak column (10 minutes before Fajr) to the prayer times table output
  • Updated UAE calculation method recommendations: Method 4 (Umm Al-Qura) as default, Method 16 specifically for Dubai/Sharjah

Reviewed changes

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

File Description
src/api.ts Modified formatDate function to accept timezone parameter and use Intl.DateTimeFormat for timezone-aware formatting; added timezone parameter to fetch options interfaces
src/commands/ramadan.ts Added Imsak column to RamadanRow interface and table display; updated timezone handling in fetch functions; modified help text to reflect Imsak addition
src/recommendations.ts Changed UAE default method from 16 to 4; added specific entries for Dubai and Sharjah with method 16

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

Comment thread src/api.ts
const parts = new Intl.DateTimeFormat('en-GB', options).formatToParts(date);
const day = parts.find((p) => p.type === 'day')?.value;
const month = parts.find((p) => p.type === 'month')?.value;
const year = parts.find((p) => p.type === 'year')?.value;
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The formatDate function could return a string with undefined values like "undefined-undefined-undefined" if formatToParts() fails to produce the expected parts. This could happen with invalid timezones or edge cases. Consider adding validation or fallback logic to handle cases where parts are not found, or throw an explicit error if any part is undefined.

Suggested change
const year = parts.find((p) => p.type === 'year')?.value;
const year = parts.find((p) => p.type === 'year')?.value;
if (!day || !month || !year) {
throw new Error(
`Failed to format date for timezone "${timezone ?? 'UTC'}". Missing date component.`
);
}

Copilot uses AI. Check for mistakes.
Comment thread src/commands/ramadan.ts
Comment on lines +752 to +754
if (query.timezone) {
addressOptions.timezone = query.timezone;
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

Adding addressOptions.timezone = query.timezone here will cause a TypeScript compilation error because the addressOptions type definition (lines 731-736) does not include a timezone?: string property. The type definition needs to be updated to include this property, similar to how cityOptions (line 769) and coordsOptions (line 804) were updated.

Copilot uses AI. Check for mistakes.
Comment thread src/commands/ramadan.ts Outdated
console.log('');
}
console.log(pc.dim(' Sehar uses Fajr. Iftar uses Maghrib.'));
console.log(pc.dim(' Imsak is 10m before Fajr. Sehar ends at Fajr.'));
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The note "Imsak is 10m before Fajr" is presented as a fact, but this is actually determined by the prayer time calculation method being used. Different methods may calculate Imsak differently (not always exactly 10 minutes before Fajr). Consider clarifying this as "typically" or verifying that all supported calculation methods use this specific offset.

Suggested change
console.log(pc.dim(' Imsak is 10m before Fajr. Sehar ends at Fajr.'));
console.log(pc.dim(' Imsak is typically 10m before Fajr. Sehar ends at Fajr.'));

Copilot uses AI. Check for mistakes.
@lyra-alishaikh
Copy link
Copy Markdown
Author

Implemented follow-up fixes from review:

  • Added defensive validation in formatDate() to throw a clear error if day/month/year parts are missing (avoids undefined-undefined-undefined output).
  • Added missing timezone?: string to addressOptions typing in fetchRamadanDay to match runtime usage.
  • Clarified output note to: "Imsak is typically 10m before Fajr."

Validation run locally:

  • pnpm biome check src/api.ts src/commands/ramadan.ts
  • pnpm typecheck
  • pnpm test ✅ (38/38 tests passing)

Could you please re-check the PR when you get a chance? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants