From c650e93aaac225559229968fbbf6dfd7ca5d0cf7 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 1 Feb 2018 16:35:43 +0100 Subject: stdlib: Add RFC 3339 functions to module calendar Functions for converting between RFC 3339 strings and system time are added. Options are lists, but we are considering using maps instead. If we change, it will happen after Erlang/OTP 21.0-rc1 is released. --- lib/stdlib/doc/src/calendar.xml | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/calendar.xml b/lib/stdlib/doc/src/calendar.xml index 0c4a30ce16..8f2b6b747a 100644 --- a/lib/stdlib/doc/src/calendar.xml +++ b/lib/stdlib/doc/src/calendar.xml @@ -316,6 +316,30 @@ + + + + Convert from RFC 3339 timestamp to system time. + + + +

Converts an RFC 3339 timestamp into system time.

+

Valid option:

+ + {unit, Unit} +

The time unit of the return value. + The default is second.

+
+
+
+1> calendar:rfc3339_to_system_time("2018-02-01T16:17:58+01:00").
+1517498278
+2> calendar:rfc3339_to_system_time("2018-02-01 15:18:02.088Z",
+   [{unit, nanosecond}]).
+1517498282088000000
+
+
+ Compute days and time from seconds. @@ -346,6 +370,52 @@ + + + + Convert from system to RFC 3339 timestamp. + + + + +

Converts a system time into RFC 3339 timestamp.

+

Valid options:

+ + {offset, Offset} +

The offset, either a string or an integer, to be + included in the formatted string. + An empty string, which is the default, is interpreted + as local time. A non-empty string is included as is. + The time unit of the integer is the same as the one + of Time.

+
+ {time_designator, Character} +

The character used as time designator, that is, + the date and time separator. The default is $T.

+
+ {unit, Unit} +

The time unit of Time. The + default is second. If some other unit is given + (millisecond, microsecond, or + nanosecond), the formatted string includes a + fraction of a second.

+
+
+
+1> calendar:system_time_to_rfc3339(erlang:system_time(second)).
+"2018-04-23T14:56:28+02:00"
+2> calendar:system_time_to_rfc3339(erlang:system_time(second),
+   [{offset, "-02:00"}]).
+"2018-04-23T10:56:52-02:00"
+3> calendar:system_time_to_rfc3339(erlang:system_time(second),
+   [{offset, -7200}]).
+"2018-04-23T10:57:05-02:00"
+4> calendar:system_time_to_rfc3339(erlang:system_time(millisecond),
+   [{unit, millisecond}, {time_designator, $\s}, {offset, "Z"}]).
+"2018-04-23 12:57:20.482Z"
+
+
+ Convert system time to universal date and time. -- cgit v1.2.3