perspective icon indicating copy to clipboard operation
perspective copied to clipboard

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

Open sc1f opened this issue 4 years ago • 2 comments

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 avatar Feb 02 '21 01:02 sc1f

Can i work on this??

Vipul2504 avatar Apr 14 '21 13:04 Vipul2504

@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!

texodus avatar Apr 15 '21 01:04 texodus