Closes #15618: Always use ISO 8601 date & time formatting (#15737)

* Introduce the isodate(), isotime(), and isodatetime() template filters

* Display the relative time on mouse hover

* Render journal entry times in ISO 8601 format

* Use ISO 8601 format when displaying dates & times in a table

* Standardize the use of DateTimeColumn across all tables
This commit is contained in:
Jeremy Stretch
2024-04-17 11:46:47 -04:00
committed by GitHub
parent f0aca5bac1
commit 77a4300888
24 changed files with 109 additions and 67 deletions

View File

@@ -9,9 +9,9 @@
{% elif customfield.type == 'boolean' and value == False %}
{% checkmark value false="False" %}
{% elif customfield.type == 'date' and value %}
{{ value|annotated_date }}
{{ value|isodate }}
{% elif customfield.type == 'datetime' and value %}
{{ value|annotated_date }}
{{ value|isodate }} {{ value|isodatetime }}
{% elif customfield.type == 'url' and value %}
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
{% elif customfield.type == 'json' and value %}

View File

@@ -5,6 +5,7 @@ import re
import yaml
from django import template
from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.utils.html import escape
from django.utils.safestring import mark_safe
from markdown import markdown
@@ -20,6 +21,9 @@ __all__ = (
'content_type',
'content_type_id',
'fgcolor',
'isodate',
'isodatetime',
'isotime',
'linkify',
'meta',
'placeholder',
@@ -202,3 +206,36 @@ def render_yaml(value):
{{ data_dict|yaml }}
"""
return yaml.dump(json.loads(json.dumps(value)))
#
# Time & date
#
@register.filter()
def isodate(value):
if type(value) is datetime.date:
text = value.isoformat()
elif type(value) is datetime.datetime:
text = value.date().isoformat()
else:
return ''
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
@register.filter()
def isotime(value, spec='seconds'):
if type(value) is datetime.time:
return value.isoformat(timespec=spec)
if type(value) is datetime.datetime:
return value.time().isoformat(timespec=spec)
return ''
@register.filter()
def isodatetime(value, spec='seconds'):
if type(value) is datetime.datetime:
text = f'{isodate(value)} {isotime(value, spec=spec)}'
else:
return ''
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')