Re: std.getopt and std.datetime

2017-05-13 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2017-05-13 at 02:23 -0700, Jonathan M Davis via Digitalmars-d-
learn wrote:
> 
[…]
> At best, it's slang. It's not proper anything.
> 
> https://github.com/dlang/phobos/pull/5388
> 
> - Jonathan M Davis

Indeed. Thanks for getting a pull request in to ameliorate the
difficulty.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc
Description: This is a digitally signed message part


Re: std.getopt and std.datetime

2017-05-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 13, 2017 06:53:25 Russel Winder via Digitalmars-d-learn 
wrote:
> Is there a canonical, idiomatic way of processing std.datetime objects
> using std.getopt?
>
> Currently, I am suffering:
>
> /usr/include/d/std/getopt.d(921): Error: static assert  "Dunno how to deal
> with type SysTime*"
>
> which on the one hand is understandable, albeit dreadful English, but
> then I suppose it is American not English

At best, it's slang. It's not proper anything.

https://github.com/dlang/phobos/pull/5388

- Jonathan M Davis



Re: std.getopt and std.datetime

2017-05-13 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2017-05-13 at 06:05 +, Vladimir Panteleev via Digitalmars-
d-learn wrote:
> 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:

std.getopt appears also to be able to deal with integers as well as
strings.

> 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);
> }

I hadn't realised you could put a function in the argument sequence, I
had the address of the variable to amend:

SysTime t;
auto buffer = t.toISOString();
getopt(args,
"date|d",
"Some explanation of the d option.",
);
t = SysTime.fromISOString(buffer);

I think I like your way better. :-)

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

I am only interested in ISO8601 dates. However looking at this code is
interesting as I learnt some stuff. 

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc
Description: This is a digitally signed message part


Re: std.getopt and std.datetime

2017-05-13 Thread Vladimir Panteleev via Digitalmars-d-learn

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


std.getopt and std.datetime

2017-05-12 Thread Russel Winder via Digitalmars-d-learn
Is there a canonical, idiomatic way of processing std.datetime objects
using std.getopt?

Currently, I am suffering:

/usr/include/d/std/getopt.d(921): Error: static assert  "Dunno how to deal with 
type SysTime*"

which on the one hand is understandable, albeit dreadful English, but
then I suppose it is American not English, as std.getopt is only going
to process builtin types, but it is very annoying.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc
Description: This is a digitally signed message part