-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #877 - Updates date format #3240
Changes from all commits
e76b80e
c81d3f1
706ea74
dd6a4bd
c541b74
94b809f
100f5eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,9 @@ | |
{% macro render(datetime, | ||
show_value_for={'date':true, 'time':true, 'timezone':true}) %} | ||
<span class="datetime"> | ||
{% if show_value_for.date == true %} | ||
{% if show_value_for.date == true %} | ||
<time class="datetime_date" datetime="{{ dt.format_datetime(datetime) }}"> | ||
{{ dt.format_date(datetime) }} | ||
{{ render_date_no_markup(datetime, show_value_for) }} | ||
</time> | ||
{% endif %} | ||
|
||
|
@@ -41,3 +41,20 @@ | |
{% endif %} | ||
</span> | ||
{% endmacro %} | ||
|
||
{% macro render_date_no_markup(datetime, | ||
show_value_for={'date':true, 'time':true, 'timezone':true}) %} | ||
{# TODO: Replace this with a custom Jinja method that uses | ||
https://dateutil.readthedocs.io/ #} | ||
{# Displays the date in the format: MMM. DD, YYYY #} | ||
{% set format_month = '{dt:%b}'.format(dt = datetime) %} | ||
{% if format_month == 'May' %} | ||
{# May doesn't have a period. #} | ||
{{ '{dt:%b} {dt.day}, {dt.year}'.format(dt = datetime) }} | ||
{% elif format_month == 'Sep' %} | ||
{# September is four letters. #} | ||
{{ 'Sept. {dt.day}, {dt.year}'.format(dt = datetime) }} | ||
{% else %} | ||
{{ '{dt:%b}. {dt.day}, {dt.year}'.format(dt = datetime) }} | ||
{% endif %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spent some time thinking about this and looking at possible alternatives. I couldn't find a Python library that has built-in support for formatting months like this (conditionality around when a month is abbreviated and to what character-number). At the very least, I don't think this should be in the template itself, it should be a filter or something similar that can be called from any template (particularly if this is the standardized way to refer to dates) and can be properly unittested. It would also simplify the logic greatly to use a mapping (like Python's build-in datetime library) of month number to abbreviation instead of ifs/elses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it further, a custom wrapper around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all sounds well and good and over my head 😄 |
||
{% endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ehhhh, I'm not crazy about it. @richaagarwal, do you know a better way to write this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's awesome! Best code I've ever written! Look at all the brackets!