vmems-website/layouts/partials/FormatHistoricalDate.html

36 lines
1.1 KiB
HTML

{{ $formattedDate := "" }}
{{ $rawDate := . }}
{{- $date := "1800-01-01" -}}
{{- $datePrecision := "day" -}}
{{ if reflect.IsMap $rawDate }}
{{ partial "FormatHistoricalDate" ($rawDate.from) }}
-
{{ partial "FormatHistoricalDate" ($rawDate.to) }}
{{ else }}
{{ $rawDate = string $rawDate }}
{{ if eq (len $rawDate) 4 }}
{{ $datePrecision = "year" }}
{{ $date = printf "%s-01-01" $rawDate }}
{{ end }}
{{ if eq (len $rawDate) 7 }}
{{ $datePrecision = "month" }}
{{ $date = printf "%s-01" $rawDate }}
{{ end }}
{{ if eq (len $rawDate) 10 }}
{{ $datePrecision = "day" }}
{{ $date = $rawDate }}
{{ end }}
{{- if eq $datePrecision "year" -}}
{{ $formattedDate = ($date | time.Format "2006") }}
{{- end -}}
{{- if eq $datePrecision "month" -}}
{{ $formattedDate = ($date | time.Format "January 2006") }}
{{- end -}}
{{- if eq $datePrecision "day" -}}
{{ $formattedDate = ($date | time.Format "2 January 2006") }}
{{- end -}}
{{ end }}
{{ printf "%s" $formattedDate }}