'Why golang time.Parse supports fractional seconds even the formatString does not have them?

this code:

fmt.Println(time.Parse("2006-01-02T15:04:05", "2020-01-26T08:02:29.9"))

(https://go.dev/play/p/w1eZNdVgse4)

prints: 2020-01-26 08:02:29.9 +0000 UTC

It does not have fractional seconds in the format but they are still going though. Anyone any idea is there some reason to this. the source: https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/time/format.go;l=1075;drc=refs%2Ftags%2Fgo1.18

go


Solution 1:[1]

According to the documentation for time.Parse:

When parsing, if the seconds value is followed by a decimal point and some digits, that is taken as a fraction of a second even if the layout string does not represent the fractional second.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Burak Serdar