foxbunny/datetimejs

Wrong date-Object when parsing strings without date

Closed this issue · 5 comments

Hi,
I think we discovered a bug. If you parse without using a date the result points to the last day of the previous month.
e.g.:

datetime.strptime("March 2019", "%B %Y") // results is 28.02.2019
datetime.strptime("2019", "%Y") // result is 31.12.2018

I'd expect it to give me the first day of the month and the first day of the year.

The Problem seems to be in the parse routine where you initialize the meta object with the default values. For date the default value should be 1 because 0 leads to the last day of the previous month.

date: 0,

We've attached a patch with tests and a fix or if you like we can create a pull request.

Regards,
Gideon

Hi Gideon, and thanks for taking the time. Yeah, the patch looks good. And sorry you had to put up with the weird variable names. That's probably from CoffeeScript-to-JavaScript conversion which I never got around to cleaning up.

Anyway, feel free to open a PR at your own leisure, or let me know if you'd rather that I patch that in.

Thank you for the quick answer and action. Yes the variable names are a bit weird, but that's ok.
Is it possible to publish a new version 0.3.5?

Yes, I'll take care of it in a few minutes.

@metromorph Published as 0.3.5. Let me know if you run into issues. It's been a while since I published this package, so might have broken something while cleaning up the package.json.

Thank you so much! It seems to work just fine. Could you please do me the favour and publish it to npm?