Support for complex date parsing

I have a content folder named “images” and I add date to each of the image, these images are historical so I might not know the date at a day precision.
So I would like to just put date “1980” if I know that this picture was taken sometime in the year 1980. Right now I get a parse error when I try to use .Date.Format.
My need is to have something like that:
if it’s only the year, then show just the year
if it’s the year plus the month then format to show the Year + Month
if it’s the year + month + day then format as usual.

So I created complex logic in my template to do custom parsing.
It would be ideal if I could define my own go function to handle because it’s a lot of code in the template.

I’m just sharing this as an example of a use case of hugo to do complex logic template.

You cannot create your own Go function, but you can create your own Hugo function using a partial template with a return statement.


{{ $result := 0 }}
{{ range . }}
  {{ $result = add $result . }}
{{ end }}
{{ return $result }}  

some other template

{{ partial "functions/sum" (slice 1 2 3) }}  --> 6

Note that the return statement may only be used once, and must appear at the end of the partial.

Yes, the partial feature is what is the closest to I want in the hugo features set. But of course, among others issues, having to use the curly brace everytime clutter the code, when I just want to compute a single string. I’m really looking forward for a plugin feature (even a very limited one) that could solve this very point.