hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Date format / timezone issue after remote build

Open willduncanphoto opened this issue 2 years ago • 9 comments

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.

Screenshot_20220612T005802@2x

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?

willduncanphoto avatar Jun 12 '22 08:06 willduncanphoto

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.

bep avatar Jun 12 '22 09:06 bep

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:

Screenshot_20220612T031435@2x

On Cloudflare/Netlify builds:

Screenshot_20220612T031351@2x

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.

willduncanphoto avatar Jun 12 '22 10:06 willduncanphoto

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.)~

satotake avatar Jun 12 '22 10:06 satotake

Tested on netlify. See this.

satotake avatar Jun 12 '22 12:06 satotake

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

techmagus avatar Jun 13 '22 06:06 techmagus

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.

willduncanphoto avatar Jun 13 '22 06:06 willduncanphoto

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

techmagus avatar Jun 13 '22 09:06 techmagus

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.

willduncanphoto avatar Jun 15 '22 08:06 willduncanphoto

https://community.cloudflare.com/t/hugo-timezone-format-issue/390678

https://community.cloudflare.com/t/re-timezone-format-issue/391130

willduncanphoto avatar Jun 16 '22 07:06 willduncanphoto

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.

github-actions[bot] avatar Jun 17 '23 01:06 github-actions[bot]

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.

github-actions[bot] avatar Sep 03 '23 01:09 github-actions[bot]