Skip to content
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

12AM parsed as 12PM in US-format date string #1312

Closed
sc1f opened this issue Feb 2, 2021 · 1 comment
Closed

12AM parsed as 12PM in US-format date string #1312

sc1f opened this issue Feb 2, 2021 · 1 comment
Labels
bug Concrete, reproducible bugs good first issue A relatively simple issue JS

Comments

@sc1f
Copy link
Contributor

sc1f commented Feb 2, 2021

In strptime as compiled for Emscripten, when given the US locale string format ("%m/%d/%Y, %I:%M:%S %p"), it incorrectly parses "12:00:00 AM" as "12:00:00 PM". In order to fix this, we will need a custom-written string parser similar to the CustomISO8601Parser from arrow_csv.cpp. This parser uses the arrow::TimestampParser interface from Apache Arrow, and should be relatively easy to write and test out. A custom parser is required because the current issue manifests itself inside a call to strptime (especially strange, I know), and not due to any custom code.

One can reproduce the issue by adding this block of code to make_table inside emscripten.cpp (where it is guaranteed to run as part of Perspective's Table constructor):

        std::tm res;
        char* ret = strptime("3/1/2020, 12:30:55 AM", "%m/%d/%Y, %I:%M:%S %p", &res);
        if (ret != NULLPTR) {
            // parses to 2020/3/1 12:30:55, which is incorrect
            // should parse to 2020/3/1 00:30:55
            std::cout << "parsed using strptime: " << res.tm_year + 1900 << "/" << res.tm_mon + 1 << "/" << res.tm_mday << " " << res.tm_hour << ":" << res.tm_min << ":" << res.tm_sec << std::endl;
        }

Adding this same block of code in make_table in python/table.cpp generates the correct output. Tests to reproduce this issue are in #1310 - although more tests should be added to make sure no other edge cases are created.

For users, the best way to pass in datetime values is through new Date() - date strings will always be parsed as UTC.

@sc1f sc1f added bug Concrete, reproducible bugs good first issue A relatively simple issue JS labels Feb 2, 2021
@texodus
Copy link
Member

texodus commented Apr 15, 2021

@pawan521 You don't have to ask for permission, just take a crack at it and reply in this Issue have any questions. No task marked good first issue should really merit exclusivity, these are small tasks that won't suffer from potentially duplicate work - learning how Perspective works is worth the time anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Concrete, reproducible bugs good first issue A relatively simple issue JS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants