HUGO

Add minutes to date

[Created new topic from https://discourse.gohugo.io/t/add-minutes-to-date/6142]

We’re four years later now. Would it be possible to get a function that just performs this operation for us, that doesn’t require a round-trip via UNIX time stamps (as described in Add n minutes to a given date)?

Motivation: UNIX time stamps are not timezone-aware, and thus any operations involving those have to be performed very, very carefully in order to not mess up anything.

Actually, they are timezone-aware. The timezone is UTC (offset 00:00).

+++
title = "Test"
date = 2021-07-24T08:00:00-07:00
draft = false
+++
Code Result
{{ (.Date.Add (time.ParseDuration "36h")).Format "2006-01-02T15:04:05-07:00" }} 2021-07-25T20:00:00-07:00
{{ (.Date.Add (time.ParseDuration "-36h")).Format "2006-01-02T15:04:05-07:00" }} 2021-07-22T20:00:00-07:00
{{ (.Date.Add (time.ParseDuration "90m")).Format "2006-01-02T15:04:05-07:00" }} 2021-07-24T09:30:00-07:00
{{ (.Date.Add (time.ParseDuration "90s")).Format "2006-01-02T15:04:05-07:00" }} 2021-07-24T08:01:30-07:00
{{ (.Date.Add (time.ParseDuration "1h2m3s")).Format "2006-01-02T15:04:05-07:00" }} 2021-07-24T09:02:03-07:00

Reference:

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.