subeshb1 / Nepali-Date

📅 A small JS Library to convert English Date to Nepali and Vice Versa
https://subeshb1.github.io/Nepali-Date/
MIT License
53 stars 21 forks source link

Js Date stored in Instance Object is a day behind the date object. #36

Closed amSiddiqui closed 3 years ago

amSiddiqui commented 3 years ago

When I am passing a JS Date object as a constructor to NepaliDate, the stored Js date, in the instance, is 1 day behind the original JS date object. This is an example of the problem.

Original Date:  2021-06-08T18:15:00.000Z
Nepali Instance:  NepaliDate {
  [Symbol(Year)]: 2078,
  [Symbol(MonthIndex)]: 1,
  [Symbol(Date)]: 25,
  [Symbol(Day)]: 2,
  [Symbol(JsDate)]: 2021-06-07T18:30:00.000Z
}
Formatted Original:  2021-06-09
Formatted Nepali Date:  2021-06-08

The format is done using Intl.DateTimeFormat.

let formatted = new Intl.DateTimeFormat('en-GB', {timeZone: process.env.TZ, month: '2-digit', day: "2-digit", year: "numeric"}).format(d);

Where process.env.TZ = 'Asia/Kathmandu'

amSiddiqui commented 3 years ago

This issue is only presenting on my local machine and not on the deployed Server Instance. I suspect the issue is due to TimeZone. I was running some tests by changing the time values, but I wanted an opinion on the issue.