add feature to customize date formatting #100
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the option to set a custom date format, like requested in #78 by @iznaut.
I added a
DateFormatterclass, which gets used in theAPIModels to format date strings. I also looked up what type of date formats are used by the various APIs, and saved them as variables calledapiDateFormat. This makes the date formatting more robust, because you don't have to guess the actual date formats.The
DateFormatterholds the currently set custom date format. This gets updated in themain- by calling thesetFormat()function ofDateFormatter- when the user changes the custom date format in the settings tab.For the settings tab, I added a text field where the user can input a custom date format string. The settings also shows a preview of what the current format will look like.

For the actual date formatting the
DateFormatterusesmoment.js. Which is also used and exported byobsidianitself. But I had some trouble importing it. WithesModuleInteropset in the compiler config, the type script compiler doesn't like thatobsidianimportsmomentwith a namespace-style import (which is also not compliant with ES6 module spec) like this:So when running
npm run buildthe following always results in compiler errors complaining about the namespace-style import ofmomentinobsidian.ts:I eventually got it to work with:
I don't know if this is a good way to import it though.