From efb26d07776b8ec8c99af5d857e63ee08e1007ba Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:04:21 +0300 Subject: [PATCH 1/2] Implement moment.js, fix different displayed date --- .../templates/plugins/plugin_list.html | 5 +- .../templates/plugins/version_detail.html | 3 +- .../plugins/templatetags/local_timezone.py | 7 +- qgis-app/static/js/local_timezone.js | 22 +- qgis-app/static/js/moment.min.js | 5685 +++++++++++++++++ qgis-app/templates/base.html | 1 + 6 files changed, 5714 insertions(+), 9 deletions(-) create mode 100644 qgis-app/static/js/moment.min.js diff --git a/qgis-app/plugins/templates/plugins/plugin_list.html b/qgis-app/plugins/templates/plugins/plugin_list.html index 513a8d09..f2e28b06 100644 --- a/qgis-app/plugins/templates/plugins/plugin_list.html +++ b/qgis-app/plugins/templates/plugins/plugin_list.html @@ -1,4 +1,5 @@ {% extends 'plugins/plugin_base.html' %}{% load i18n bootstrap_pagination humanize static sort_anchor range_filter thumbnail %} +{% load local_timezone %} {% block extrajs %} + From 88d9dd0c58a0986351027e852487eb689ff948ed Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:16:36 +0300 Subject: [PATCH 2/2] Fix displayed date for Created on column --- qgis-app/plugins/templates/plugins/plugin_list.html | 2 +- qgis-app/plugins/templatetags/local_timezone.py | 6 ++++-- qgis-app/static/js/local_timezone.js | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/qgis-app/plugins/templates/plugins/plugin_list.html b/qgis-app/plugins/templates/plugins/plugin_list.html index f2e28b06..c959d4f8 100644 --- a/qgis-app/plugins/templates/plugins/plugin_list.html +++ b/qgis-app/plugins/templates/plugins/plugin_list.html @@ -94,7 +94,7 @@

{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}

{% if object.author %} {{ object.author }} {% endif %} - {{ object.latest_version_date|local_timezone:"SHORT" }} + {{ object.latest_version_date|local_timezone:"SHORT_NATURAL_DAY" }} {{ object.created_on|local_timezone:"SHORT" }}
({{ object.rating_votes }})
{% if object.stable %}{{ object.stable.version }}{% else %}—{% endif %} diff --git a/qgis-app/plugins/templatetags/local_timezone.py b/qgis-app/plugins/templatetags/local_timezone.py index 1fabb173..8463a9be 100644 --- a/qgis-app/plugins/templatetags/local_timezone.py +++ b/qgis-app/plugins/templatetags/local_timezone.py @@ -9,8 +9,10 @@ def local_timezone(date, args="LONG"): try: utcdate = date.astimezone(pytz.utc).isoformat() - if args and str(args).lower() == "short": - result = '%s' % (utcdate,) + if args and str(args) == "SHORT": + result = '%s' % (utcdate,) + elif args and str(args) == "SHORT_NATURAL_DAY": + result = '%s' % (utcdate,) else: result = '%s' % (utcdate,) except AttributeError: diff --git a/qgis-app/static/js/local_timezone.js b/qgis-app/static/js/local_timezone.js index a8605b7f..6b6cca21 100644 --- a/qgis-app/static/js/local_timezone.js +++ b/qgis-app/static/js/local_timezone.js @@ -5,12 +5,17 @@ $(".user-timezone").each(function (i) { $(this).text(localDate); }) -$(".short-user-timezone").each(function (i) { - let localDate = toUserTimeZone($(this).text(), false); +$(".user-timezone-short").each(function (i) { + let localDate = toUserTimeZone($(this).text(), withTime=false); $(this).text(localDate); }) -function toUserTimeZone(date, withTime=true) { +$(".user-timezone-short-naturalday").each(function (i) { + let localDate = toUserTimeZone($(this).text(), withTime=false, isNaturalDay=true); + $(this).text(localDate); +}) + +function toUserTimeZone(date, withTime=true, isNaturalDay=false) { try { date = new Date(date); let options = { @@ -23,7 +28,7 @@ function toUserTimeZone(date, withTime=true) { } const diffInDays = moment().diff(moment(date), 'days'); - if (diffInDays <= 1 && !withTime) { + if (diffInDays <= 1 && isNaturalDay) { const distance = moment(date).fromNow(); return distance }