www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.datetime: easy way to parse 24/Jun/2020?

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
The day and year obviously are easy, is there a way to easily parse the 
month from English into number? Thanks!
Jun 28 2020
next sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Monday, 29 June 2020 at 00:42:17 UTC, Andrei Alexandrescu 
wrote:
 The day and year obviously are easy, is there a way to easily 
 parse the month from English into number? Thanks!
There's [1] if you're willing to transform the input. [1] https://dlang.org/library/std/datetime/date/date.from_simple_string.html
Jun 28 2020
prev sibling next sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 6/28/20 8:42 PM, Andrei Alexandrescu wrote:
 The day and year obviously are easy, is there a way to easily parse the 
 month from English into number? Thanks!
std.datetime specifically does not deal with parsing all formats (generally, this is a HUGE amount of work). It has 2 parsing formats (3 actually, if you can't the non-EXT and EXT ISO formats): https://dlang.org/phobos/std_datetime_date.html#.DateTime.fromSimpleString, https://dlang.org/phobos/std_datetime_date.html#.DateTime.fromISOExtString Otherwise, you have to do it yourself. Note that the 3-letter english name (not capitalized) might match the Month enum: https://dlang.org/phobos/std_datetime_date.html#Month, which means you could possibly parse it with formattedRead. There are also dub packages, e.g.: https://code.dlang.org/packages/dateparser -Steve
Jun 28 2020
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 6/28/2020 5:42 PM, Andrei Alexandrescu wrote:
 The day and year obviously are easy, is there a way to easily parse the month 
 from English into number? Thanks!
The old D1 std.datetime does it using compiler lexing techniques: https://github.com/dlang/undeaD/blob/master/src/undead/dateparse.d
Jun 28 2020
prev sibling parent Seb <seb wilzba.ch> writes:
On Monday, 29 June 2020 at 00:42:17 UTC, Andrei Alexandrescu 
wrote:
 The day and year obviously are easy, is there a way to easily 
 parse the month from English into number? Thanks!
https://code.dlang.org/packages/dateparser
Jun 28 2020