Specify date format in archetype?

Okay, this got really interesting!

I made a test archetype to play with formatting, see if I could replicate the error. And sure enough, it shows the same for me.

+++
title = "blah"
date = "{{ dateFormat .Date "2-1-2006" }}"
+++
template: date:3:11: executing "date" at <dateFormat .Date "2-...>: error calling dateFormat: unable to parse date: 2-1-2006

Then I was getting a refresher (meaning I never remember this stuff) on Go’s layout string in the docs, where I remembered there being a specific example: "2006-01-02"

+++
title = "blah"
date = "{{ dateFormat .Date "2006-01-02" }}"
+++
+++
title = "blah"
date = "2017-10-29T00:06:02+00:00"
+++

Then I decided to move them around one at a time, to see if we could pinpoint the reason even 02-01-2006 doesn’t work. My next test was for 2006-02-01

+++
title = "blah"
date = "{{ dateFormat .Date "2006-02-01" }}"
+++
+++
title = "blah"
date = "1027-20-19T00:09:00+00:00"
+++

:astonished:

:thinking:

:face_with_raised_eyebrow:

Okay, let’s see what we get! I tried all combos (there were only six for the portions we are messing with), and only the format with the year at the beginning is parsing.

+++
title = "blah"
date = "{{ .Date }}"
+++

{{ dateFormat .Date "2006-01-02" }}
{{ dateFormat .Date "2006-02-01" }}
+++
title = "blah"
date = "2017-10-29T01:09:09-07:00"
+++

2017-10-29T01:09:09+00:00
1027-20-19T02:09:09+00:00

These don’t work:

  • 02-2006-01
  • 02-01-2006
  • 01-02-2006
  • 01-2006-02

So, I hope we figure out @Jura’s thing, but I am also very curious as to why using 2006-02-01 produces 1027-20-19, where every other number is switched as a pair. :slight_smile:

1 Like