mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 09:00:33 +00:00
Merge pull request #967 from bookwyrm-social/date-localization
Fixes localization weirdness with dates
This commit is contained in:
commit
baa423bb69
5 changed files with 4 additions and 55 deletions
|
@ -1,6 +1,7 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load humanize %}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% with format=book.physical_format pages=book.pages %}
|
{% with format=book.physical_format pages=book.pages %}
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% with date=book.published_date|date:'M jS Y' publisher=book.publishers|join:', ' %}
|
{% with date=book.published_date|naturalday publisher=book.publishers|join:', ' %}
|
||||||
{% if date or book.first_published_date %}
|
{% if date or book.first_published_date %}
|
||||||
<meta
|
<meta
|
||||||
itemprop="datePublished"
|
itemprop="datePublished"
|
||||||
|
|
|
@ -123,7 +123,7 @@
|
||||||
{% include 'snippets/status_preview.html' with status=related_status %}
|
{% include 'snippets/status_preview.html' with status=related_status %}
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-narrow {% if notification.notification_type == 'REPLY' or notification.notification_type == 'MENTION' %}has-text-black{% else %}has-text-grey-dark{% endif %}">
|
<div class="column is-narrow {% if notification.notification_type == 'REPLY' or notification.notification_type == 'MENTION' %}has-text-black{% else %}has-text-grey-dark{% endif %}">
|
||||||
{{ related_status.published_date | post_date }}
|
{{ related_status.published_date|timesince }}
|
||||||
{% include 'snippets/privacy-icons.html' with item=related_status %}
|
{% include 'snippets/privacy-icons.html' with item=related_status %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer-item">
|
<div class="card-footer-item">
|
||||||
<a href="{{ status.remote_id }}">{{ status.published_date | post_date }}</a>
|
<a href="{{ status.remote_id }}">{{ status.published_date|timesince }}</a>
|
||||||
</div>
|
</div>
|
||||||
{% if not moderation_mode %}
|
{% if not moderation_mode %}
|
||||||
<div class="card-footer-item">
|
<div class="card-footer-item">
|
||||||
|
|
|
@ -129,28 +129,6 @@ def get_uuid(identifier):
|
||||||
return "%s%s" % (identifier, uuid4())
|
return "%s%s" % (identifier, uuid4())
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="post_date")
|
|
||||||
def time_since(date):
|
|
||||||
""" concise time ago function """
|
|
||||||
if not isinstance(date, datetime):
|
|
||||||
return ""
|
|
||||||
now = timezone.now()
|
|
||||||
|
|
||||||
if date < (now - relativedelta(weeks=1)):
|
|
||||||
formatter = "%b %-d"
|
|
||||||
if date.year != now.year:
|
|
||||||
formatter += " %Y"
|
|
||||||
return date.strftime(formatter)
|
|
||||||
delta = relativedelta(now, date)
|
|
||||||
if delta.days:
|
|
||||||
return "%dd" % delta.days
|
|
||||||
if delta.hours:
|
|
||||||
return "%dh" % delta.hours
|
|
||||||
if delta.minutes:
|
|
||||||
return "%dm" % delta.minutes
|
|
||||||
return "%ds" % delta.seconds
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="to_markdown")
|
@register.filter(name="to_markdown")
|
||||||
def get_markdown(content):
|
def get_markdown(content):
|
||||||
""" convert markdown to html """
|
""" convert markdown to html """
|
||||||
|
|
|
@ -181,36 +181,6 @@ class TemplateTags(TestCase):
|
||||||
uuid = bookwyrm_tags.get_uuid("hi")
|
uuid = bookwyrm_tags.get_uuid("hi")
|
||||||
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
|
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
|
||||||
|
|
||||||
def test_time_since(self, _):
|
|
||||||
""" ultraconcise timestamps """
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since("bleh"), "")
|
|
||||||
|
|
||||||
now = timezone.now()
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since(now), "0s")
|
|
||||||
|
|
||||||
seconds_ago = now - relativedelta(seconds=4)
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since(seconds_ago), "4s")
|
|
||||||
|
|
||||||
minutes_ago = now - relativedelta(minutes=8)
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since(minutes_ago), "8m")
|
|
||||||
|
|
||||||
hours_ago = now - relativedelta(hours=9)
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since(hours_ago), "9h")
|
|
||||||
|
|
||||||
days_ago = now - relativedelta(days=3)
|
|
||||||
self.assertEqual(bookwyrm_tags.time_since(days_ago), "3d")
|
|
||||||
|
|
||||||
# I am not going to figure out how to mock dates tonight.
|
|
||||||
months_ago = now - relativedelta(months=5)
|
|
||||||
self.assertTrue(
|
|
||||||
re.match(r"[A-Z][a-z]{2} \d?\d", bookwyrm_tags.time_since(months_ago))
|
|
||||||
)
|
|
||||||
|
|
||||||
years_ago = now - relativedelta(years=10)
|
|
||||||
self.assertTrue(
|
|
||||||
re.match(r"[A-Z][a-z]{2} \d?\d \d{4}", bookwyrm_tags.time_since(years_ago))
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_get_markdown(self, _):
|
def test_get_markdown(self, _):
|
||||||
""" mardown format data """
|
""" mardown format data """
|
||||||
result = bookwyrm_tags.get_markdown("_hi_")
|
result = bookwyrm_tags.get_markdown("_hi_")
|
||||||
|
|
Loading…
Reference in a new issue