Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

DateTime getMonth() functions returning the wrong value (month - 1) #574

Closed
jphillips-bp3 opened this issue Mar 14, 2019 · 6 comments
Closed

Comments

@jphillips-bp3
Copy link

I have a DateTime parameter on my request, and is being set using the UTC value 2019-03-11T12:30:59.000Z.

If I call the following DateTime getX functions I get the following results:

getYear() // 2019
getMonth() // 2 - expected 3
getDay() // 11
getHour() // 12
getMinute() // 30
getSecond() // 59

All of them are correct apart from the getMonth, so is this for some reason indexed from zero which is why the third month is the value two?

@jeromesimeon
Copy link
Member

This is behavior inherited from momentJS... http://momentjs.com/docs/#/get-set/month/

I don't know why it is done this way in momentJS, but we could take a different road and have months ranging from 1 to 12 instead of from 0 to 11. Would welcome feedback on this from the community.

@jphillips-bp3
Copy link
Author

Mmm very odd. OK no worries I will just add one to the value for now but it would be good to make Ergo at least behave consistently.

@jeromesimeon
Copy link
Member

Right. I guess I'm saying it's consistent with the (arguably inconsistent) semantics in momentjs.

I will make the months range from 1 to 12 unless I hear someone object.

@jphillips-bp3
Copy link
Author

Right. I guess I'm saying it's consistent with the (arguably inconsistent) semantics in momentjs.

I will make the months range from 1 to 12 unless I hear someone object.

I agree, moment is the inconsistent one!

@jeromesimeon
Copy link
Member

PR here: #582

@jeromesimeon
Copy link
Member

Done in 0.7.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants