Android Question Parsing a date with complex conditions using AI

Sergey_New

Well-Known Member
Licensed User
Longtime User
The date is represented as, for example, "BET 1 JAN 1852 AND 31 DEC 1852".
I decided to try using DeepSeek neural network.
The task was to parse a date and date range using the B4A language.
Conditions:
The year of the date contains 4 digits. To calculate the number of digits, leading zeros should not be counted.
The month name must be one of the 3 specified Latin characters in uppercase.
The day of the date must be from 1 to 31. Leap years must be taken into account.
The date may have prefixes.
For a single date: ABT, CAL, EST, AFT, BEF, FROM.
For the first date of the date range: ABT, CAL, EST, AFT, BEF, BET, FROM.
For the second date of the date range: TO, AND.
The BET prefix of the first date must be used with the AND prefix of the second date.
The FROM prefix of the first date must be used with the TO prefix of the second date.
For each date, five string values must be returned: prefix, day, month, year, and the parsing success result. If any value is missing, a blank is returned.

The problem was almost completely solved in the few hours it took me to clarify the requirements and test the code.
I received the parser and activity codes with comments in the native language.
Ultimately, the AI was unable to correctly attribute the parsing error of the second date prefix to the second date, assigning it to the first date in the range.
If you are interested in the resulting code, let me know, and I'll post it.
 

Sergey_New

Well-Known Member
Licensed User
Longtime User
Feels like dates for genealogy purposes
Yes, you've got it right. The basic date requirements are outlined in the first post. If any clarification is needed, I'm happy to discuss them.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
See post #18. Your code resolves these conditions incorrectly.
Please point to me which one is incorrect.

Your code should work like this
These date values are correct:
ParseText("BET 1 JAN 1852 AND 31 DEC 1852")
ParseText("ABT 3 SEP 1852")
ParseText("FROM 31 DEC 1852")
These date values are incorrect:
ParseText("FROM 1 FEB 2025 AND 30 NOV 2025")
ParseText("BET 1 FEB 2026 TO 30 NOV 2026")
These date values are correct:
ParseText("FROM 1 FEB 2025 TO 30 NOV 2025")
ParseText("BET 1 FEB 2026 AND 30 NOV 2026")
yes, this is expected right?

FROM ... AND .. ❌
BET ... TO .. ❌

FROM ... TO .. ✅
BET ... AND .. ✅
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Please point to me which one is incorrect.
Of course the last ones, marked with the icon
1766936882402.png
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Of course the last ones, marked with the icon View attachment 169094
You mean this should be incorrect?
BET ... AND .. ✅ <-- Wrong??
The BET prefix of the first date must be used with the AND prefix of the second date.

By the way, I really have no idea what are those short forms or codes such as ABT, BET, BEF since you don't explain.
I can only guess BET stands for "between" and BEF stands for "before".
So I think it should be acceptable for an input phrase "between date1 and date2".

If you tell AI that it's code is wrong and not telling it what is wrong, I don't know how do you proceed.

If you can't type or explain in English, maybe try with your language. I don't know is it Russian?
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
My idea is first check for some condition, for example if string start with BET, it must contain also AND.
If it start with FROM, it must contain TO, and so on for others check.
Then, I would use RegEX for to extract all datas and so you can parse it and convert into two dates
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
1766943502391.png

I purposely added 3 tests for invalid input.
I don't see anything wrong.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
By the way, I really have no idea what are those short forms or codes
AFT = Event happened after the given date.
BEF = Event happened before the given date.
BET = Event happened some time between date 1 AND date 2.
FROM = Indicates the beginning of a happening.
TO = Indicates the ending of a happening.
ABT = About, meaning the date is not exact.
CAL = Calculated mathematically
EST = Estimated based on an algorithm using some other event date.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Wait, you mean this is correct?
Yes, that's also true.
FROM can be used with or without the second TO date prefix. The presence of the prefix defines it as a date range.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
1766947907410.png
 

Attachments

  • NotComplexDateParseV2.zip
    1.7 KB · Views: 19
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
The results shown in the image do not match the results obtained when executing the code:
Invalid date1! CAL 01 FEB 1852
Invalid date1! EST 01 MAR 1852
Invalid date1! AFT 01 APR 1852
Invalid date1! BEF 01 MAY 1852
Invalid date1! EST 29 FEB 1852
Invalid date1! FROM 31 DEC 1852
Invalid date1! FROM 1 FEB 2025 TO 30 NOV 2025
Invalid date1! BET 1 FEB 2026 AND 30 NOV 2026
Invalid date1! BEF 29 FEB 1853
BET missing AND! BET 1 MAR 1852
Invalid date1! BET 1 JAN AND 31 DEC 1852
Invalid date1! BET 1 JAN 1852 AND 31 DEC
Unmatched date pair! FROM 1 FEB 2025 AND 30 NOV 2025
Unmatched date pair! BET 1 FEB 2026 TO 30 NOV 2026
Program terminated (StartMessageLoop was not called)

Also, a date can be represented without the year, month, or day. At least one of these date parameters must be present.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
You must have modified the code.
Why not upload what you have modified?

For me a text like:
day = "1",
month "JAN" or
year = "2026" only
is not a parseble date.

Date like "1 JAN", "JAN 2026" or "1 2026" (missing month) are also meaningless and not parseble.

I have provided solutions where you can adapt further to your requirements.
You can add more rules or checking on your own.
 
Upvote 0

QSerg

Member
The date is represented as, for example, "BET 1 JAN 1852 AND 31 DEC 1852".
I decided to try using DeepSeek neural network.
The task was to parse a date and date range using the B4A language.
Conditions:
The year of the date contains 4 digits. To calculate the number of digits, leading zeros should not be counted.
The month name must be one of the 3 specified Latin characters in uppercase.
The day of the date must be from 1 to 31. Leap years must be taken into account.
The date may have prefixes.
For a single date: ABT, CAL, EST, AFT, BEF, FROM.
For the first date of the date range: ABT, CAL, EST, AFT, BEF, BET, FROM.
For the second date of the date range: TO, AND.
The BET prefix of the first date must be used with the AND prefix of the second date.
The FROM prefix of the first date must be used with the TO prefix of the second date.
For each date, five string values must be returned: prefix, day, month, year, and the parsing success result. If any value is missing, a blank is returned.

The problem was almost completely solved in the few hours it took me to clarify the requirements and test the code.
I received the parser and activity codes with comments in the native language.
Ultimately, the AI was unable to correctly attribute the parsing error of the second date prefix to the second date, assigning it to the first date in the range.
If you are interested in the resulting code, let me know, and I'll post it.
Your conditions strict enough to make simple enough function that parsing those dates. Why do you need stupid AI to make you parsing much more complicated and make it depends on changes made elsewhere? Just to sake of using so-called AI?
 
Upvote 0
Top