The Abbreviated Date Parser Library contains a predicate that parses abbreviated incomplete dates in multiple languages.
Imagine you want to understand the date: "11-09, št". We can infer that "št" is an abbreviation of:
findall([F,L,C],(parse(date(2022,09,9),'11-09, št',[D],_,L,C),format_time(string(F),"%A, %d %b %Y",D)),Y),cli_table(Y,[head(['Date','Language','Country'])]).
╔═══════════════════════╤════════════╤════════════════╗
║ Date │ Language │ Country ║
╟───────────────────────┼────────────┼────────────────╢
║ Saturday, 09 Nov 2024 │ Lithuanian │ Lithuania ║
║ Saturday, 11 Sep 2027 │ Lithuanian │ Latvia ║
║ Thursday, 11 Sep 2025 │ Slovak │ Czech Republic ║
║ Thursday, 11 Sep 2025 │ Slovak │ Slovakia ║
║ Thursday, 11 Sep 2025 │ Slovak │ Czech Republic ║
║ Thursday, 11 Sep 2025 │ Slovak │ Slovakia ║
╚═══════════════════════╧════════════╧════════════════╝
- Šeštadienis which means in Saturday in Lithuanian
- Štvrtok which means in Thursday in Slovak
But Lithuanian is spoken not only in Lithuania but also in Latvia and Slovak is spoken not only in Slovakia but also by a minority in Czech Republic. These countries use different date representations: Czech Republic, Latvia and Slovakia have the day written first because of the "little" date endianness format used as the standard in the country. Lithuania, on the other hand, uses the "big" date endiannes format which means that the month is written first.
The system factor in all this facts and is able to come with the right answers:
In the case of interpreting the abbreviation as s Saturday:
- 9 of November 2024
- 11 of September 2027
In the case of interpreting the abbreviation as a Thursday:
- 11 of September 2025
This pack is available from the add-on registry of SWI-Prolog.
It can be installed with pack_install/1
:
?- pack_install(abbreviated_dates).
Then, you can use it by simply calling use_module(library(abbreviated_dates))
.
parse(Context, Expression, Dates, Trace).
For maintenance tasks bumpversion and hub might be required.
parse/4. % parse an abbreviated incomplete date in multiple languages (today, tomorrow, etc).
For further details have a look at the implementation. In addition, the new might give an impression on how to use this library.
The tests can be run using the following command:
make test
Define new Tests
New tests should be defined in the test file.
Review: https://eu.swi-prolog.org/pack/review?p=abbreviated_dates
- Multi-language Support
- Add back to top links
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
file for more information.