Petro31 / easy-time-jinja

Easy Time calculations for Home Assistant templates
MIT License
68 stars 25 forks source link

Having problems running some of your examples in Developer Tools Template #12

Closed deepcoder closed 1 year ago

deepcoder commented 1 year ago

First, thank you for your work on this, useful!

In the Developer Tools (HA 2023.5.4), trying this function in the example, returns the error below:

last_day_in_month(month, weekday) https://github.com/Petro31/easy-time-jinja#last_day_in_monthmonth-weekday

{% from 'easy_time.jinja' import last_day_in_month %}

{# Last Sunday in August #}
{{ last_day_in_month(8, 6) }} 
{{ last_day_in_month(8, 6) | as_datetime }} 

returns:

UndefinedError: 'day' is undefined

Returns a rather odd answer:

{% from 'easy_time.jinja' import next_dst_phrase %}

{# Next daylight savings time #}
{{ next_dst_phrase() }} 
{{ next_dst_phrase() | as_datetime }} 
Result type: string
gain 53 years 
None

I have to do multiple imports to get below to run:

{% from 'easy_time.jinja' import days_in_month %}
{% from 'easy_time.jinja' import days_next_month %}
{% from 'easy_time.jinja' import days_last_month %}

{# Number of days this month #}
{{ days_in_month() | int }}

{# Number of days in december #}
{{ days_in_month(12) | int }}

{# Number of days in February #}
{# works on leap year #}
{{ days_in_month(2) | int }}

{# Number of days next month #}
{{ days_next_month() | int }}
{# Optionally add an offset for further in the future #}
{{ days_next_month(2) | int }}

{# Number of days last month #}
{{ days_last_month() | int }}

Petro31 commented 1 year ago

@deepcoder looks like a bug. I'll look into it.

Petro31 commented 1 year ago

FYI you can do multiple imports in 1 row

{% from 'easy_time.jinja' import days_in_month, days_next_month, days_last_month %}

image

and this isn't valid, probably a copy/paste error on my part. That phrase will only return gain/lose x time

{{ next_dst_phrase() | as_datetime }} 
ashkii7 commented 1 year ago

Hi, Like @deepcoder , i have the same error returned (UndefinedError: 'day' is undefined) with the command '{{ last_day_in_month(8, 6) | as_datetime }}' It's a shame, but thank you all the same for your excellent work elsewhere PS: I tested it In The Developer Tools (Ha 2023.6.2)

Petro31 commented 1 year ago

Fixed in next release

ashkii7 commented 1 year ago

Hi, Thanks you @Petro31 it works fine now