wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.25k stars 1.21k forks source link

Dates passed from JS to wails change timezone #2784

Open YairLevi opened 1 year ago

YairLevi commented 1 year ago

Description

Couldn't find someone who specified this issue yet. When I send a Date type to wails from the JS, it changes the time (zone). for example, I send 20:00 (not the current time, just any time at all), and when i print the time in the js its the same, but the moment wails receives it from the frontend, it turns to 17:00, UTC. why is this happening and how can I fix this?

To Reproduce

  1. Create default wails app (react)
  2. add function to boilerplate App struct:
    func (a *App) SendDate(time time.Time) {
    fmt.Println(time)
    }
  3. add simple click to send date:
    // e.g., button in component
    return (
    <div>
      <button onClick={() => SendDate(new Date())}>Click to send date</button>
    </div>
    )
  4. click the button and watch go print different time.

Expected behaviour

I expect the time to remain unchanged when it reaches wails.

Screenshots

No response

Attempted Fixes

No response

System Details

# System

OS           | Windows 10 Pro
Version      | 2009 (Build: 19044)
ID           | 21H2
Go Version   | go1.18.4
Platform     | windows
Architecture | amd64

# Wails

Version | v2.5.1

# Dependencies

Dependency | Package Name | Status    | Version      
WebView2   | N/A          | Installed | 114.0.1823.86
Nodejs     | N/A          | Installed | 16.16.0
npm        | N/A          | Installed | 8.11.0
*upx       | N/A          | Available | 
*nsis      | N/A          | Available | 
* - Optional Dependency

Additional context

No response

leaanthony commented 1 year ago

Did you try explicitly setting the TZ in Go?

YairLevi commented 1 year ago

Did you try explicitly setting the TZ in Go?

Do you mean using the .In(...) function? if so, I did. Also tried changing the time.Local like a solution suggested, and didn't work (made sure to put the right location.

When I printed time.Now() it prints the current time in my local zone correctly, but when I send a Date from frontend to wails, it changes it to UTC.

mooijtech commented 1 year ago

JavaScript Date uses ISO 8601 if I remember correctly. As in new Date will accept this format.

Possibly this could work (try also without UTC()): time.Now().UTC().Format("2006-01-02T15:04:05Z07:00")