buda-base / blmp-client

JS client for the BLMP
3 stars 0 forks source link

EDTF humanizer #21

Closed eroux closed 2 years ago

eroux commented 2 years ago

as a help for the dates field, it would be good to have a humanizer for EDTF that we can plugin in the same UI space as the Unicode preview for Wylie fields. The humanizer could then be used on PDL to display the date.

There's a PHP library and a Ruby gem to take inspiration from, but no JS library...

We can start with the most important patterns, in that order (it has to be recursive):

berger-n commented 2 years ago

found this: https://github.com/nicompte/edtfy

eroux commented 2 years ago

yes, this is the other way around though (parsing plain English into EDTF)

berger-n commented 2 years ago

oh I see! sorry but there seems be an associated "backwards" package: https://github.com/nicompte/unedtfy (but not updated since 2016 though...)

eroux commented 2 years ago

ah I see... I think it will be easier once we integrate edtf.js, we can make use of it for parsing

berger-n commented 2 years ago

there seems be an associated "backwards" package: https://github.com/nicompte/unedtfy

installed it, could only parse edtf date but not export it to human-readable format though I guess it's normal since there seems to be only one initial commit in the repo (see /tests)

eroux commented 2 years ago

yes, let's not rely on it, I'll write the code if you want, I'm just swamped in the list serialization issue

berger-n commented 2 years ago

no problem! I can do it, should be straightforward

berger-n commented 2 years ago

needs some further testing but almost done:

image

beside an annoying soon-to-be-fixed UI bug moving cursor while typing when an error is detected, some oddities though:

eroux commented 2 years ago

wonderful, that's a very nice code!

I'm wondering what 18 means in EDTF though, it's a bit unclear... does it mean 0018 or 2018? anyways, it's a minor issue

Also, can you test it for decades? 197X should be "1970s" (I think...)

Otherwise this is really good, thanks a lot!

berger-n commented 2 years ago

18 is unambiguously 19th c.:

image

so why not do that:

image

ok for decades:

image

eroux commented 2 years ago

great! this is enough for a first iteration!

berger-n commented 2 years ago

added EDTF error message when more informative than "syntax error" or "no parsing possible":

image