Three Standard Types are available for encoding dates and times:
- a date on its own
- a time on its own
- a combined date with a time
Date
This part of the specification is in a draft state and open to discussion.
A date is encoded as a 4 byte integer of the form YYYYMMDD. For example 6 January 2010 is represented as the integer 20100106 (hex 0132B40A). This gives an effective date range of 10,000 years.
Clearly some values are not valid dates, for example 20090231. A compliant system MUST NOT reject or ignore invalid date fields. The original value MUST be preserved within the Fudge message. When converting to a language implementation's native date type for application level processing, the value MUST be converted to the next valid day (the next highest integer that represents a valid date) or trigger an error condition if there is no next valid day (e.g. if 99991232 were received).
Time
This part of the specification is open to discussion.
Combined date and time
This part of the specification is in a draft state and open to discussion.
Fudge date/time encoding aims to support most language implementations whilst addressing some of the common issues. In summary:
- 12-byte encoding.
- Up to nanosecond precision for times.
- Optional support for timezone offset information.
- Ability to truncate resolution, including date-only representation (as distinct from midnight on a particular date).
- Date range of +/- 4 million years.
Fudge date/time fields are represented as follows:
| Bytes | Meaning | Encoding |
|---|---|---|
| 0 | Options | Bitmask - see below |
| 1 | Timezone offset | Offset from UTC in 15-minute intervals |
| 2-7 | Seconds from epoch | Signed 64-bit integer |
| 8-11 | Nanoseconds | Unsigned 32-bit integer |
- Epoch is defined as 1 Jan 1970.
- Timezone examples:
GMT Greenwich Mean Time London UTC+0H 0 CET Central European Time Frankfurt UTC+1H 4 PST Pacific Standard Time LA UTC-8H -32 ACST Australian Central Standard Time Darwin UTC+9:30H 38
The options bitmask is encoded as follows:
| Bits | Meaning |
|---|---|
| 0 - 4 | Accuracy |
| 5 | Timezone specified |
| 6 - 7 | Unused |
Accuracy is an enumeration (ordered to follow the English semantics of "greater" precision meaning smaller):
- 0 = Century
- 1 = Year
- 2 = Month
- 3 = Day (this is the one to use for a pure date with no time component)
- 4 = Hour
- 5 = Minute
- 6 = Second
- 7 = Millisecond
- 8 = Microsecond
- 9 = Nanosecond
