Date conversion returning December for every single digit month representation I can't figure out what I'm doing wrong, but trying to convert single digit months to their name representations (ex. '4' to 'April' in English) but am just getting December printed out for every single one. I can't compare to month names because the site is in quite a few languages, so need to actually use the date functionality.

{% set groupedEntries = entriesInYear | group("postDate|date('n')") %}

{% for key, eachMonth in groupedEntries %}
    {% set monthName = date(key) | date('F') %}
    &lt;li&gt;
        &lt;a href="{{ craft.languageLink.url(craft.locale, urlParam) }}"
            {{ monthName }}, {{ eachMonth|length }}
        &lt;/a&gt;
    &lt;/li&gt;
{% endfor %}


'Key' is the month representation with no leading 0's (4, 3, and 2 for posts that exist in April, March and February).

Getting output as:
December, 4
December, 4
December, 2
(following number is number of posts in that month)

WHAT the heck am I doing wrong?
Here's what's happening... Every time you get "December", it's because the date is being parsed as December 31, 1969 (aka, just before the Unix Epoch). Basically, it's failing to parse the date properly, and thus defaulting back to the Epoch.

And here's why... date(key) is basically saying "Get the date of 4". Which obviously doesn't make any sense. So the "date of 4" is a fail, and you get the Epoch default instead.

So here's what I recommend instead... replace this:

{% set monthName = date(key) | date('F') %}


... with something more like this:

{% switch key %}
    {% case 1 %}
        {% set monthName = 'January'|t %}
    {% case 2 %}
        {% set monthName = 'February'|t %}
    {% case 3 %}
        {% set monthName = 'March'|t %}
    {% case 4 %}
        {% set monthName = 'April'|t %}
    {% case 5 %}
        {% set monthName = 'May'|t %}
    {% case 6 %}
        {% set monthName = 'June'|t %}
    {% case 7 %}
        {% set monthName = 'July'|t %}
    {% case 8 %}
        {% set monthName = 'August'|t %}
    {% case 9 %}
        {% set monthName = 'September'|t %}
    {% case 10 %}
        {% set monthName = 'October'|t %}
    {% case 11 %}
        {% set monthName = 'November'|t %}
    {% case 12 %}
        {% set monthName = 'December'|t %}
{% endswitch %}


That's a big chunk of code, I know. So feel free to offload that to a macro if it's more convenient.

Alternately, you could use a placeholder date, as carlcs suggested in his answer.