I have an ISO date string in a javascript variable, and I want to format it for display. Simply enough, you might think. For instance:
new Date(iso).toDateString()
However, ISO dates might only represent a year ("yyyy"), or a year and month ("yyyy-mm"); they're not always "yyyy-mm-dd". Under these circumstances, the parse method fills in defaults for the missing fields, which I do not want to see.
In other words, I want to only format the date fields defined in the ISO string, but no others. If the ISO string was "2017-12" then I may want it formatted as one of 12/2012, Dec 2017, December 2017, décembre 2017, depending on my locale and level of detail; I would not want a day number. Similarly, if the ISO string was only "2017" then I would not want a day or month indication.
This question is primarily related to the elided ISO forms, and is therefore not a duplicate.
Is there a simple method of formatting such ISO dates properly -- preferably in a locale-aware fashion -- or do I have to do it all long-hand?