gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.07k stars 7.48k forks source link

Update to gopkg.in/yaml.v3 #8822

Open bep opened 3 years ago

bep commented 3 years ago

Add this to have something to track this with.

The main blocker I see for this is that it's not possible to control location/timezone for dates without that information.

package main

import (
    "fmt"
    "log"

    v2 "gopkg.in/yaml.v2"
    v3 "gopkg.in/yaml.v3"
)

var data = `
d: 2021-07-15

`

func main() {
    mv2 := make(map[string]interface{})
    err := v2.Unmarshal([]byte(data), &mv2)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    fmt.Printf("--- mv2: %T %v \n", mv2["d"], mv2["d"])

    mv3 := make(map[string]interface{})
    err = v3.Unmarshal([]byte(data), &mv3)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    fmt.Printf("--- mv3: %T %v \n", mv3["d"], mv3["d"])
}

Prints:

--- mv2: string 2021-07-15 
--- mv3: time.Time 2021-07-15 00:00:00 +0000 UTC 

Note that v2 isn't perfect, either, but that at least allows us to handle known dates (e.g. the front matter dates).

bep commented 3 years ago

See https://github.com/go-yaml/yaml/issues/770

jmooring commented 7 months ago

Everyone once in a while a user gets burned by "on/off/yes/no" keys. This happened again yesterday. While I understand why this is blocked, I must say I have little sympathy for unqualified dates. If we could start over, or break some eggs, I'd place every unqualified date in Etc/UTC.