Skip to content

Commit

Permalink
Add datetime support for month and weekdayu
Browse files Browse the repository at this point in the history
  • Loading branch information
Petro31 committed Nov 17, 2023
1 parent 4e9c50d commit 7f70ee8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions easy_time.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1474,12 +1474,24 @@
{%- endmacro -%}

{%- macro month(month=None, language=default_language) %}
{%- set idx = (month - 1) % 12 if month is integer and month > 0 else now().month - 1 %}
{%- if month is datetime %}
{%- set idx = month.month - 1 %}
{%- elif month is integer and month > 0 %}
{%- set idx = (month - 1) % 12 %}
{%- else %}
{%- set idx = now().month - 1 %}
{%- endif %}
{{- languages.get(language, {}).get('months', [_bad_value]*12)[idx] }}
{%- endmacro %}

{%- macro weekday(weekday=None, language=default_language) %}
{%- set idx = (weekday - 1) % 7 if weekday is integer and weekday > 0 else now().weekday() %}
{%- if weekday is datetime %}
{%- set idx = weekday.weekday() %}
{%- elif weekday is integer and weekday > 0 %}
{%- set idx = (weekday - 1) % 7 %}
{%- else %}
{%- set idx = now().weekday() %}
{%- endif %}
{{- languages.get(language, {}).get('days', [_bad_value]*7)[idx] }}
{%- endmacro %}

Expand Down

0 comments on commit 7f70ee8

Please sign in to comment.