-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from bartfeenstra/html-time
Implement the HTML <time> element.
- Loading branch information
Showing
3 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{%- macro format(date) -%} | ||
{# All components. #} | ||
{%- if date.year and date.month and date.day -%} | ||
{%- set formatted = calendar.month_name[date.month] + ' ' + date.day | string + ', ' + date.year | string -%} | ||
{%- set timevals = [date.year, '{:0>2}'.format(date.month), '{:0>2}'.format(date.day)] -%} | ||
{# No year, but month and day. #} | ||
{%- elif not date.year and date.month and date.day -%} | ||
{%- set formatted = calendar.month_name[date.month] + ' ' + date.day | string -%} | ||
{%- set timevals = ['{:0>2}'.format(date.month), '{:0>2}'.format(date.day)] -%} | ||
{# No month, but year. #} | ||
{%- elif date.year and not date.month -%} | ||
{%- set formatted = date.year | string -%} | ||
{%- set timevals = [date.year] -%} | ||
{# No day, but year and month. #} | ||
{%- elif date.year and date.month and not date.day -%} | ||
{%- set formatted = calendar.month_name[date.month] + ', ' + date.year | string -%} | ||
{%- set timevals = [date.year, '{:0>2}'.format(date.month)] -%} | ||
{%- else -%} | ||
{%- set formatted = 'unknown date' -%} | ||
{%- endif -%} | ||
{%- if timevals is defined -%} | ||
<time datetime="{{ timevals | join('-') }}">{{ formatted }}</time> | ||
{%- else -%} | ||
{{ formatted }} | ||
{%- endif -%} | ||
{%- endmacro -%} |