The OpenD Programming Language

SysTime.fromISOExtString

Creates a SysTime from a string with the format YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone). Whitespace is stripped from the given string.

The exact format is exactly as described in toISOExtString except that trailing zeroes are permitted - including having fractional seconds with all zeroes. The time zone and fractional seconds are optional, however, a decimal point with nothing following it is invalid. Also, while toISOExtString will never generate a string with more than 7 digits in the fractional seconds (because that's the limit with hecto-nanosecond precision), it will allow more than 7 digits in order to read strings from other sources that have higher precision (however, any digits beyond 7 will be truncated).

If there is no time zone in the string, then std.datetime.timezone.LocalTime is used. If the time zone is "Z", then UTC is used. Otherwise, a std.datetime.timezone.SimpleTimeZone which corresponds to the given offset from UTC is used. To get the returned SysTime to be a particular time zone, pass in that time zone and the SysTime to be returned will be converted to that time zone (though it will still be read in as whatever time zone is in its string).

The accepted formats for time zone offsets are +HH, -HH, +HH:MM, and -HH:MM.

struct SysTime
static @safe
fromISOExtString
(
S
)
(
scope const S isoExtString
,
immutable TimeZone tz = null
)

Parameters

isoExtString S

A string formatted in the ISO Extended format for dates and times.

tz TimeZone

The time zone to convert the given time to (no conversion occurs if null).

Throws

std.datetime.date.DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid.

Examples

import core.time : hours, msecs, usecs, hnsecs;
import std.datetime.date : DateTime;
import std.datetime.timezone : SimpleTimeZone, UTC;

assert(SysTime.fromISOExtString("2010-07-04T07:06:12") ==
       SysTime(DateTime(2010, 7, 4, 7, 6, 12)));

assert(SysTime.fromISOExtString("1998-12-25T02:15:00.007") ==
       SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(7)));

assert(SysTime.fromISOExtString("0000-01-05T23:09:59.00002") ==
       SysTime(DateTime(0, 1, 5, 23, 9, 59), usecs(20)));

assert(SysTime.fromISOExtString("2013-02-07T04:39:37.000050392") ==
       SysTime(DateTime(2013, 2, 7, 4, 39, 37), hnsecs(503)));

assert(SysTime.fromISOExtString("-0004-01-05T00:00:02") ==
       SysTime(DateTime(-4, 1, 5, 0, 0, 2)));

assert(SysTime.fromISOExtString(" 2010-07-04T07:06:12 ") ==
       SysTime(DateTime(2010, 7, 4, 7, 6, 12)));

assert(SysTime.fromISOExtString("2010-07-04T07:06:12Z") ==
       SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC()));

assert(SysTime.fromISOExtString("2010-07-04T07:06:12-08:00") ==
       SysTime(DateTime(2010, 7, 4, 7, 6, 12),
               new immutable SimpleTimeZone(hours(-8))));
assert(SysTime.fromISOExtString("2010-07-04T07:06:12+08:00") ==
       SysTime(DateTime(2010, 7, 4, 7, 6, 12),
               new immutable SimpleTimeZone(hours(8))));

Meta