That is easy, because weekday sunday is zero and the only thing needed is to subtract the weekday. But with friday the weekday will have a jump back to zero on sunday.
What is the easiest way to get the computer time since last friday?
The whole time I was doing this I thought there must be an easier way with modular arithmetic.
start: >
{% set weekday = now().weekday() %}
{% set offset = 3 if weekday < 5 else -4 %}
{{ today_at('00:00') - timedelta(days = weekday - offset) }}
Looks like Olivier worked that out. I tested his formula in the template editor with all the integer days. It works as long as you want a whole week instead of 0 days on Friday.
Sorry, maybe my brain made monday to 1, because that was how I understood the start.
Let’s say it’s monday, that would mean weekday() is 0. But how does the example work?
Isn’t today_at(‘00:00’) - 0 the same as today and not yesterday?
Many thanks Olivier and Tom for your solution. I went through Oliviers solution with pen and paper. Here it is -1 for Saturday, which feels to be right. But for friday it will be -7 and shouldn’t that be -0?
I guess that is the same misunderstanding as already with the example
Edit: friday will of course be -7. I forgot to add the +1
start: >
{% set weekday = now().weekday() %}
{% set offset = 3 if weekday < 5 else -4 %}
{{ today_at('00:00') - timedelta(days = weekday - offset) }}
Today we have saturday which is weekday 5. Therefore, it isn’t smaller than 5 and the offset will be set to -4.
5 - (-4) is 9. and should be 1. Changing the timedelta to week + offset will correct it for saturday, but will be incorrect for the other days.