I have a yaml file containing metadata used around the site. One particular value usually contains a nicely formatted date string (YYYY-MM-DD), but in some cases it might contain pure text, like a fuzzy future date (early 2026, for example).
These dates are displayed in a couple of different formats, and Hugo is very helpful with that.
The problem I’m running into is that there seems to be no way for me to test whether a given string is parseable as a date. I’d like to do something like this:
{{ if (“early 2026” | time) }}
it worked
{{ else }}
it did not work
{{ end }}
But any attempt that direction throws an error:
execute of template failed at <time>: error calling time: unable to parse date: early 2026
One dumb workaround I thought of is to turn either the parseable date strings or the fuzzy strings into slices so that I can use reflect.IsSlice and handle them that way.
Is that my best option? Or is there a better way?