get_event_dates.html 1.0 KB

1234567891011121314151617
  1. {{/* Function to get event start and end dates/times. */}}
  2. {{ $t1 := time .Date }}{{/* Start datetime. */}}
  3. {{ $str := slice (time.Format site.Params.locale.date_format (time $t1)) }}{{/* Init return string with start date. */}}
  4. {{/* Show start time if not all day event. */}}
  5. {{ if not .Params.all_day }}{{ $str = $str | append (time.Format site.Params.locale.time_format (time $t1)) }}{{ end }}
  6. {{/* Show event end date if provided. */}}
  7. {{ if .Params.date_end }}
  8. {{ $str = $str | append "—" }}
  9. {{ $t2 := time .Params.date_end}}{{/* End datetime. */}}
  10. {{/* Show end date if it differs to start date. */}}
  11. {{ if not (eq $t1.Year $t2.Year | and (eq $t1.Month $t2.Month) | and (eq $t1.Day $t2.Day)) }}
  12. {{ $str = $str | append (time.Format site.Params.locale.date_format (time $t2)) }}
  13. {{ end }}
  14. {{/* Show end time if not all day event. */}}
  15. {{ if not .Params.all_day }}{{ $str = $str | append (time.Format site.Params.locale.time_format (time $t2)) }}{{ end }}
  16. {{ end }}
  17. {{ return (delimit $str " ") }}