Skip to content
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

Incorrect month calculation #235

Closed
punjab opened this issue Sep 12, 2021 · 3 comments
Closed

Incorrect month calculation #235

punjab opened this issue Sep 12, 2021 · 3 comments

Comments

@punjab
Copy link

punjab commented Sep 12, 2021

Hello Sarabveer:

While testing out the Nanakshahi library to cross-reference data for my own ruby library on some dates, I came across what appears to be a bug. Please have a look. Regards

const n = require('nanakshahi')

const date = new Date(2004, 3, 14)
console.log( n.getNanakshahiDate( date ) )

Output was Vaisakh 1, but should be Chet 1

Object
gregorianDate: Wed Apr 14 2004 00:00:00 GMT-0500 (Central Daylight Time)
englishDate: Object {month: 2, monthName: "Vaisakh", date: 1, year: 536, day: "Budhvaar", dayShort: "Budh"}
punjabiDate: Object {month: "੨", monthName: "ਵੈਸਾਖ", date: "੧", year: "੫੩੬", day: "ਬੁੱਧਵਾਰ", dayShort: "ਬੁੱਧ"}
leapYear: false
@sarabveer
Copy link
Owner

sarabveer commented Sep 14, 2021

This is not an issue with my library. Months in Javascript are from 0 to 11.

So to get March 14, 2004, one would do: new Date(2004, 2, 14).

See gregorianDate, it is correctly showing April 14, 2004.

@punjab
Copy link
Author

punjab commented Sep 15, 2021

Thanks for clarifying, bhaji. I was just pointing out the Punjabidate in the object returned, which says "punjabiDate: Object {month: "੨", monthName: "ਵੈਸਾਖ", date: "੧", year: "੫੩੬", ". Please ignore and close the ticket, if it is by design. Chardi kala!

@sarabveer
Copy link
Owner

No problem! I am not sure why JS has months from 0-11 instead of 1-12.

Here is the output if a Date object is initialized as new Date(2004, 2, 14).

const n = require('nanakshahi')

const date = new Date(2004, 2, 14)
console.log( n.getNanakshahiDate( date ) )

Output:

Object
gregorianDate: Sun Mar 14 2004 00:00:00 GMT-0500 (Eastern Standard Time)
englishDate: Object {month: 1, monthName: "Chet", date: 1, year: 536, day: "Aitvaar", dayShort: "Ait"}
punjabiDate: Object {month: "੧", monthName: "ਚੇਤ", date: "੧", year: "੫੩੬", day: "ਐਤਵਾਰ", dayShort: "ਐਤ"}
leapYear: false

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

No branches or pull requests

2 participants