hugo
hugo copied to clipboard
Date format / timezone issue after remote build
What version of Hugo are you using (hugo version
)?
$ hugo version 0.100.2
Does this issue reproduce with the latest release?
Yes.
When attempt to use the timezone in a .Date.Format
for a post/page, it works locally, but when deployed, it displays the timezone as -0700
no matter what. And when I use just {{ .Date }}
it displays -0700 -0700
.
{{ .Date.Format "January 2, 2006 3:04 PM MST" }}
and {{ .Date }}
return the following on both Cloudflare and Netlify.

Locally it spits out June 11, 2022 at 2:06 AM PDT // 2022-06-11 02:06:56 -0700 PDT
as it should.
Are there logs I can track to figure out the cause? As far as I can tell, it's a bug of some kind, but that both netlify and pages suffer from? is it a timezone/config issue on my end and I'm crazy?
I think setting a timeZone
in your Hugo config and then use time.Format for any date formatting may give you better results:
{{ .Date | time.Format "January 2, 2006 3:04 PM MST" }}
But I'm not totally sure what happens in your case.
Thanks. I applied as you suggested, same results. That is a much better solution though, so thank you!
The timezone / fomatting are correct on the posts after the build on Cloudflare. I assumed that was set by the timezone set in the post front matter so I didn't need timezone in the config. Since I'm just trying to display the PST / PDT with the post time. I'm still not the most savvy Hugo user.
Local:

On Cloudflare/Netlify builds:

Cloudflare was able to replicate it though. If it's not a bug, it might be a misconception in the configuration of Hugo on these services? But so far I've been unable to figure out why it's happening.
This might be a workaround.
Could you set TZ
environment variable before building such as TZ="/usr/share/zoneinfo/America/Denver"
?
~(I have not tested with netlify.)~
Just adding this thread from Hugo discourse: https://discourse.gohugo.io/t/possible-bug-mst-showing-as-0900-instead-of-jst-or-kst/37883
I currently don't have extra time to get back to it but if someone wants to do testing for GH Pages, the repo sample is: https://github.com/techmagus/hugo-test-site
Copy that. Was able to replicate it on both without the TZ set in the environmental variable. The server doesn't seem to know how to return the PDT/PST without it.
And without it, it spits back the -0700 in place of PDT.
Updated netlify.toml and set the environment variable in cloudflare and it appears to work now.
I still thing it's buggy behavior that I don't understand at all. My timezone without the TZ configuration was correct. It's also not something that is mentioned in any tutorial or documentation / build instructions for Cloudflare documentation that I can find.
At least it can easily be mitigated.
I just tested the workaround and it only works for single language/timezone sites. If a site is multilingual and the relative timezone of the language is different from the TZ environment variable, it won't work for those.
In my test site (https://hugo-test-site.pages.dev) I set the TZ env to /usr/share/zoneinfo/Asia/Manila
and the language that matched Asia/Manila
started to show the correct MST value which is PST
.
However, in the JA and KO languages, it still shows +0900
instead of JST
and KST
respectively, even though the system is capable of displaying the correct MST value.
Tested in Cloudflare Pages, haven't tested in Github Pages but probably will be the same result.
Note: The checkmark or x-mark shown in the test site are automatically generated on build if it matches the expected field. The source for the test site is at: GitHub - techmagus/hugo-test-site: YourOnly.One's Hugo Test Site
Also posted here: Hugo Discourse thread
Cloudflare did inform me to use Asia/Manila
and not the /usr/share path, I think I fat fingered that in a copy paste out of my Netlify docs. But, both worked to solve my...problem. Which was probably solved by just enforcing any timezone at all. It's over my head. I can't find a lot of documentation or tutorials on the subject involving timezone setup with cloudflare.
https://community.cloudflare.com/t/hugo-timezone-format-issue/390678
https://community.cloudflare.com/t/re-timezone-format-issue/391130
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master
branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.