boostorg / boostorg/chrono

Incorrect results for time_point's operator >>

Open
#59 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
20
Forks
58
PR merge metrics
No merged PRs in 30d

Description

In case when no year or day of month is specified in the time format, stream extraction of a `time_point` will yield incorrect results. The reason for this is that struct `std::tm` is initialised in various places to all zeroes using `memset`, which is not correct, because in this struct day of month is counted from 1, not 0, and years are counted from 1900, not 1970. Therefore, if the fields are passed unmodified to `timegm` (which is the case when the parsed timestamp has no year or day in its format), the result will be off by the relevant differences.

For example, if "01" is parsed with time format "%S", the expected result would be 1970-01-01T00:00:01, but instead it's 1899-12-31T00:00:01.

Contributor guide

No contributing guide indexed for this repository

Research direction

Trace stream extraction for time_point where the format omits the year or day, focusing on the std::tm initialization and the timegm call described in the issue. Reproduce the "%S" example and verify that an input such as "01" produces 1970-01-01T00:00:01 rather than the incorrect 1899 result.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.