Recent

Author Topic: Date/Time parser  (Read 2261 times)

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Date/Time parser
« on: November 23, 2019, 05:59:10 pm »
removed
« Last Edit: November 25, 2019, 11:25:40 pm by piola »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: Date/Time parser
« Reply #1 on: November 24, 2019, 12:11:10 am »
Seems complicated. Just use scandatetime() ?

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Date/Time parser
« Reply #2 on: November 24, 2019, 03:57:53 am »
No, because ScanDateTime needs to know the date/time format whilst dateparser don't ;)

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Date/Time parser
« Reply #3 on: November 24, 2019, 10:22:20 am »
No, because ScanDateTime needs to know the date/time format whilst dateparser don't ;)
And how does your library determine whether the string '01/02/03' corresponds to the date Feb 01 2003 or Jan 02 2003 or Feb 03 2001?

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Date/Time parser
« Reply #4 on: November 24, 2019, 10:48:13 am »
And how does your library determine whether the string '01/02/03' corresponds to the date Feb 01 2003 or Jan 02 2003 or Feb 03 2001?
From the go sources: the locale information for a system is retrieved, so it does actually the same or similar as ScanDateTime() does with formatsettings and fails on every single example where ScanDateTime also fails.
(I tried some of the above and all 1-2,2-1,3-2,2-3.....11-12 pairs: they pass only based on matching the locale info, other options are ignored)

So the whole project adds no value over ScanDateTime at all, in contrast to what OP writes.
I think he was simply not familiar with this function or its functionality.

Note I tested only the go lib, not the pascal version, because I first wanted to test the source before testing the derivative.
« Last Edit: November 24, 2019, 10:56:44 am by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Date/Time parser
« Reply #5 on: November 24, 2019, 12:58:23 pm »
No, because ScanDateTime needs to know the date/time format whilst dateparser don't ;)
That is true, but the go library also only gives correct results based on locale. All my border cases failed.
@marcov
Note that ScanDateTime() has room for improvement/addition by returning a boolean and a Tdatetime as out parameter. The  EConvertError exception is not a very clean way to handle it. Something along the lines of TryScanDateTime()
« Last Edit: November 24, 2019, 01:04:34 pm by Thaddy »
Specialize a type, not a var.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Date/Time parser
« Reply #6 on: November 24, 2019, 01:15:42 pm »
I used ScanDateTime a lot, but I think TryStrToDate has improved a lot. Is there anything which ScanDateTime can handle, but none of the TryStrToDate overloads? And the exceptions of ScanDateTime are really annoying, as Thaddy noted.

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Date/Time parser
« Reply #7 on: November 24, 2019, 01:31:35 pm »
And how does your library determine whether the string '01/02/03' corresponds to the date Feb 01 2003 or Jan 02 2003 or Feb 03 2001?

How would you as a human interpret 01/02/03?

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Date/Time parser
« Reply #8 on: November 24, 2019, 01:37:13 pm »
Depends on what the FormatSettings say. When FormatSettings.ShortDateFormat is 'dd/mm/yy' then the date of '01/02/03' is Feb 01 2003.

I just mentioned this example because you postulated that dateparser does not need to know the format. And this obviously is wrong.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Date/Time parser
« Reply #9 on: November 24, 2019, 02:03:08 pm »
And how does your library determine whether the string '01/02/03' corresponds to the date Feb 01 2003 or Jan 02 2003 or Feb 03 2001?

How would you as a human interpret 01/02/03?

A human would interpret it depending on the context. In an Spanish report, for example, that would be Feb. 1, 2003 while in an English one I would "guess" it means Jan. 2, 2003.

Unfortunately computers are not yet very god at judging from context, though it looks like they will soon :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Date/Time parser
« Reply #10 on: November 24, 2019, 02:38:27 pm »
And how does your library determine whether the string '01/02/03' corresponds to the date Feb 01 2003 or Jan 02 2003 or Feb 03 2001?

How would you as a human interpret 01/02/03?

A human would interpret it depending on the context. In an Spanish report, for example, that would be Feb. 1, 2003 while in an English one I would "guess" it means Jan. 2, 2003.

Unfortunately computers are not yet very god at judging from context, though it looks like they will soon :)
If by "English" you mean having to do with England ("British" would be less ambiguous), then the guessed interpretation would more likely be 1 Feb 2003.
If by "English" you mean (north) American then, yes, you would guess at Jan 2, 2003.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Date/Time parser
« Reply #11 on: November 24, 2019, 05:18:39 pm »
In Japan it would be interpreted as

2001 - february -03

Now we got  three "solutions"

Winni

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Date/Time parser
« Reply #12 on: November 24, 2019, 06:10:25 pm »
Well the only viable option is to rely on the system settings for the user and /or the database settings if available. The latter can be converted to system settings.
BTW AFAIK this is where both options rely on. Hence I suggested it has little merit. -mot if any, but still some - It makes us think again
Specialize a type, not a var.

 

TinyPortal © 2005-2018