Skip to content

Store a timezone #16

@JeffAbrahamson

Description

@JeffAbrahamson

This may be a question about how to use the library rather than an issue. If so, many thanks for a pointer in the right direction.

I receive strings representing time and then store absolute time (in protobufs as int64):

// Time zone is required by cctz::Parse().  It is only used if the
// formatted time does not include offset info.
const auto utc = cctz::UTCTimeZone();
const char kFmt[] = "%Y-%m-%dT%H:%M:%E*S%Ez";
system_clock::time_point this_time_point;
if (!cctz::Parse(kFmt, date_str, utc, &this_time_point)) {
    cout << "Failed to parse time: " << date_str << endl;
    return 0;
}
return system_clock::to_time_t(this_time_point);

This works great. From time to time, I need to know local time for the original source. That is, I've received something like 2015-12-23 10:55:09+0100 and stored 1450864509. Now, in another process on another day, I see 1450864509 and want to recover 10:55 (i.e., for this absolute time, the corresponding local time was 10:55. For a concrete mental image, suppose I'm analysing when events correspond to lunchtime.

Of course, I can (outside of cctz) parse out the UTC offset and store that. I could also simply parse out the "HH:MM" string and store that. But those both seem quite wrong, and cctz seems well enough thought through that I'm guessing there's some way I haven't understood to persist an idea of a timezone.

And, if not, I suggest that this would be useful.

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