I am trying to create a widget, that shows different item depending on the calendar week/week of the year.
The widget is a list and I use the filter function to show/hide certain items.
But I can’t set the filter for calendar week/week of the year.
For other thinks I use dayjs but =dayjs().weekYear() does not work.
Is there a way to use the calendar week in the filter section of an list widget.
weekYear() is not available because it requires a day.js plugin that is not loaded.
The currently loaded plugins is rather limited:
This list is not final, only those plugins with universally useful functionality or a tiny overhead were included, but PRs that add more will likely be accepted.
Surely better, if you use widget expressions to make complex computations or derive states rather than just formatting the display, you’re probably doing something wrong.
You could have a single number item and a very simple rule that keeps the current day in your 4-week period (i.e. incremented every day and resets to 0 when it reaches 28).
To display the name of the 15th day (if the 4-week period starts on Monday) you can use: =dayjs().startOf('isoWeek').add(15, 'day').format('dddd')
(replace 15 with your item’s state)
If your language in Regional Settings is German it will yield “Dienstag” in this case.
If you want it in English: =dayjs().locale('en').startOf('isoWeek').add(15, 'day').format('dddd')
But if your regional settings are not to set to German you can’t use locale('de') - only English and the current language are loaded.
And btw after you’re replaced with the state of the item (number of days after the first Monday of the period) should always be the current day, so if it’s not, you know that the rule failed to run at least once - can happen if your system was offline. Then you just adjust the item.