std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

kdevel kdevel at vogtner.de
Mon Mar 9 02:14:09 UTC 2020


On Sunday, 8 March 2020 at 17:28:33 UTC, Robert M. Münch wrote:
[...]
> But I have to do:
>
> DateTime dt = 
> DateTime.fromISOExtString(split("2018-11-06T16:52:03+01:00", 
> regex("\\+"))[0]);

You don't need a regex. split (..., '+') seems to suffice here.

> IMO such a string should be feedable directly to the function.

It took me less than an hour to figure out how to provide a local 
version of std.datetime named local.datetime:

```local/datetime.d
module local.datetime;
public import std.datetime;
struct DateTime {
    std.datetime.DateTime dt;
    alias dt this;
    static DateTime fromISOExtString (string s)
    {
       import std.array;
       auto arr = split (s, '+');
       import std.exception;
       enforce (arr.length > 0);
       return DateTime (dt.fromISOExtString (arr[0]));
    }
}
```

usage: import local.datetime instead of import std.datetime.


More information about the Digitalmars-d-learn mailing list