On Saturday, 13 May 2017 at 05:53:25 UTC, Russel Winder wrote:
Is there a canonical, idiomatic way of processing std.datetime objects using std.getopt?

As std.getopt is going to give you strings, you need to convert strings to SysTime values, e.g. using fromSimpleString:

import std.datetime;
import std.getopt;
import std.stdio;

void main()
{
        string[] args = ["program", "--date", "2017-May-13 05:58:59"];
        SysTime t;
        getopt(args,
"date", (string _, string s) { t = SysTime.fromSimpleString(s); },
        );
        writeln(t);
}

For more flexibility, you'll need a date parser. Mine is here:
https://github.com/CyberShadow/ae/blob/master/utils/time/parse.d

Reply via email to