mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-27 17:00:52 +01:00
fix local-time somehow
this fixes it. i don't know how. don't ask. i'm not a javascript guy much.
This commit is contained in:
parent
2d6b599b26
commit
d2f1b7e0e0
@ -17,29 +17,40 @@ $(document).ready(function(){
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var iso8601 = function(s) {
|
var iso8601 = function(s) {
|
||||||
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
|
var parts = s.split('T');
|
||||||
s = s.replace(/-/,"/").replace(/-/,"/");
|
if (parts.length === 2) {
|
||||||
s = s.replace(/T/," ").replace(/Z/," UTC");
|
var timeParts = parts[1].split(':');
|
||||||
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
if (timeParts.length === 3) {
|
||||||
|
var secondsParts = timeParts[2].split('.');
|
||||||
|
if (secondsParts[0] > 59) {
|
||||||
|
secondsParts[0] = '59';
|
||||||
|
}
|
||||||
|
timeParts[2] = secondsParts.join('.');
|
||||||
|
}
|
||||||
|
parts[1] = timeParts.join(':');
|
||||||
|
}
|
||||||
|
s = parts.join('T');
|
||||||
|
if (!s.endsWith('Z')) {
|
||||||
|
s += 'Z';
|
||||||
|
}
|
||||||
return new Date(s);
|
return new Date(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
var zeropad = function(num, count) {
|
var zeropad = function(num, count) {
|
||||||
return [Math.pow(10, count - num.toString().length), num].join('').substr(1);
|
return [Math.pow(10, count - num.toString().length), num].join('').substr(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
var dateformat = (typeof strftime === 'undefined') ? function(t) {
|
var dateformat = (typeof strftime === 'undefined') ? function(t) {
|
||||||
return zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
|
return zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
|
||||||
" (" + [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")][t.getDay()] + ") " +
|
" (" + ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][t.getDay()] + ") " +
|
||||||
// time
|
// time
|
||||||
zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
|
zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
|
||||||
|
|
||||||
} : function(t) {
|
} : function(t) {
|
||||||
// post_date is defined in templates/main.js
|
// post_date is defined in templates/main.js
|
||||||
return strftime(window.post_date, t, datelocale);
|
return strftime(window.post_date, t, datelocale);
|
||||||
};
|
};
|
||||||
|
|
||||||
function timeDifference(current, previous) {
|
function timeDifference(current, previous) {
|
||||||
|
|
||||||
var msPerMinute = 60 * 1000;
|
var msPerMinute = 60 * 1000;
|
||||||
var msPerHour = msPerMinute * 60;
|
var msPerHour = msPerMinute * 60;
|
||||||
var msPerDay = msPerHour * 24;
|
var msPerDay = msPerHour * 24;
|
||||||
@ -51,36 +62,35 @@ $(document).ready(function(){
|
|||||||
if (elapsed < msPerMinute) {
|
if (elapsed < msPerMinute) {
|
||||||
return 'Just now';
|
return 'Just now';
|
||||||
} else if (elapsed < msPerHour) {
|
} else if (elapsed < msPerHour) {
|
||||||
return Math.round(elapsed/msPerMinute) + (Math.round(elapsed/msPerMinute)<=1 ? ' minute ago':' minutes ago');
|
return Math.round(elapsed / msPerMinute) + (Math.round(elapsed / msPerMinute) <= 1 ? ' minute ago' : ' minutes ago');
|
||||||
} else if (elapsed < msPerDay ) {
|
} else if (elapsed < msPerDay) {
|
||||||
return Math.round(elapsed/msPerHour ) + (Math.round(elapsed/msPerHour)<=1 ? ' hour ago':' hours ago');
|
return Math.round(elapsed / msPerHour) + (Math.round(elapsed / msPerHour) <= 1 ? ' hour ago' : ' hours ago');
|
||||||
} else if (elapsed < msPerMonth) {
|
} else if (elapsed < msPerMonth) {
|
||||||
return Math.round(elapsed/msPerDay) + (Math.round(elapsed/msPerDay)<=1 ? ' day ago':' days ago');
|
return Math.round(elapsed / msPerDay) + (Math.round(elapsed / msPerDay) <= 1 ? ' day ago' : ' days ago');
|
||||||
} else if (elapsed < msPerYear) {
|
} else if (elapsed < msPerYear) {
|
||||||
return Math.round(elapsed/msPerMonth) + (Math.round(elapsed/msPerMonth)<=1 ? ' month ago':' months ago');
|
return Math.round(elapsed / msPerMonth) + (Math.round(elapsed / msPerMonth) <= 1 ? ' month ago' : ' months ago');
|
||||||
} else {
|
} else {
|
||||||
return Math.round(elapsed/msPerYear ) + (Math.round(elapsed/msPerYear)<=1 ? ' year ago':' years ago');
|
return Math.round(elapsed / msPerYear) + (Math.round(elapsed / msPerYear) <= 1 ? ' year ago' : ' years ago');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var do_localtime = function(elem) {
|
var do_localtime = function(elem) {
|
||||||
var times = elem.getElementsByTagName('time');
|
var times = elem.getElementsByTagName('time');
|
||||||
var currentTime = Date.now();
|
var currentTime = Date.now();
|
||||||
|
|
||||||
for(var i = 0; i < times.length; i++) {
|
for (var i = 0; i < times.length; i++) {
|
||||||
var t = times[i].getAttribute('datetime');
|
var t = times[i].getAttribute('datetime');
|
||||||
var postTime = new Date(t);
|
var postTime = iso8601(t);
|
||||||
|
|
||||||
times[i].setAttribute('data-local', 'true');
|
times[i].setAttribute('data-local', 'true');
|
||||||
|
|
||||||
if (localStorage.show_relative_time === 'false') {
|
if (localStorage.show_relative_time === 'false') {
|
||||||
times[i].innerHTML = dateformat(iso8601(t));
|
times[i].innerHTML = dateformat(postTime);
|
||||||
times[i].setAttribute('title', timeDifference(currentTime, postTime.getTime()));
|
times[i].setAttribute('title', timeDifference(currentTime, postTime.getTime()));
|
||||||
} else {
|
} else {
|
||||||
times[i].innerHTML = timeDifference(currentTime, postTime.getTime());
|
times[i].innerHTML = timeDifference(currentTime, postTime.getTime());
|
||||||
times[i].setAttribute('title', dateformat(iso8601(t)));
|
times[i].setAttribute('title', dateformat(postTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,7 +111,7 @@ $(document).ready(function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (localStorage.show_relative_time !== 'false') {
|
if (localStorage.show_relative_time !== 'false') {
|
||||||
$('#show-relative-time>input').attr('checked','checked');
|
$('#show-relative-time>input').attr('checked', 'checked');
|
||||||
interval_id = setInterval(do_localtime, 30000, document);
|
interval_id = setInterval(do_localtime, 30000, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user