redjack/libcork — pull request #17 by dcreager (2013-11-21 18:53:23+00:00)
Title: Subsecond string representations from Cork timestamps

cork_timestamp_format_utc() and cork_timestamp_format_local() produce time strings with 1 second resolution. Internally, time is maintained with gamma second resolution (1 part in 2^32). It would be useful to provide support for higher resolution times.

At present, this requires appending the fractional representation to the string value returned by the above functions and may require "munging" the string if it contains an explicit time zone component. This could be subsumed into the basic functionality in several ways:

* Proliferate the number of function signatures to provide functions for each desired degree of precision.
* Extend the strftime format to include an explicit fractional second notation that indicated the precision desired, e.g %f (for fraction - lower case f is the first letter that is not already used in the strftime format) %f (or %1f) would display the time truncated to 0.1 second, %2f to 0.01 sec, etc.
* Add an explicit fractional units parameter to the functions. This could indicate the desired precision in decmal digits with 0 producing the current whole second values, 1 giving 0.1 second resolution, etc. This could be accompanied by an enum declaration in the .h file to provide symbolic definitions.
* If this approach is used, it might be useful to explicitly pass the indicator for time zone representation (UTC, local, or arbitrary) to the functions, as well allowing the format string to specify only the format down to the whole second. Note that the general practice for time values is to store them relative to the UTC beginning of the epoch. There are many cases where you want to display time in a time zone that is neither UTC (available with gmtime) nor the the time zone of the conversion (available with localtime). Having the ability to do this is desirable, even though it is not explicitly supported in the Unix time conversion functions.