Discussion:
[fpc-pascal] Parse strings like "day-1" to convert in a time stamp
Marcos Douglas B. Santos
2018-10-14 14:15:24 UTC
Permalink
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
Sven Barth via fpc-pascal
2018-10-14 22:15:11 UTC
Permalink
Post by Marcos Douglas B. Santos
Do you know any Pascal lib to parse strings to convert in date/time values?
- "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.
- 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
Michael Van Canneyt
2018-10-14 23:19:40 UTC
Permalink
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
Do you know any Pascal lib to parse strings to convert in date/time values?
- "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.
- 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
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.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-
Marcos Douglas B. Santos
2018-10-15 12:18:53 UTC
Permalink
On Sun, Oct 14, 2018 at 8:19 PM Michael Van Canneyt
Post by Michael Van Canneyt
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
Do you know any Pascal lib to parse strings to convert in date/time values?
- "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.
- 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
http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser
At least according to the source it also supports datetime handling.
Thanks, Sven.
Post by Michael Van Canneyt
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
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lis
Michael Van Canneyt
2018-10-15 12:37:48 UTC
Permalink
Post by Marcos Douglas B. Santos
On Sun, Oct 14, 2018 at 8:19 PM Michael Van Canneyt
Post by Marcos Douglas B. Santos
2018,
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
Do you know any Pascal lib to parse strings to convert in date/time
values?
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
- "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.
- 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
Post by Sven Barth via fpc-pascal
http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser
At least according to the source it also supports datetime handling.
Thanks, Sven.
Post by Marcos Douglas B. Santos
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.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman
Marcos Douglas B. Santos
2018-10-15 13:11:29 UTC
Permalink
On Mon, Oct 15, 2018 at 9:33 AM Michael Van Canneyt
Post by Michael Van Canneyt
Post by Marcos Douglas B. Santos
On Sun, Oct 14, 2018 at 8:19 PM Michael Van Canneyt
Post by Marcos Douglas B. Santos
2018,
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
Do you know any Pascal lib to parse strings to convert in date/time
values?
Post by Sven Barth via fpc-pascal
Post by Marcos Douglas B. Santos
- "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.
- 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
Post by Sven Barth via fpc-pascal
http://wiki.lazarus.freepascal.org/How_To_Use_TFPExpressionParser
At least according to the source it also supports datetime handling.
Thanks, Sven.
Post by Marcos Douglas B. Santos
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!
Post by Michael Van Canneyt
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
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailma

Loading...