Nanosecond civil_time

24 views
Skip to first unread message

rafaelef...@gmail.com

unread,
Jul 12, 2017, 11:19:47 PM7/12/17
to cctz
Hi,

Clock sources provide nanosecond level precision. There are use cases where you want to keep nanoseconds component with civil_time. The simplest one that comes to mind is logging. However, cctz doesn't offer the ability to store the nanosecond component of time as part of the object. As a result, I would be forced to write a wrapper around civil_time to achieve this. For comparison, chrono does offer milli, micro, and nanosecond durations. Boost Date Time also offers nanosecond representation in ptime. I am wondering why isn't there a nanosecond civil_time? Can it be added?

Thank you,
-Rafael

Greg Miller

unread,
Jul 13, 2017, 9:04:33 AM7/13/17
to rafaelef...@gmail.com, cctz
On Wed, Jul 12, 2017 at 11:19 PM, <rafaelef...@gmail.com> wrote:
Hi,

Clock sources provide nanosecond level precision. There are use cases where you want to keep nanoseconds component with civil_time. The simplest one that comes to mind is logging. However, cctz doesn't offer the ability to store the nanosecond component of time as part of the object. As a result, I would be forced to write a wrapper around civil_time to achieve this. For comparison, chrono does offer milli, micro, and nanosecond durations. Boost Date Time also offers nanosecond representation in ptime. I am wondering why isn't there a nanosecond civil_time? Can it be added?


Could it be added? Yes. The reason we haven't added it is that we haven't actually seen the need for it yet. In the case of your example, logging, presumably you want to be logging an absolute time, not a civil time. That is, the input to your logging function would be a std::chrono::time_point (or equivalent), and as you indicated that indeed can be logged with subsecond precision, see https://github.com/google/cctz/blob/master/include/time_zone.h#L221.

So my guess is that if you suspect you need subsecond precision, you probably are actually dealing with absolute times, not civil times. See https://github.com/google/cctz/wiki/FAQ#what-is-an-absolute-time for a description of these terms as I'm using them here.

HTH,
Greg
 

Thank you,
-Rafael

--
https://github.com/google/cctz
---
You received this message because you are subscribed to the Google Groups "cctz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cctz+unsubscribe@googlegroups.com.
To post to this group, send email to cc...@googlegroups.com.
Visit this group at https://groups.google.com/group/cctz.
To view this discussion on the web visit https://groups.google.com/d/msgid/cctz/9dc83d17-5d70-4a7c-9015-e596969787f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages