When some pages have dates without timezones, and some with timezones, the page ordering looks incorrect. The pages with only dates, or dates+times get interpreted as UTC times. This can cause a page with date = "2016-02-18T20:00:00-05:00" to appear as a later post than a page with date = "2016-02-19".
If you understand what's happening under the hood, you can see why, but for a non-developer, or even one that doesn't understand this specific implementation quirk, that posts to inexplicably appear in an incorrect order. Intuitively, 2016-02-19 would refer to a date, not specifically midnight on that date in England.
The library that hugo uses to parse dates (spf13/cast) will parse these date formats that don't include a timezone:
2006-01-02T15:04:05Mon Jan _2 15:04:05 20062006-01-02 _(This one is what a user would get if they manually cut off the time portion of the date. That's how I stumbled on this issue.)_02 Jan 2006There are probably a few ways to make the behavior more friendly. I don't have an opinion on these, I'm just throwing out suggestions:
hugo tool, insert a date without a timezone, so that it will also end up in UTC, like a date entered manually by the user without a timezone. _(This would be a half-measure, since any pages created with an older version of hugo would have timezones, as well as any dates manually entered with timezones by the user. Although, for going forward, it would mitigate the quirks that might results from the other solutions.)_When parsing pages, detect date values that did not include a timezone and explicitly put them into the local timezone of the user, maybe with a user-configurable site-wide default timezone.
I think this is the best solution to this.
I'm not sure where this needs to happen (spf13/cast?), but we can use time.ParseInLocation. It respects timezone info if it's in the string, but you can pass in a default. We can use time.Local as the default.
@moorereason we need to have a specified timezone in config (and maybe also as overriden in the page front matter). Once we have this we can say:
We should probably extend cast with another method to solve this, but the current method is a little bit of a convenience method.
That's what I was thinking, too, but I'm more concerned with how we customize the unmarshaler. BurntSushi/toml can do that, but I don't know about YAML, and JSON.
I had started a change for this in spf13/cast, but I haven't had time to wrap it up & submit a PR. I'll try to get that done Sunday or Monday. There are a few issues with using time.ParseInLocation. I'll bring those up in that PR, plus tests to validate correct behavior.
On the hugo side, @bep, 1 & 2 in your sequence sound reasonable. What do you think of using local timezone in step 3, though? I wonder what portion of Hugo users explicitly want times for their blog posts to be UTC, and of that small group of people, how many of them aren't already listing date values with timezones.
Another benefit of defaulting to local (when no explicit timezone), is that the hugo tool generates pages with local times. So if a user overrides just one of those pages to a a time without a zone, then hugo defaulting to local timezone would keep that page's time consistent with all the other ones.
So if a user overrides just one of those pages to a a time without a zone, then hugo defaulting to local timezone would keep that page's time consistent with all the other ones.
Yes, that makes sense.
This issue has been automatically marked as stale because it has not been commented on for at least four months.
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 valuable, please open a proposal at https://discuss.gohugo.io/.
This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.
Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.
If this is a bug and you can still reproduce this error on the latest release or 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.
So, we have https://github.com/spf13/cast/pull/80 which I have tested and that makes sense to me. But when I started to implement this in Hugo I figured out I have no idea how.
time.Time I'm cluelessTextUnmarshaler interfaces etc., but I have no idea how to do that with a dynamic map schema. Even if we had fixed structs for all, there is a problem with where to store the location.If anyone smarter than me could come up with something that works, I would be happy camper.
Hey @bep. Wondering if it would be possible to include this functionality? I noticed there were a few small template sample on the forums that showcased loading the TZ data in Go. Doesn't seem like this would take a whole lot of work to at least add a couple of methods. (Although, that is usually never the case).
Specifically, need capability to:
1) Load a Date/Time with a specific Timezone
(e.g. Build a Date from front matter using MM/YY/DD and HH:MM and timezone "America/Los_Angeles" - note front matter user doesn't know diff between PST/PDT - but output would handle accordingly)
2) Modify the Date object by setting a new timezone (such that it can be output in a custom timezone).
(e.g. Modify result from step 1 now setting to "America/New_York" and then outputting, expecting a result modified by 3 hours with now EST/EDT)
In the above case assume this is repeated for varying timezones, thus setting the system timezone would not work for step 1.
@virgofx,
The scope of this issue is larger than what I think you're asking for. It sounds like you are interested in additional template functions under the time namespace (godocs). If so, I'd recommend opening a separate issue.
You're right. Proper TZ support likely includes a lot more. I'd love additional output formatting options as referenced above. I'll open up another PR.
@heewa The latest PR which added Timezone/Location support to the time function should resolve your issue in the next release (0.77). I realize it's not "full timezone" support but I think it would help. Full Timezone support could be a very very large task and I'm thinking that if the latest merged PR fixes your issue and mine ... it would suffice for this project and we could close this.
Thoughts?
it would suffice for this project and we could close this.
This is still needed.
Most helpful comment
This is still needed.