Hugo

Add n minutes to a given date

The .AddDate function supports adding years, months, and days.

For an online calendar I needed to add n minutes to date_start (unless date_end is provided).

With something like {{ add (time .date_start).Minute 150 } I had no success, because this does not increment the hours—or even the day/year if necessary (e.g. for an event starting 2019-12-31:T23:00:00-02:00).

Yet, with the Unix time format time calculation is no problem. It is a bit JavaScript like:

{{ $date_end := "" }}
{{ range sort .Site.Data.talks ".date_start" "desc" }}
    {{ $date_end = (time .date_start).Unix }}
    {{ $date_end = (add $date_end 9000) }}
    {{ dateFormat "2006-01-02-15-04" $date_end }}
{{ end }}

Maybe this is useful for someone.

Actually, something very similar is already documented for the .Unix function.

4 Likes