timezones
This commit is contained in:
parent
1e80907235
commit
65a2038da2
|
@ -80,9 +80,12 @@
|
|||
<p>
|
||||
<span title="{{ view.country_name }}" class="unselectable">{{ view.country_flag.emoji }}</span>
|
||||
<span title="{{ view.region }}">{{ view.region }}</span>
|
||||
{% if view.referer is not null %}<samp>(<small title="{{ view.referer }}‎">{{ view.referer }}‎</small>)</samp>{% endif %}
|
||||
{% if view.referer is not null %}<samp>(<small title="{{ view.referer }}‎">{{ view.referer
|
||||
}}‎</small>)</samp>{% endif %}
|
||||
<span title="{{ view.useragent }}">{{ view['x-forwarded-for'] ?? view.ip }}</span>
|
||||
<span title="{{ view.created|date('Y.m.d H:i:s') }}"><b>{{ view.created|date('H:i:s') }}</b></span>
|
||||
<span title="{{ view.created }}" data-date-convert="title" data-date-convert-format="year.month.day hour:minute:second">
|
||||
<b data-date-convert="value">{{ view.created }}</b>
|
||||
</span>
|
||||
</p>
|
||||
{% endfor %}
|
||||
</section>
|
||||
|
@ -146,6 +149,62 @@
|
|||
{{ block('header_js_init') }}
|
||||
{{ block('troller_js_init') }}
|
||||
<script>
|
||||
// Generate dates with user timezone
|
||||
for (const element of document.body.querySelectorAll('[data-date-convert]')) {
|
||||
// Enumerating elements to convert
|
||||
|
||||
// Initializing a format of convertation
|
||||
const format = element.getAttribute('data-date-convert-format') ?? 'hour:minute:second';
|
||||
|
||||
if (element.getAttribute('data-date-convert') === 'title') {
|
||||
// Title
|
||||
|
||||
// Initializing a date with timezone
|
||||
const date = new Date(element.getAttribute('title') * 1000);
|
||||
|
||||
// Initializing parts of the date
|
||||
let year = date.getFullYear();
|
||||
let month = date.getMonth() + 1;
|
||||
let day = date.getDay();
|
||||
let hour = date.getHours();
|
||||
let minute = date.getMinutes();
|
||||
let second = date.getSeconds();
|
||||
|
||||
// Convertation parts of the date to double symbols
|
||||
month = (month < 10 ? "0" : '') + month;
|
||||
day = (day < 10 ? "0" : '') + day;
|
||||
hour = (hour < 10 ? "0" : '') + hour;
|
||||
minute = (minute < 10 ? "0" : '') + minute;
|
||||
second = (second < 10 ? "0" : '') + second;
|
||||
|
||||
if (format === 'hour:minute:second') element.setAttribute('title', `${hour}:${minute}:${second}`);
|
||||
else if (format === 'year.month.day hour:minute:second') element.setAttribute('title', `${year}.${month}.${day} ${hour}:${minute}:${second}`);
|
||||
} else {
|
||||
// Value (implied)
|
||||
|
||||
// Initializin a date with timezone
|
||||
const date = new Date(element.innerText * 1000);
|
||||
|
||||
// Initializing parts of the date
|
||||
let year = date.getFullYear();
|
||||
let month = date.getMonth() + 1;
|
||||
let day = date.getDay();
|
||||
let hour = date.getHours();
|
||||
let minute = date.getMinutes();
|
||||
let second = date.getSeconds();
|
||||
|
||||
// Convertation parts of the date to double symbols
|
||||
month = (month < 10 ? "0" : '') + month;
|
||||
day = (day < 10 ? "0" : '') + day;
|
||||
hour = (hour < 10 ? "0" : '') + hour;
|
||||
minute = (minute < 10 ? "0" : '') + minute;
|
||||
second = (second < 10 ? "0" : '') + second;
|
||||
|
||||
if (format === 'hour:minute:second') element.innerText = `${hour}:${minute}:${second}`;
|
||||
else if (format === 'year.month.day hour:minute:second') element.innerText = `${year}.${month}.${day} ${hour}:${minute}:${second}`;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('bloodchaos.loaded', function(e) {
|
||||
const bloodchaos = e.detail.bloodchaos;
|
||||
|
||||
|
|
Loading…
Reference in New Issue