Date, Time and Time Zone

This document registers tags for serializing date, time of day and a time zone designator in Concise Binary Object Representation (CBOR) (ref. 1).

Date

Time

Time Zone

Introduction

Many areas of daily life require date and time information. For example, birthdays or opening hours. CBOR tag 1 provides only a coding for time points. A major disadvantage is that a specific date or time can only be interpreted in conjunction with a time zone or a UTC offset. This document proposes two new tags so that the date and time can be encoded individually.

A date consists of three components: year, month and day.

A time consists of 2 to 4 components. Hour, minute, optional second, optional fractional second.

In addition, a tag is specified for the coding of a IANA time zone designator.

Some programming languages have built-in support for date, time or time zone objects. C++ has a proposal to add support to its standard library. (As of 2019)

Detailed Semantics

A date in CBOR has tag 100 and is encoded as a positive or negative integer or a text string. The integer counts the days since 1970-01-01. The text string encodes the date in ISO 8601 format "YYYY-MM-DD".

A time of day in CBOR has tag 116 and is encoded as a positive integer or a floating point number or a text string. The integer and floating point number encode the (fractional) seconds since midnight. The text string encodes the time in ISO 8601 format "hh:mm", "hh:mm:ss" or "hh:mm:ss.sss". The last one contains fractional seconds "sss". Fractional seconds have at least 1 decimal place and are not limited to any length.

A time zone has the tag 122 and is encoded as a text string.

A CBOR decoder can treat data items with tag 100, 116 or 122 that don't meet the criteria above as an error, but this specification doesn't define how a CBOR implementation ought to behave in this case. Section 3.4 of RFC 7049 (ref. 1) details this kind of error-handling behavior.

Example

The following example shows how the date 2018-12-31 is encoded.

  D8 64         # tag(100)
     19 45E8    # unsigned(17896)

The following example shows how the time 12:00:05 is encoded.

  D8 74         # tag(116)
     19 A8C5    # unsigned(43205)

The following example shows how the time zone "America/New_York" is encoded.

  D8 7A                                  # tag(122)
     70                                  # text(16)
	416D65726963612F4E65775F596F726B # "America/New_York"

References

Ref. 1. Bormann, C. and Hoffman, P. "Concise Binary Object Representation (CBOR)". RFC 7049, October 2013.

Author

Jörg Richter (joerg.richter at pdv-fs dot de)

Any copyright to this specification is released to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/