Skip to content

Conversation

sajin-shrestha
Copy link
Collaborator

Description

  • add NepalTimezoneDate class and integrate with NepaliDate
  • updated README to document the new NepalTimezoneDate class and its integration with NepaliDate.

Related Issue

Fixes #104

Type of Change

Please mark the appropriate option below to describe the type of change your pull request introduces:

  • Bug fix
  • New feature
  • Enhancement
  • Documentation update
  • Refactor
  • Other (please specify)

Checklist

  • I have added/updated the necessary documentation on README.md.
  • I have added appropriate test cases (if applicable) to ensure the changes are functioning correctly.
  • My pull request has a clear title and description.

Additional Notes

[Add any additional notes or context that you think the reviewers should know about.]

By submitting this pull request, I confirm that I have read and complied with the contribution guidelines of this project.

Copy link
Member

@aj3sh aj3sh left a comment

Choose a reason for hiding this comment

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

@sajin-shrestha, I have added a few suggestions. Please review them. Also, let's add the tests for this new feature.

* const fromTimestamp = new NepalTimezoneDate(1703766035170); // From timestamp
*/
constructor(...args: ConstructorParameters<typeof Date>) {
this._date = new Date(...args)
Copy link
Member

Choose a reason for hiding this comment

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

We should not assign the args directly to the Date. The args provided here are the NepalTimeZone detail, not the Date (timezone unsafe).

Expected:

NepalTimeZone(2025, 8, 2, 13, 53) 
Nepali Time: 1:53 PM
UTC Time: 8:08 AM

If you are running the code in a different timezone, this code will fail.
We can use utils getDate to safely convert the Nepali date params to the Date object and keep it.

I realized that it's quite challenging to do, so we should accept 3 types of arguments first.

  1. Unix epoch
    new NepalTimezoneDate(1756819453)
  2. Date object
    new NepalTimezoneDate(dateObj)
  3. year, month, ...
    new NepalTimezoneDate(year, month, date, hour, ...)

Formatting and parsing for English dates are already done on NepaliDate, we will move it here later.

@@ -0,0 +1,190 @@
import { getNepalDateAndTime } from './utils'
Copy link
Member

Choose a reason for hiding this comment

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

Let's move the getNepalDateAndTime and getDate as the NepalTimezoneDate internal function. The core logic of the timezone handling will be done only by the NepalTimezoneDate class.

NepaliDate will internally use NepalTimezoneDate for the safe timezone date conversion.

@@ -101,6 +101,13 @@ You can create a `NepaliDate` object in several ways:
const date6 = new NepaliDate(2079, 2, 15, 10, 30)
```

- Using a NepalTimezoneDate object: Converts a NepalTimezoneDate object (Gregorian date in Nepal timezone) to a NepaliDate object.
Copy link
Member

Choose a reason for hiding this comment

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

Let's not include this on NepaliDate section.

* date.getYear(); // Returns 2024
*/
getYear(): number {
return getNepalDateAndTime(this._date).year
Copy link
Member

Choose a reason for hiding this comment

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

set this as _nepalTimezoneSafeDate on the constructor. This reduces the call of getNepalDateAndTime on every function.

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.

Feature: NepalTimezoneDate class
2 participants