Here is my current dateFormat: {{ dateFormat 3:04 PM • 02 Jan 2006" .Date.Local}}
How do I force it to resolve to a specific timezone (ET, specifically)? It uses my local time when I run Hugo locally, but Netlify builds my site with UTC, so my published blog has times from the wrong timezone.
I hate the date formatter in Go Templates, and I cannot seem to find comprehensive documentation anywhere. This is my #1 pain point when it comes to Hugo.
@keithjgrant,
At the moment, we don’t provide a way to set a timezone (all you can currently do is get the system time or UTC). I’ll pitch a solution below to begin a discussion on how to fix this.
We could add a time.LoadLocation template function that simply front-ends the Go stdlib. You can see a sample usage in this playground. The template would look like this:
{{ $loc := time.LoadLocation "America/Chicago" }}
System Time: {{ time.Now }}
Central Time: {{ time.Now.In $loc }}
The more complicated issue would be trying to add a default location setting to the site config. In that case, we would likely want to treat all dates read from front matter as being in the default location (assuming no timezone data is present in the date string). Currently, all dates are assumed to be in the local system time. Solving that issue would take a lot more work.
Does setting the TZ environment variable in Netlify help? I haven’t used that var for hugo directly but it helps for setting the time zone to what I want when I export Org files to markdown for Hugo using Emacs on Netlify.
I needed setting the timezone to UTC so that my tests run on Netlify wouldn’t fail due to timezone differences.
Excellent! Setting the TZ environment variable in Netlify worked. It looks like only EST and EDT are valid though, not ET, so I’ll have to change this every time daylight savings changes, but I guess I can live with that.
I am such a newbie on this subject that I do not know how to add TZ environment variable. But after reading this documentation, I learned to add it to the build.environment label:
If a key has a list of key/value pairs as its value, you can set that key in its own block like this:
ERROR 2019/09/04 08:36:13 failed to render pages: render of “home” failed: “/…/themes/xyz/layouts/index.html:8:12”: execute of template failed: template: index.html:8:12: executing “main” at : can’t evaluate field LoadLocation in type interface {}