Skip to content

put_time returning time zone as "Easter" #21582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jrobichaux opened this issue Mar 21, 2024 · 8 comments · Fixed by #21585
Closed

put_time returning time zone as "Easter" #21582

jrobichaux opened this issue Mar 21, 2024 · 8 comments · Fixed by #21585

Comments

@jrobichaux
Copy link

In the latest emscripten, a call to std::put_time( std::localtime(&t_time), "%Z" ) on my Windows machine returns "Easter" instead of "Eastern Daylight Time".

This worked properly on the previous version I was using (3.1.51).

Minimal repro:

time_test.cpp

#include <ctime>
#include <iomanip>
#include <iostream>

int main()
{
	std::time_t t_time = std::time( NULL );
	std::cout << "time zone = " << std::put_time( std::localtime(&t_time), "%Z" ) << std::endl;
	return 0;
}

Compile with:
em++ time_test.cpp

Run with:
node a.out.js

On my machine (Windows 10) this returns "time zone = Easter". If I compile as a standard Windows executable it properly returns "time zone = Eastern Daylight Time".

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.56 (cf90417346b78455089e64eb909d71d091ecc055)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 34ba90745fa55777436a2429a51a3799c83c6d4c)
Target: wasm32-unknown-emscripten
Thread model: posix
@sbc100
Copy link
Collaborator

sbc100 commented Mar 21, 2024

I believe this is due to #21375.

The max number of chars in timezone name in POSIX is defined to be 6 (

#define _POSIX_TZNAME_MAX 6
) and musl's internal data structures use this limit.

If we could fix node on windows to give the abbreviated name (EDT) would that be enough to fix your issue? Or do you really need/want to full unabbreviated name?

@jrobichaux
Copy link
Author

Wow, fast answer. Abbreviated name works for me, that's what we're getting on iOS and Mac already.

Thanks!

@sbc100
Copy link
Collaborator

sbc100 commented Mar 21, 2024

Sadly I couldn't find any easy way to get such names on windows :(

BTW is node your target environment or it the browser? Do you know if the same results are produced when running the browser on windows?

@jrobichaux
Copy link
Author

It's a browser app. I get the same (Easter) when I run it on Chrome in Windows.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 21, 2024

OK, in that case I think we need to increase out TZNAME_MAX so allow for these windows timezone names.

sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 21, 2024
sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 21, 2024
@jrobichaux
Copy link
Author

jrobichaux commented Mar 21, 2024

If it helps, the TIME_ZONE_INFORMATION struct uses a max length of 32 for Windows timezone names.

Ironically the example on that page shows a return value of "EST" for the StandardName and DaylightName, but when I call GetTimeZoneInformation I get the full "Eastern Daylight Time".

sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 21, 2024
@sbc100
Copy link
Collaborator

sbc100 commented Mar 21, 2024

Thanks @jrobichaux , do you happen to know if there is any way to access the StandardName on the web or under node? I'm guessing the answer is no?

sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 21, 2024
sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 21, 2024
Without this change then timezone names will be the long form (Pacific
Standard Time) rather than the short form (PST), and since TZNAME_MAX
in musl is 6 (same in POSIX) the long names were getting truncated.

Fixes emscripten-core#21582
sbc100 added a commit to sbc100/emscripten that referenced this issue Mar 22, 2024
Without this change then timezone names will be the long form (Pacific
Standard Time) rather than the short form (PST), and since TZNAME_MAX
in musl is 6 (same in POSIX) the long names were getting truncated.

Fixes emscripten-core#21582
sbc100 added a commit that referenced this issue Mar 22, 2024
Without this change then timezone names will be the long form (Pacific
Standard Time) rather than the short form (PST), and since TZNAME_MAX
in musl is 6 (same in POSIX) the long names were getting truncated.

Fixes #21582
@jrobichaux
Copy link
Author

do you happen to know if there is any way to access the StandardName on the web or under node? I'm guessing the answer is no?

Not that I know of. I was just thinking if you were going to increase the size of TZNAME_MAX then 32 should be a good number.

But I saw what you did in #21585 by using Javascript directly, and that's a good/clever workaround. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants