node-nepali-datetime icon indicating copy to clipboard operation
node-nepali-datetime copied to clipboard

Feature: NepalTimezoneDate class

Open aj3sh opened this issue 1 year ago • 0 comments

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.

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

Alternatives Considered
N/A

Dependencies
N/A

Additional Context The logic implemented in NepaliDate are in src/utils.ts > getNepalDateAndTime and getDate

aj3sh avatar Dec 28 '24 16:12 aj3sh