parse_date_code is off by 1 month
teohhanhui opened this issue · 1 comments
Value returned from SSF.parse_date_code
has m
(month) value offset by +1.
moment.fromOADate
(moment-msdate
plugin) gives the correct value.
tl;dr parse_date_code
returns one-based month numbers and JS uses zero-based month numbers. This is simpler than making adjustments elsewhere.
The intention of the parse_date_code
function is to return the values that you would use in rendering a date output (including corrections for the 1900 leap year ). Since other sources do not try to make 1900 a leap year, I generally don't recommend using this if you have a date code from a source other than a spreadsheet.
The m
value from parse_date_code gives you the 1-indexed month value, consistent with string renderings of the m
and mm
format. For example, today is "October 20 2016" date code 42663
according to Excel. There are 5 month formats, from m
to mmmmm
. If you want to compare, try using the format m , mm , mmm , mmmm , mmmmm
:
value | date | m , mm , mmm , mmmm , mmmmm |
---|---|---|
42663 |
10/20/16 | 10 , 10 , Oct , October , O |
42419 |
2/19/16 | 2 , 02 , Feb , February , F |
JS dates use zero-indexed months, which is why parse_date_code
seems to give you a different month. It was a design decision. For what it's worth, it seems inconsistent for getDate
to return a one-based day and for getMonth
to return a zero-based month.