Skip to content

parse(civil_second) #36

Description

@Siesh1oo

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions