Date math with template tokens #33
Replies: 4 comments 42 replies
-
I like the idea. That would be an improvement for my weekly template as well. Let's think about it. At the moment, I think addition and subtraction seem enough when applied to dates, days, weeks. |
Beta Was this translation helpful? Give feedback.
-
@renerocksai Okay, I couldn't leave this be and created PR #34. I simplified the original proposal as I realized any more complicated date calculations are out of scope for templates. That said, given a need it would be straightforward to build this out as a parameterized function if you want to build a robust templating scheme. I mainly started the PR as a proposal for discussion. It's not merge-ready because it doesn't currently handle the edge cases of week rollovers, for example As a possible solution, I'd propose the breaking change of changing the string format for |
Beta Was this translation helpful? Give feedback.
-
print(os.date('%Y-%m-%V', os.time() + 3 * 7 * 24 * 60 * 60))
2022-01-52
print(os.date('%Y-%m-%V', os.time() + 3 * 7 * 24 * 60 * 60 - 24 * 60 * 60))
2021-12-52 Gives you everything you need to know: if it's week 52 but the month is 01, so it's up to you if you want to re-frame it as week 1 of 2022 - which would probably be incorrect (see calendar below). The signifier you're looking for is implicit: match month against week number and you'll see when they disagree like in the example above. But I think os.date does the right thing: So today in 3 weeks is in fact week 52 (of 2021) even though the date is Jan 1st, 2022. So in calendar week number theory, week 52 can span 2 years, apparently 😄 I don't see how renaming The week consists of 7 days and if you take the first day of the week as reference for |
Beta Was this translation helpful? Give feedback.
-
Thanks for the info! I use coc so I never thought of using null-ls until I switch to the builtin LSP client. But this makes me reconsider. |
Beta Was this translation helpful? Give feedback.
-
This is only a partially formed idea as I'm still mulling over the use cases, but being able to do simple day- and week-based math operations against the template tokens could be useful.
For example in a daily template maybe you a templated navigation bar:
or even with helper tokens:
This next one might be a little trickier depending on when you generate your weekly, but something similar for weeklies that automatically links to the dailies for the days of that week would be awesome.
Maybe I'll take a look at the source code this weekend to see if I've got the chops to put together a PR.
Beta Was this translation helpful? Give feedback.
All reactions