mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Switch to "adaptive" date display in most places
Switch to "adaptive" date display in most places
Previously, dates were always displayed in the relative, "ago" style, but these become pretty unwieldy for longer time spans, especially since the ago library I'm using jumps directly from days to years, so it will show ones like "200 days ago" that are hard to place. This adds an "adaptive" date display method and uses it almost everywhere instead. These will use the "ago" style for shorter periods, and then switch to showing an absolute date for dates longer ago than that. The threshold for the switch is currently set to 7 days.merge-requests/53/head
Chad Birch
6 years ago
8 changed files with 45 additions and 25 deletions
-
7tildes/tildes/jinja.py
-
21tildes/tildes/lib/datetime.py
-
6tildes/tildes/templates/macros/comments.jinja2
-
14tildes/tildes/templates/macros/datetime.jinja2
-
4tildes/tildes/templates/macros/messages.jinja2
-
4tildes/tildes/templates/macros/topics.jinja2
-
4tildes/tildes/templates/messages.jinja2
-
10tildes/tildes/templates/topic.jinja2
@ -1,19 +1,15 @@ |
|||
{# Copyright (c) 2018 Tildes contributors <code@tildes.net> #} |
|||
{# SPDX-License-Identifier: AGPL-3.0-or-later #} |
|||
|
|||
{% macro time_ago(datetime) -%} |
|||
<time datetime="{{ datetime.strftime('%Y-%m-%dT%H:%M:%SZ') }}" title="{{ datetime.strftime('%Y-%m-%d %H:%M:%S UTC') }}">{{ datetime|ago }}</time> |
|||
{% macro time_ago(datetime, abbreviate=False) -%} |
|||
<time datetime="{{ datetime.strftime('%Y-%m-%dT%H:%M:%SZ') }}" title="{{ datetime.strftime('%Y-%m-%d %H:%M:%S UTC') }}">{{ datetime|ago(abbreviate) }}</time> |
|||
{%- endmacro %} |
|||
|
|||
{% macro time_ago_abbreviated(datetime) -%} |
|||
<time datetime="{{ datetime.strftime('%Y-%m-%dT%H:%M:%SZ') }}" title="{{ datetime.strftime('%Y-%m-%d %H:%M:%S UTC') }}">{{ datetime|ago(abbreviate=True) }}</time> |
|||
{%- endmacro %} |
|||
|
|||
{% macro time_ago_responsive(datetime, class_=None) -%} |
|||
{% macro adaptive_date_responsive(datetime, class_=None) -%} |
|||
<time |
|||
class="time-responsive{{ ' '+class_ if class_ else '' }}" |
|||
datetime="{{ datetime.strftime('%Y-%m-%dT%H:%M:%SZ') }}" |
|||
title="{{ datetime.strftime('%Y-%m-%d %H:%M:%S UTC') }}" |
|||
data-abbreviated="{{ datetime|ago(abbreviate=True) }}" |
|||
><span class="time-responsive-full">{{ datetime|ago(abbreviate=False) }}</span></time> |
|||
data-abbreviated="{{ datetime|adaptive_date(abbreviate=True) }}" |
|||
><span class="time-responsive-full">{{ datetime|adaptive_date(abbreviate=False) }}</span></time> |
|||
{%- endmacro %} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue