You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application that transforms between string and time.Time values using Format and Parse along with time.UnixDate. The application runs as a combination of AMD64 and WebAssembly (Go js/wasm), and it goes back and forth between these representations. A client who uses Chrome on macOS has found that Format will create strings Parse cannot parse. Here is an example:
Thu May 1 20:00:36 -0500 2025
(On the platforms I have direct access to, Format always produces CDT, not -0500.)
The problem comes when parsing. For the example that uses -0500, calling Parse with time.UnixDate causes the following error: parsing time "Thu May 1 20:00:36 -0500 2025" as "Mon Jan _2 15:04:05 MST 2006": cannot parse "-0500 2025" as "MST". Here is an example that shows this:
package main
import (
"fmt"
"time"
)
func main() {
s := "Thu May 1 20:00:36 -0500 2025"
_, err := time.Parse(time.UnixDate, s)
if err != nil {
fmt.Println(err)
}
}
I have not yet been able to reproduce the Format side of this, that is, the process that results in a string with -0500. However, these comments in the Go source lead me to believe it is possible, depending on the platform:
Go version
go version go1.24.2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I have an application that transforms between
string
andtime.Time
values usingFormat
andParse
along withtime.UnixDate
. The application runs as a combination of AMD64 and WebAssembly (Go js/wasm), and it goes back and forth between these representations. A client who uses Chrome on macOS has found thatFormat
will create stringsParse
cannot parse. Here is an example:Thu May 1 20:00:36 -0500 2025
(On the platforms I have direct access to,
Format
always producesCDT
, not-0500
.)The problem comes when parsing. For the example that uses
-0500
, callingParse
withtime.UnixDate
causes the following error:parsing time "Thu May 1 20:00:36 -0500 2025" as "Mon Jan _2 15:04:05 MST 2006": cannot parse "-0500 2025" as "MST"
. Here is an example that shows this:I have not yet been able to reproduce the
Format
side of this, that is, the process that results in a string with-0500
. However, these comments in the Go source lead me to believe it is possible, depending on the platform:https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/time/format.go;l=820
https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/time/zoneinfo_js.go;l=27
These comments seem to corroborate the claim of my client.
What did you see happen?
Under some circumstances,
Parse
will not process something created withFormat
, even when using the same layout string.What did you expect to see?
My expectation was that
Parse
could parse anythingFormat
produced, assuming the layout string is the same.The text was updated successfully, but these errors were encountered: