google / google/cctz

parse(civil_second)

Open
#36 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
654
Forks
178
Avg merge
4d 22h
Merged PRs (30d)
6

Description

Hi,

There are cases where first parsing a std::chrono time point and then converting it to cctz::civil_second is cumbersome.

As an example, when parsing the time of day "07:30:12.123" for a calendar, or a recurring event, it is currently required to first parse the absolute time and then try to get rid of the date offset, and time zone shift.

A quick glance in cctz.git/src/time_zone_format.cc suggests that parse() generates a civil_second anyway, before converting to an absolute time.

Might it make sense to expose this to the API, for example by splitting cctz::parse() in two functions? Conceptually, like this:

```
bool cctz::parse (const std::string& format, const std::string& input,
const time_zone& tz, cctz::civil_second* cs,
std::chrono::nanoseconds* ns) {
/* Mostly the current implementation in cctz.git/src/time_zone_format.cc,
* but returning cs and _not_ calling ptz.lookup().
*/
}

bool cctz::parse (const std::string& format, const std::string& input,
const time_zone& tz, time_point* sec,
std::chrono::nanoseconds* ns) {
cctz::civil_second cs;
bool retval = cctz::parse(format, input, tz, &cs, ns);
*sec = cctz::convert(cs, tz);
return retval;
}

```

What do you think?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.