I am looking for a script to display a countdown until the last 3rd business day of the month, each month. For example, this month would be the 29th, and February would be 26th, March would be the 27th, and so on and so forth.
Ideally, I would like to have a tile that displays a countdown for it. For this, I’ll call it “Month End” and the tile should look like:
Month End
in 8 days
Month End
Today
Month End
in 32 days
If anyone can help me with this, it would be greatly appreciated!
Also, I am using the TrashCard integration from HACS, and considered using a chip to display it if I can figure out a way to make it work.
This template will get the number of days until the next 3rd last business day of the month. For the other formatting you described you can use a markdown card, or add it to this template.
{% set biz_day_offset = [-4, -4, -2, -2, -2, -3, -4] %}
{% set next_month = now().date().replace(day=28) + timedelta(days=4) %}
{% set third_month = next_month + timedelta(days=32) %}
{% set last_day_this = next_month - timedelta(days=next_month.day) %}
{% set last_day_next = third_month - timedelta(days=third_month.day) %}
{% set until_last_biz_day_this = (last_day_this + timedelta(days=biz_day_offset[last_day_this.weekday()]) - now().date()).days %}
{% set until_last_biz_day_next = (last_day_next + timedelta(days=biz_day_offset[last_day_next.weekday()]) - now().date()).days %}
{{ until_last_biz_day_this if until_last_biz_day_this >= 0 else until_last_biz_day_next }}
The business day offset basically says that if the last day of the month is Monday, you have to subtract 4 days to get to the third last business day (Thursday, in that case). Same with Tuesday (Friday), then Wednesday only needs to subtract 2 (Monday), … and so on.
I only checked January and Feburary and it seemed to work. Shame I didn’t check further. Anyways,I can probably add a new macro, but OP can use arts in combination with count_the_days.