Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in TOML LocalDate Format Support #9949

Open
xM8WVqaG opened this issue May 29, 2022 · 2 comments
Open

Regression in TOML LocalDate Format Support #9949

xM8WVqaG opened this issue May 29, 2022 · 2 comments

Comments

@xM8WVqaG
Copy link

What version of Hugo are you using (hugo version)?

  • Regression introduced in hugo v0.87.0-B0C541E4 linux/amd64 BuildDate=2021-08-03T10:57:28Z VendorInfo=gohugoio
  • Regression exists in hugo v0.99.1-d524067382e60ce2a2248c3133a1b3af206b6ef1 linux/amd64 BuildDate=2022-05-18T11:18:14Z VendorInfo=gohugoio
  • Last confirmed release where this pattern works is hugo v0.86.0-41C6C52E linux/amd64 BuildDate=2021-07-21T09:53:14Z VendorInfo=gohugoio

Issue

This is quite a minor issue as there is a solution. Feel free to close this if I've misunderstood and this isn't a valid regression.

In Hugo before v0.87 you could use the .Format method on a toml.LocalDate date. Since then with the new TOML backend and updated .Format functionality it errors.

For hugo <= 0.86, given the toml:

date = 2021-10-19

This template renders correctly:

{{ with index . "date" }}
  <dt class="cite__key">Date</dt>
  <dd class="cite__value">
    <time
        datetime='{{ .Format "2006-01-02" }}'>
      {{ .Format "2006-01-02" }}
    </time>
  </dd>
{{end}}

From hugo >= 0.87 it errors with:

Error: Error building site: failed to render pages: render of "page" failed: "/path/to/hugo/template.html:42:25": execute of template failed: template: hugo/template.html:42:25: executing "main" at <.Format>: can't evaluate field Format in type toml.LocalDate

However, calling time.Format directly and passing in toml.LocalDate as an argument does correctly render.

{{ with index . "date" }}
  <dt class="cite__key">Date</dt>
  <dd class="cite__value">
    <time
        datetime='{{ time.Format "2006-01-02" . }}'>
      {{ time.Format "2006-01-02" . }}
    </time>
  </dd>
{{end}}

Shouldn't toml.LocalDate (which can be coerced into a time.Time) be treated as a just like regular a TOML Offset Date-Time (which I think are automatically time.Time in go-toml).

@bep bep removed the NeedsTriage label May 29, 2022
@bep bep added this to the v0.100.0 milestone May 29, 2022
@bep bep assigned bep and unassigned bep May 29, 2022
@bep bep added the Upstream label May 29, 2022
@bep
Copy link
Member

bep commented May 29, 2022

I don't think we can/want to fix this, though.

@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.104.0, v0.105.0 Sep 23, 2022
@bep bep modified the milestones: v0.105.0, v0.106.0 Oct 26, 2022
@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Dec 3, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.110.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@jmooring
Copy link
Member

jmooring commented Nov 22, 2023

When using toml.LocalDate and toml.LocalDateTime values in the four predefined front matter date fields, the values are converted to time.Time, so the .Format method works as expected.

This issue is limited to custom front matter date fields, and date values from local and remote data files.

As noted here, it would be nice if pelletier/go-toml had an option to unmarshal toml.LocalDate and toml.LocalDateTime to time.Time in UTC. Or we walk the tree and do it ourselves.

We've had to make adjustments here and there to accommodate toml.LocalDate and toml.LocalDateTime values:

It would be nice if we could just handle it while unmarshaling.


I've clarified the time.Format documentation here.

@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants