Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-10

Parse strings like "day-1" to convert in a time stamp

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas B. Santos

Do you know any Pascal lib to parse strings to convert in date/time values? The user is supposed to type human-friendly values like:
- "day" => trunc(now)
- "day-2" => trunc(now-2)
- "week" => trunc(now-7)
- "yesterday" => trunc(now-1)
- etc...
But they could type even their computer date format or ISO as well.

A lib in C, but very complex:
- https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y

I would like to start with something simpler, if possible. Thank you.

Best regards,
Marcos Douglas

Reply by email

Sven Barth
to Marcos Douglas B. Santos

Marcos Douglas B. Santos schrieb am So., 14. Okt. 2018, 16:15:

Show quoted text 14 lines
Do you know any Pascal lib to parse strings to convert in date/time values? The user is supposed to type human-friendly values like: - "day" => trunc(now) - "day-2" => trunc(now-2) - "week" => trunc(now-7) - "yesterday" => trunc(now-1) - etc... But they could type even their computer date format or ISO as well. A lib in C, but very complex: - https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y I would like to start with something simpler, if possible. Thank you.

I don't know a specific library that fulfills your needs, but maybe you can build something atop of FpExprPars:
http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser At least according to the source it also supports datetime handling.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 22 lines
Marcos Douglas B. Santos schrieb am So., 14. Okt. 2018, 16:15: > Do you know any Pascal lib to parse strings to convert in date/time values? > The user is supposed to type human-friendly values like: > - "day" => trunc(now) > - "day-2" => trunc(now-2) > - "week" => trunc(now-7) > - "yesterday" => trunc(now-1) > - etc... > But they could type even their computer date format or ISO as well. > > A lib in C, but very complex: > - https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y > > I would like to start with something simpler, if possible. Thank you. > I don't know a specific library that fulfills your needs, but maybe you can build something atop of FpExprPars: http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser At least according to the source it also supports datetime handling.
It does, it's used (amongst other things) in the reporting engine;

Michael.

Reply by email

Marcos Douglas B. Santos
to Michael Van Canneyt
PM Michael Van Canneyt wrote 27 lines
On Mon, 15 Oct 2018, Sven Barth via fpc-pascal wrote: > Marcos Douglas B. Santos schrieb am So., 14. Okt. 2018, > 16:15: > >> Do you know any Pascal lib to parse strings to convert in date/time values? >> The user is supposed to type human-friendly values like: >> - "day" => trunc(now) >> - "day-2" => trunc(now-2) >> - "week" => trunc(now-7) >> - "yesterday" => trunc(now-1) >> - etc... >> But they could type even their computer date format or ISO as well. >> >> A lib in C, but very complex: >> - https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y >> >> I would like to start with something simpler, if possible. Thank you. >> > > I don't know a specific library that fulfills your needs, but maybe you can > build something atop of FpExprPars: > http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser > At least according to the source it also supports datetime handling.

Thanks, Sven.

It does, it's used (amongst other things) in the reporting engine;

Michael,
But does it work using just date values - accordingly with date format in OS - or also with "day", "tomorrow", etc?
If not, can I extend those classes without change the original ones?

Regards,
Marcos Douglas

Reply by email

Michael Van Canneyt
to Marcos Douglas B. Santos
Show quoted text 42 lines
On Sun, Oct 14, 2018 at 8:19 PM Michael Van Canneyt wrote: > > > > On Mon, 15 Oct 2018, Sven Barth via fpc-pascal wrote: > > > Marcos Douglas B. Santos schrieb am So., 14. Okt. > 2018, > > 16:15: > > > >> Do you know any Pascal lib to parse strings to convert in date/time > values? > >> The user is supposed to type human-friendly values like: > >> - "day" => trunc(now) > >> - "day-2" => trunc(now-2) > >> - "week" => trunc(now-7) > >> - "yesterday" => trunc(now-1) > >> - etc... > >> But they could type even their computer date format or ISO as well. > >> > >> A lib in C, but very complex: > >> - https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y > >> > >> I would like to start with something simpler, if possible. Thank you. > >> > > > > I don't know a specific library that fulfills your needs, but maybe > you can > > build something atop of FpExprPars: > > http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser > > At least according to the source it also supports datetime handling. Thanks, Sven. > > It does, it's used (amongst other things) in the reporting engine; Michael, But does it work using just date values - accordingly with date format in OS - or also with "day", "tomorrow", etc? If not, can I extend those classes without change the original ones?

All depends on the exact format you want to use.
day -1
can be easily implemented by registering a function day, which returns teh same Date()

double quotes are supported as delimiters for identifiers, so "Day" should work, but a date literal is going to be tricky.

Michael.

Reply by email

Marcos Douglas B. Santos
to Michael Van Canneyt
AM Michael Van Canneyt wrote 48 lines
> On Sun, Oct 14, 2018 at 8:19 PM Michael Van Canneyt > wrote: >> >> >> >> On Mon, 15 Oct 2018, Sven Barth via fpc-pascal wrote: >> >> > Marcos Douglas B. Santos schrieb am So., 14. Okt. >> 2018, >> > 16:15: >> > >> >> Do you know any Pascal lib to parse strings to convert in date/time >> values? >> >> The user is supposed to type human-friendly values like: >> >> - "day" => trunc(now) >> >> - "day-2" => trunc(now-2) >> >> - "week" => trunc(now-7) >> >> - "yesterday" => trunc(now-1) >> >> - etc... >> >> But they could type even their computer date format or ISO as well. >> >> >> >> A lib in C, but very complex: >> >> - https://github.com/gagern/gnulib/blob/master/lib/parse-datetime.y >> >> >> >> I would like to start with something simpler, if possible. Thank you. >> >> >> > >> > I don't know a specific library that fulfills your needs, but maybe >> you can >> > build something atop of FpExprPars: >> > http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser >> > At least according to the source it also supports datetime handling. > > Thanks, Sven. > >> >> It does, it's used (amongst other things) in the reporting engine; > > Michael, > But does it work using just date values - accordingly with date format > in OS - or also with "day", "tomorrow", etc? > If not, can I extend those classes without change the original ones? All depends on the exact format you want to use. day -1 can be easily implemented by registering a function day, which returns teh same Date()

So I can register those identifiers as functions, cool!

double quotes are supported as delimiters for identifiers, so "Day" should work, but a date literal is going to be tricky.

Maybe I can test the value first if it is a valid date format, before try to use FpExprPars on it...
It looks like a good start, though. Thanks.

regards,
Marcos Douglas

Reply by email