Skip to content

std::time_put does not properly handle "%Ec" format #22050

@hly2019

Description

@hly2019

Please include the following in your bug report:

Version of emscripten/emsdk:
3.1.54

Failing command line in full:

# emcc:
emcc locale_Ec.cpp  -o main.js
node main.js

# g++:
g++ locale_Ec.cpp  -o main
./main

Hi, it seems the std::time_put doesn't handle properly with the formatting %Ec in Emscripten. For example, the code shown below produces a result "%c", which seems incorrect and meaningless.

I'd appreciate it if you could please check this issue. Thank you!

Code

#include <sstream>
#include <locale>
#include <chrono>
#include <iostream>
#include <string.h>
int main() {
    std::wstring format = L"%Ec";
    auto t_now = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
    auto t = std::chrono::system_clock::to_time_t(t_now);
    std::tm tm = *std::gmtime(&t);
    auto loc = std::locale::classic();
    const std::time_put<wchar_t>& timeput = std::use_facet<std::time_put<wchar_t>>(loc);
    std::wostringstream os;
    os.imbue(loc);
    timeput.put(os, os, L' ', &tm, format.c_str(), format.c_str() + format.size());
    std::wcout << "error?: " << strerror(errno) << std::endl;
    std::wcout << "value of os.str: "<< os.str() << std::endl;
    return 0;
}

Results:

# in wasm:
error?: No error information
value of os.str: %c

# in native:
error?: Success
value of os.str: Tue Jun  4 03:56:58 2024

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions