Convert edited timestamp to local time

This commit is contained in:
TheAMM 2017-11-10 05:50:50 +02:00
parent 0b094a7229
commit faf7548cd0
3 changed files with 13 additions and 3 deletions

View File

@ -449,6 +449,11 @@ class CommentBase(DeclarativeHelperBase):
''' Returns a UTC POSIX timestamp, as seconds '''
return (self.created_time - UTC_EPOCH).total_seconds()
@property
def edited_utc_timestamp(self):
''' Returns a UTC POSIX timestamp, as seconds '''
return (self.edited_time - UTC_EPOCH).total_seconds() if self.edited_time else 0
@property
def editable_until(self):
return self.created_utc_timestamp + config['EDITING_TIME_LIMIT']

View File

@ -174,6 +174,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
var target = timestamp_targets[i];
var torrent_timestamp = parseInt(target.getAttribute('data-timestamp'));
var swap_flag = target.getAttribute('data-timestamp-swap') != null;
var title_flag = target.getAttribute('data-timestamp-title') != null;
if (torrent_timestamp) {
var timedelta = now_timestamp - torrent_timestamp;
@ -182,10 +183,14 @@ document.addEventListener("DOMContentLoaded", function(event) {
var formatted_timedelta = _format_time_difference(timedelta);
if (swap_flag) {
target.setAttribute('title', formatted_date);
target.innerText = formatted_timedelta;
if (!title_flag) {
target.innerText = formatted_timedelta;
}
} else {
target.setAttribute('title', formatted_timedelta);
target.innerText = formatted_date;
if (!title_flag) {
target.innerText = formatted_date;
}
}
}
};

View File

@ -156,7 +156,7 @@
<div class="row comment-details">
<a href="#com-{{ loop.index }}"><small data-timestamp-swap data-timestamp="{{ comment.created_utc_timestamp|int }}">{{ comment.created_time.strftime('%Y-%m-%d %H:%M UTC') }}</small></a>
{% if comment.edited_time %}
<small title="{{ comment.edited_time }}">(edited)</small>
<small data-timestamp-swap data-timestamp-title data-timestamp="{{ comment.edited_utc_timestamp }}" title="{{ comment.edited_time }}">(edited)</small>
{% endif %}
<div class="comment-actions">
{% if g.user.id == comment.user_id and not comment.editing_limit_exceeded %}