mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 10:19:59 +00:00
Convert UTC to local time in JS
Also adds classes to row headers to accurately access them in JS. Updates the serverside date format in view.html to match YYYY-MM-DD HH:MM
This commit is contained in:
parent
b147cfeb81
commit
cf77b03a6f
|
@ -62,7 +62,14 @@ function _format_time_difference(seconds) {
|
||||||
}
|
}
|
||||||
return prefix + parts.join(" ") + suffix;
|
return prefix + parts.join(" ") + suffix;
|
||||||
}
|
}
|
||||||
|
function _format_date(date) {
|
||||||
|
var pad = function (n) { return ("00" + n).slice(-2); }
|
||||||
|
var ymd = date.getFullYear() + "-" + pad(date.getMonth()+1) + "-" + pad(date.getDate());
|
||||||
|
var hm = pad(date.getHours()) + ":" + pad(date.getMinutes());
|
||||||
|
return ymd + " " + hm;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add title text to elements with data-timestamp attribute
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
var now_timestamp = (Date.now() / 1000) | 0; // UTC timestamp in seconds
|
var now_timestamp = (Date.now() / 1000) | 0; // UTC timestamp in seconds
|
||||||
|
|
||||||
|
@ -73,8 +80,17 @@ document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
if (torrent_timestamp) {
|
if (torrent_timestamp) {
|
||||||
var timedelta = now_timestamp - torrent_timestamp;
|
var timedelta = now_timestamp - torrent_timestamp;
|
||||||
target.setAttribute('title', _format_time_difference(timedelta));
|
target.setAttribute('title', _format_time_difference(timedelta));
|
||||||
|
|
||||||
|
var asd = new Date(torrent_timestamp*1000);
|
||||||
|
console.log(torrent_timestamp, asd);
|
||||||
|
target.innerText = _format_date(asd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var header_date = document.querySelector('.hdr-date');
|
||||||
|
if (header_date) {
|
||||||
|
header_date.setAttribute('title', 'In local time');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialise markdown editors on page
|
// Initialise markdown editors on page
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% macro render_column_header(header_style, center_text=False, sort_key=None, header_title=None) %}
|
{% macro render_column_header(header_class, header_style, center_text=False, sort_key=None, header_title=None) %}
|
||||||
{% set class_suffix = (search.sort == sort_key) and ("_" + search.order) or "" %}
|
{% set class_suffix = (search.sort == sort_key) and ("_" + search.order) or "" %}
|
||||||
{% set th_classes = filter_truthy([sort_key and "sorting" + class_suffix, center_text and "text-center"]) %}
|
{% set th_classes = filter_truthy([header_class, sort_key and "sorting" + class_suffix, center_text and "text-center"]) %}
|
||||||
<th {% if th_classes %} class="{{ ' '.join(th_classes) }}"{% endif %} {% if header_title %}title="{{ header_title }}"{% endif %} style="{{ header_style }}">
|
<th {% if th_classes %} class="{{ ' '.join(th_classes) }}"{% endif %} {% if header_title %}title="{{ header_title }}"{% endif %} style="{{ header_style }}">
|
||||||
{% if sort_key %}
|
{% if sort_key %}
|
||||||
<a href="{% if class_suffix == '_desc' %}{{ modify_query(s=sort_key, o="asc") }}{% else %}{{ modify_query(s=sort_key, o="desc") }}{% endif %}"></a>
|
<a href="{% if class_suffix == '_desc' %}{{ modify_query(s=sort_key, o="asc") }}{% else %}{{ modify_query(s=sort_key, o="desc") }}{% endif %}"></a>
|
||||||
|
@ -13,31 +13,31 @@
|
||||||
<table class="table table-bordered table-hover table-striped torrent-list">
|
<table class="table table-bordered table-hover table-striped torrent-list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% call render_column_header("width:80px;", center_text=True) %}
|
{% call render_column_header("hdr-category", "width:80px;", center_text=True) %}
|
||||||
<div>Category</div>
|
<div>Category</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:auto;", sort_key="name") %}
|
{% call render_column_header("hdr-name", "width:auto;", sort_key="name") %}
|
||||||
<div>Name</div>
|
<div>Name</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:0;", center_text=True) %}
|
{% call render_column_header("hdr-link", "width:0;", center_text=True) %}
|
||||||
<div>Link</div>
|
<div>Link</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:100px;", center_text=True, sort_key="size") %}
|
{% call render_column_header("hdr-size", "width:100px;", center_text=True, sort_key="size") %}
|
||||||
<div>Size</div>
|
<div>Size</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:140px;", center_text=True, sort_key="id", header_title="In UTC") %}
|
{% call render_column_header("hdr-date", "width:140px;", center_text=True, sort_key="id", header_title="In UTC") %}
|
||||||
<div>Date</div>
|
<div>Date</div>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
{% if config.ENABLE_SHOW_STATS %}
|
{% if config.ENABLE_SHOW_STATS %}
|
||||||
{% call render_column_header("width:50px;", center_text=True, sort_key="seeders", header_title="Seeds") %}
|
{% call render_column_header("hdr-seeders", "width:50px;", center_text=True, sort_key="seeders", header_title="Seeds") %}
|
||||||
<i class="fa fa-arrow-up" aria-hidden="true"></i>
|
<i class="fa fa-arrow-up" aria-hidden="true"></i>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:50px;", center_text=True, sort_key="leechers", header_title="Leeches") %}
|
{% call render_column_header("hdr-leechers", "width:50px;", center_text=True, sort_key="leechers", header_title="Leeches") %}
|
||||||
<i class="fa fa-arrow-down" aria-hidden="true"></i>
|
<i class="fa fa-arrow-down" aria-hidden="true"></i>
|
||||||
|
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call render_column_header("width:50px;", center_text=True, sort_key="downloads", header_title="Completed downloads") %}
|
{% call render_column_header("hdr-downloads", "width:50px;", center_text=True, sort_key="downloads", header_title="Completed downloads") %}
|
||||||
<i class="fa fa-check" aria-hidden="true"></i>
|
<i class="fa fa-check" aria-hidden="true"></i>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-1">Date:</div>
|
<div class="col-md-1">Date:</div>
|
||||||
<div class="col-md-5" data-timestamp="{{ torrent.created_utc_timestamp|int }}">{{ torrent.created_time.strftime('%Y-%m-%d, %H:%M UTC') }}</div>
|
<div class="col-md-5" data-timestamp="{{ torrent.created_utc_timestamp|int }}">{{ torrent.created_time.strftime('%Y-%m-%d %H:%M UTC') }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Reference in a new issue