package octez-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a
doc/octez-libs.base/Tezos_base/Time/Protocol/index.html
Module Time.Protocol
Source
Protocol time
The out-of-protocol view of in-protocol timestamps. The precision of in-protocol timestamps are only precise to the second.
Note that the out-of-protocol view does not necessarily match the in-protocol representation.
The type of protocol times
The first instant supported by RFC 3339, corresponds to 0000-01-01 00:00:00 +0000 (UTC).
The last instant supported by RFC 3339, corresponds to 9999-12-31 23:59:59 +0000 (UTC).
include Tezos_stdlib.Compare.S with type t := t
diff a b
is the number of seconds between a
and b
. It is negative if b
is later than a
.
Conversions to and from string representations
Convert a string in the RFC3339 format (e.g., "1970-01-01T00:00:00Z"
) into a protocol time. Invalid RFC3339 notations will return None
.
Note that years outside the 0000-9999 range are invalid RFC3339-wise.
Convert a string in the RFC3339 format (e.g., "1970-01-01T00:00:00Z"
) into a protocol time. Invalid RFC3339 notations will raise Invalid_argument
.
Note that years outside the 0000-9999 range are invalid RFC3339-wise.
Convert a protocol time into an RFC3339 notation (e.g., "1970-01-01T00:00:00Z"
).
Note that years outside the 0000-9999 range will raise Invalid_argument
as they are invalid RFC3339-wise.
Conversion to and from "number of seconds since epoch" representation.
Serialization functions
Binary and JSON encoding.
Binary is always encoding/decoding as int64
.
JSON is more complex (for backward compatibility and user-friendliness):
- encoding uses the RFC3339 format (e.g.,
"1970-01-01T00:00:00Z"
) if the year is between 0000 and 9999 (RFC3339-compatible); otherwise it uses theint64
format - decoding tries to decode as an RFC3339 notation, and if it fails, it decodes as
int64
.
Note: the RFC has a different range than the internal representation. Specifically, the RFC can only represent times between 0000-00-00 and 9999-12-31 (inclusive). The RFC-encoding fails for dates outside of this range.
For this reason, it is preferable to use encoding
and only resort to rfc_encoding
for human-readable format.
Pretty-printing functions
Pretty print as a number of seconds after epoch.
Note: pretty-printing uses the RFC3339 for human-readability. As mentioned in the comment on rfc_encoding
, this representation fails when given dates too far in the future (after 9999-12-31) or the past (before 0000-00-00).
For reliable, generic pretty-printing use pp
.