-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Use Case
Prerequisite: The system must be running in a different timezone (e.g., UTC).
When the system is in a different timezone, handling dates and times specific to Nepal's timezone (Asia/Kathmandu) can be challenging. For instance, if we have a date/time string in Nepal's timezone, there is no direct way to retrieve Nepal-specific values like the year, month, day, hour, or minutes. Instead, it always returns data in the system's timezone data.
Thanks to the NepaliDate class, from which this can be achieved. However, introducing this feature could also benefit the NepaliDate class by improving logic decoupling. Additionally, not every use case requires converting the date to the Nepali calendar.
Proposed Solution
Create a NepalTimezoneDate class that extends JavaScript's Date object. The NepalTimezoneDate object would behave exactly like a Date object operating on Asia/Kathmandu timezone.
Goal [Update]:
The goal is to isolate the utils getNepalDateAndTime and getDate functions within NepalTimezoneDate. All the timezone handling will be done by the NepalTimezoneDate. And the NepaliDate will use NepalTimezoneDate object for timezone-safe date/time conversion.
Example Usage:
const date1 = new Date();
// 2024-12-28T15:00:35.170Z
const date2 = new NepalTimezoneDate();
// 2024-12-28 20:45:35 GMT+0545
date2.getYear(); // 2024
date2.getMinutes(); // 45[Update]
const date1 = new NepalTimezoneDate(2024, 12, 28, 20, 45, 35) // 20:45 is the nepal's time (not UTC)
date1.toString()
// 2024-12-28 20:45:35 GMT+0545
date1.toDateObject()
// 2024-12-28T15:00:35.170ZAlternatives Considered
N/A
Dependencies
N/A
Additional Context
The logic implemented in NepaliDate are in src/utils.ts > getNepalDateAndTime and getDate