You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Kevin Townsend <ke...@adafruit.com> on 2016/11/08 08:37:18 UTC

ISO8601 Timestamps

Would it make sense to add support to datetime.c/h to convert to and 
from ISO8601 timestamps, which are much more convenient to display since 
you can use a struct like this to print the values directly in the 
shell, etc.:

    typedef struct ATTR_PACKED
    {
         char year[4];        /**< Year         */
         char dash1;          /**< Dash1        */
         char month[2];       /**< Month        */
         char dash2;          /**< Dash2        */
         char day[2];         /**< Day          */
         char T;              /**< T            */
         char hour[2];        /**< Hour         */
         char colon1;         /**< Colon1       */
         char minute[2];      /**< Minute       */
         char colon2;         /**< Colon2       */
         char second[2];      /**< Second       */
         char decimal;        /**< Decimal      */
         char sub_second[6];  /**< Sub-second   */
         char Z;              /**< UTC timezone */

         char nullterm;       // not part of the format, make printf easier
    } iso8601_time_t;

* Ignore the typedef etc. which breaks the mynewt rules, this is copied 
from another project.

Maybe something like *_to_iso8601 and iso8601_to_*, converting between 
epoch and iso8601 etc.

This just has the advantage of being able to print human readable 
timestamps in a well-defined format: https://en.wikipedia.org/wiki/ISO_8601

The way the typedef is formatted above means you can just print data 
directly and get something like this: *2016-11-08T07:24:30.123456Z* 
which can in turn be understand by most other systems.

Just curious if this adds enough value to be included or if epoch is 
generally preferable as the sole time keeping units in the core codebase.

K.


Re: ISO8601 Timestamps

Posted by Oleg Hahm <ol...@inria.fr>.
Hi Kevin!

On Tue, Nov 08, 2016 at 09:37:18AM +0100, Kevin Townsend wrote:
> Would it make sense to add support to datetime.c/h to convert to and from
> ISO8601 timestamps, which are much more convenient to display since you can
> use a struct like this to print the values directly in the shell, etc.:
> 
>    typedef struct ATTR_PACKED
>    {
>         char year[4];        /**< Year         */
>         char dash1;          /**< Dash1        */
>         char month[2];       /**< Month        */
>         char dash2;          /**< Dash2        */
>         char day[2];         /**< Day          */
>         char T;              /**< T            */
>         char hour[2];        /**< Hour         */
>         char colon1;         /**< Colon1       */
>         char minute[2];      /**< Minute       */
>         char colon2;         /**< Colon2       */
>         char second[2];      /**< Second       */
>         char decimal;        /**< Decimal      */
>         char sub_second[6];  /**< Sub-second   */
>         char Z;              /**< UTC timezone */
> 
>         char nullterm;       // not part of the format, make printf easier
>    } iso8601_time_t;
> 
<snip>
>
> Just curious if this adds enough value to be included or if epoch is
> generally preferable as the sole time keeping units in the core codebase.

Just my 2 cents:
IMO it seems not advisable to "waste" 28 bytes (if I counted correctly) for a
simple 32 bit timestamp on a memory constrained device. I would always
outsource this type of convenience operations to backend tools. Even for
debugging this seems to be kind of huge.

Cheers,
Oleg
-- 
panic("Unable to find empty mailbox for aha1542.\n");
        linux-2.2.16/drivers/scsi/aha1542.c