Date extraction from string.

122 views
Skip to first unread message

mdlug...@gmail.com

unread,
Feb 7, 2025, 10:37:00 AMFeb 7
to Harbour Developers
Hi all!

I was checking whether string contains valid date/numbers etc. while post processing XML to JSON conversion

b:=hb_ctod(d,"YYYY-MM-DD")

and it has found date (1965-03-05) in <NAZWA> here.

<TOWAR>
          <KOD>5909.0002</KOD>
          <NAZWA>ORING 65 X 3,5 NBR</NAZWA>
          <OPIS />
          <EAN>5904447005909</EAN>
          <SWW />
          <NUMER_KATALOGOWY />
</TOWAR>

My post-processing converts also <KOD> into double, but this is what I must expect.

Is this a bug or a feature? LOL

Regards!

Marek

Aleksander Czajczynski

unread,
Feb 7, 2025, 12:29:07 PMFeb 7
to harbou...@googlegroups.com
This is the case:
? hb_ctod("ORING 65 X 3,5 NBR","YYYY-MM-DD")
https://os.allcom.pl/hb/#!UFJPQ0VEVVJFIE1haW4KICAgPyBoYl9jdG9kKCJPUklORyA2NSBYIDMsNSBOQlIiLCJZWVlZLU1NLUREIikKICAgICAg
I would say that you should use this function for validating "if a string is a date", it ignores the kind of separator, only the order of YYMMDD is respected. See "1965 03 10".
To really tell origin of such behaviour, you should go back to Clipper's ctod(). Harbour added second parameter for the template, but not altered the way it reads string. Maybe hb_ctod( <s>, <sT>,<lVerifyTemplate> ) as third parameter could be  implemented if someone want's to have fun with this.

Best regards, Aleksander

mdlug...@gmail.com wrote:
--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-devel/f7b33521-6299-4f3d-9d36-77cacab4405cn%40googlegroups.com.

Marek Długosz

unread,
Feb 9, 2025, 8:48:40 PMFeb 9
to harbou...@googlegroups.com
Thanks!

Now I understand. I check it back and forth now.

Marek

------ Wiadomość oryginalna ------
Nadawca "Aleksander Czajczynski" <h...@fki.pl>
Data 07.02.2025 13:18:22
Temat Re: [harbour] Date extraction from string.
mdlugosz65@gmail.com.asc
Reply all
Reply to author
Forward
0 new messages