fix: timezone-aware date fetching and added Imsak column#23
fix: timezone-aware date fetching and added Imsak column#23lyra-alishaikh wants to merge 2 commits intoahmadawais:mainfrom
Conversation
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| 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.` | |
| ); | |
| } |
| if (query.timezone) { | ||
| addressOptions.timezone = query.timezone; | ||
| } |
There was a problem hiding this comment.
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.
| 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.')); |
There was a problem hiding this comment.
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.
| 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.')); |
|
Implemented follow-up fixes from review:
Validation run locally:
Could you please re-check the PR when you get a chance? 🙏 |
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.