chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Invalid local timezone in WASM

Open nitnelave opened this issue 4 years ago • 3 comments

Hello,

I'm using chrono in WASM. My local timezone is UTC+2, but I get the same string twice when running this code:

let date : chrono::DateTime<Utc> = ...;
println!("{}", date);
println!("{}", date.with_timezone(&chrono::Local));

It seems that the local timezone is wrong when running in WASM. I tried both on Chrome and Firefox. I'm on Linux if it's relevant. I'm using chrono 0.4.19.

nitnelave avatar Aug 31 '21 07:08 nitnelave

Did you activate the wasmbind feature?

CryZe avatar Aug 31 '21 08:08 CryZe

That was indeed the issue. Should there be a compilation warning, or a panic when using the Local timezone without this feature? Rather than doing the wrong thing silently.

nitnelave avatar Aug 31 '21 11:08 nitnelave

Just ran into this same issue, and I can confirm that the behaviour is rectified with the use of the wasmbind feature, with an essentially identical set up to OP.

It's slightly peculiar, because I'm sure it was showing the correct offset a few days/couple of weeks ago...

Anyway, I agree that some sort of warning would be better than silently producing the wrong behaviour. I'm not sure how this could be programatically detected, though.

mfreeborn avatar Apr 30 '22 11:04 mfreeborn

The wasmbind feature is enabled by default since https://github.com/chronotope/chrono/pull/771.

pitdicker avatar Jun 07 '23 14:06 pitdicker