Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date parsing too lax? #71

Open
JulienPalard opened this issue Nov 10, 2024 · 1 comment
Open

Date parsing too lax? #71

JulienPalard opened this issue Nov 10, 2024 · 1 comment

Comments

@JulienPalard
Copy link

JulienPalard commented Nov 10, 2024

I had a typo in my org-file: <2024-11-12 14:00-17-00>

Yet orgparse parses it without complaining:

>>> orgparse.date.OrgDate.list_from_str("<2024-11-12 14:00-17-00>")
[OrgDate((2024, 11, 12, 14, 0, 0))]

With the typo fixed, the parsing get it right:

>>> orgparse.date.OrgDate.list_from_str("<2024-11-12 14:00-17:00>")
[OrgDate((2024, 11, 12, 14, 0, 0), (2024, 11, 12, 17, 0, 0))]

I would prefer an exception from invalid dates.

I may not fully know the org syntax for dates and maybe <2024-11-12 14:00-17-00> is kind-of-valid, like it could be a timezone offset of -00, haha, I hope no, I have not found it in the org manual yet.

Maybe a way to do it would be to restrict a bit the ignore regex like this:

-    if brtype == 'nobrace':
-        ignore = r'[\s\w]'
-    else:
-        ignore = '[^{bc}]'.format(bc=bc)
+    ignore = r'[\s\w]'

but looking at the full regex it feels like the ignore part is used too much :D

@JulienPalard
Copy link
Author

Thigs like this could help too:

@@ -98,8 +95,9 @@ def gene_timestamp_regex(brtype, prefix=None, nocookie=False):
         (?P<{prefix}year>\d{{4}}) -
         (?P<{prefix}month>\d{{2}}) -
         (?P<{prefix}day>\d{{2}})
+        (\s[^\s+\]>0-9\n-]+)?  # Optional dayname
         (  # optional time field
-           ({ignore}+?)
+           \s
            (?P<{prefix}hour>\d{{2}}) :
            (?P<{prefix}min>\d{{2}})
            (  # optional end time range

(found spec in https://orgmode.org/worg/org-syntax.html#Timestamps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant