Skip to content

Commit

Permalink
Fix displayed date for Created on column
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Nov 30, 2023
1 parent efb26d0 commit 88d9dd0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qgis-app/plugins/templates/plugins/plugin_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
{% if object.author %}
<td><a title="{% trans "See all plugins by"%} {{ object.author }}" href="{% url "author_plugins" object.author %}">{{ object.author }}</a></td>
{% endif %}
<td>{{ object.latest_version_date|local_timezone:"SHORT" }}</td>
<td>{{ object.latest_version_date|local_timezone:"SHORT_NATURAL_DAY" }}</td>
<td>{{ object.created_on|local_timezone:"SHORT" }}</td>
<td><div><div class="star-ratings"><span style="width:{% widthratio object.average_vote 5 100 %}%" class="rating"></span></div> ({{ object.rating_votes }})</div></td>
<td>{% if object.stable %}<a href="{% url "version_download" object.package_name object.stable.version %}" title="{% trans "Download the stable version" %}" >{{ object.stable.version }}</a>{% else %}&mdash;{% endif %}</td>
Expand Down
6 changes: 4 additions & 2 deletions qgis-app/plugins/templatetags/local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<span class="short-user-timezone">%s</span>' % (utcdate,)
if args and str(args) == "SHORT":
result = '<span class="user-timezone-short">%s</span>' % (utcdate,)
elif args and str(args) == "SHORT_NATURAL_DAY":
result = '<span class="user-timezone-short-naturalday">%s</span>' % (utcdate,)
else:
result = '<span class="user-timezone">%s</span>' % (utcdate,)
except AttributeError:
Expand Down
13 changes: 9 additions & 4 deletions qgis-app/static/js/local_timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
Expand Down

0 comments on commit 88d9dd0

Please sign in to comment.