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

parse(civil_second) #36

Open
Siesh1oo opened this issue Nov 26, 2016 · 2 comments
Open

parse(civil_second) #36

Siesh1oo opened this issue Nov 26, 2016 · 2 comments

Comments

@Siesh1oo
Copy link

Siesh1oo commented Nov 26, 2016

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<sys_seconds>* 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?

@floatdrop
Copy link

floatdrop commented Nov 30, 2016

I would also add format(format, civil_time, time_zone) shortcut also to pair parse(civil_second) method.

@Siesh1oo
Copy link
Author

Yes, this would be very useful indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants