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

Ability to use ISO 8601 for offset in dates #100

Closed
louisboulagnon opened this issue Apr 12, 2021 · 3 comments
Closed

Ability to use ISO 8601 for offset in dates #100

louisboulagnon opened this issue Apr 12, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@louisboulagnon
Copy link

louisboulagnon commented Apr 12, 2021

Thanks for the great plugin, I thought of a possible improvement regarding date parsing.

Is your feature request related to a problem? Please describe.
I think it could be interesting to have the ability to use ISO 8601 durations (https://en.wikipedia.org/wiki/ISO_8601#Durations) in the offset, this would allow to have fairly dynamic and granular date navigation, specifically for months which don't always have the same number of days.
The end goal being to be able to create dates like [[<% tp.date.now("YYYY-MM-DD", "P-1M") %>|This day last month]] for example

Describe the solution you'd like
Probably have the signature of days be days?: number|string (no issue with keeping number defaulting to days for backward-compatibility and ease of use) and pass a moment.duration (https://momentjs.com/docs/#/durations/creating/ which thankfully already support this ISO format) to the .add call.

export function get_date_string(date_format: string, days?: number, moment_str?: string | number, moment_format?: string) {
return window.moment(moment_str, moment_format).add(days, 'days').format(date_format);
}

Additional context
I haven't deep dived into the source code, but if you would like me to look into creating a pull request for this issue, I could probably contribute this when I have some free time.

@SilentVoid13
Copy link
Owner

Hey @louisboulagnon thanks for the suggestion! This has been implemented as of Templater 1.5.0.

Can you update and tell me if this works for you ?

@louisboulagnon
Copy link
Author

It works perfectly, thank you !

Honored to have been the 100th issue on this project haha

@Moonbase59
Copy link

@louisboulagnon This turns out to be real useful, thanks for thinking about it!
And thanks @SilentVoid13 for implementing it!

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

No branches or pull requests

3 participants