-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add NepalTimezoneDate class and integrate with NepaliDate #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
- Unix epoch
new NepalTimezoneDate(1756819453) - Date object
new NepalTimezoneDate(dateObj) - 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' |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Description
Related Issue
Fixes #104
Type of Change
Please mark the appropriate option below to describe the type of change your pull request introduces:
Checklist
README.md
.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.