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

🐞 fc-date and fc-end is not being parsed correctly when a custom date format is set with hyphens #121

Closed
3 of 7 tasks
OhMyDeera opened this issue Apr 5, 2024 · 4 comments

Comments

@OhMyDeera
Copy link

Check for existing bug reports before submitting.

  • I searched for existing Bug Reports and found no similar reports.

Expected Behavior

Unsure if this is a bug or working as expected.

Changing the date format from YYYY-MM-DD to DD MMM YYYY and updating the fc-date and fc-end to be in the same format should have only changed the format of the date displayed in the calendar view.

Current behaviour

Closing and reopening obsidian after changing the format to DD MMM YYYY removes all automatic events from the calendar.

Reproduction

  1. Create a new event using the fc-calendar, fc-date and fc-end frontmatter properties.
  2. Go to the calendar settings and change the format of the date to any format without hyphens.
  3. At first it will change the format as expected, however when you close obsidian and reopen, you will find that all the automatic events have now gone.
  4. Checking the logs you should be able to see errors like so: Calendarium: Must specify all three segments in DD MMM YYYY order. From 'Sessions/Untitled.md', date value: '24 Aug 0034'

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version Check

1.5.12

Plugin Version

1.1.0

Confirmation

  • I have disabled all other plugins and the issue still persists.

Possible solution

update the following line (event-helper.ts [line 346]) to allow space as a separator:
let datebits = datestring.split(/(?!^)[-–—](?![^[]*])/);

I know that you can also use the date object, but I prefer editing the date without having to go into source view.

@valentine195
Copy link
Member

I did play with this updating this to allow spaces:

let datebits = datestring.split(/(?!^)[-–—](?![^[]*])/);

but unfortunately that ignores other delimiters that could be used in a date format. Realistically I need to actually parse these bits against the format that was specified.

@OhMyDeera
Copy link
Author

Yeah that's a good point. I only did a quick scan through the code, but can take a more in depth look and try to come up with an actual solution once I've got some time if you'd like.
One idea could be using RegExp and using the date format supplied in the config to build a dynamic regex to get the day, month and year regardless of what seperators they are using. Though doing so whilst also making sure the recurring dates still parse as expected may prove to be fiddly.

@ebullient
Copy link
Contributor

ebullient commented Apr 15, 2024

Yeah that's a good point. I only did a quick scan through the code, but can take a more in depth look and try to come up with an actual solution once I've got some time if you'd like. One idea could be using RegExp and using the date format supplied in the config to build a dynamic regex to get the day, month and year regardless of what seperators they are using. Though doing so whilst also making sure the recurring dates still parse as expected may prove to be fiddly.

I think what would help most is any suggestion of additional tests for formats. ;) we have some, but obviously forgot this one. That way we fix this w/o breaking others.

A split based on (any non-word/non-digit character) could also do it. The other option is not to use split at all, but use regex find. We need the first three, and then the starting position of content after that as the ordinal.

@valentine195
Copy link
Member

@OhMyDeera Unfortunately I have spent quite a bit of time trying to fix this issue but its almost impossible to make this generic.

I am going to update the setting in the creator to reflect that this is for the Display Date format, and require dashes when parsing.

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

3 participants