Use data-utc for time formatting & localization.
This commit is contained in:
parent
16b4fd5424
commit
436b72416d
@ -448,56 +448,6 @@
|
|||||||
},
|
},
|
||||||
open: function(url) {
|
open: function(url) {
|
||||||
return (GM_openInTab || window.open)(location.protocol + url, '_blank');
|
return (GM_openInTab || window.open)(location.protocol + url, '_blank');
|
||||||
},
|
|
||||||
isDST: function() {
|
|
||||||
/*
|
|
||||||
http://en.wikipedia.org/wiki/Eastern_Time_Zone
|
|
||||||
Its UTC time offset is −5 hrs (UTC−05) during standard time and −4
|
|
||||||
hrs (UTC−04) during daylight saving time.
|
|
||||||
|
|
||||||
Since 2007, the local time changes at 02:00 EST to 03:00 EDT on the second
|
|
||||||
Sunday in March and returns at 02:00 EDT to 01:00 EST on the first Sunday
|
|
||||||
in November, in the U.S. as well as in Canada.
|
|
||||||
|
|
||||||
0200 EST (UTC-05) = 0700 UTC
|
|
||||||
0200 EDT (UTC-04) = 0600 UTC
|
|
||||||
*/
|
|
||||||
|
|
||||||
var D, date, day, hours, month, sunday;
|
|
||||||
D = new Date();
|
|
||||||
date = D.getUTCDate();
|
|
||||||
day = D.getUTCDay();
|
|
||||||
hours = D.getUTCHours();
|
|
||||||
month = D.getUTCMonth();
|
|
||||||
if (month < 2 || 10 < month) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ((2 < month && month < 10)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
sunday = date - day;
|
|
||||||
if (month === 2) {
|
|
||||||
if (sunday < 8) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (sunday < 15 && day === 0) {
|
|
||||||
if (hours < 7) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (sunday < 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (sunday < 8 && day === 0) {
|
|
||||||
if (hours < 6) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2799,22 +2749,7 @@
|
|||||||
|
|
||||||
Time = {
|
Time = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var chanOffset;
|
|
||||||
Time.foo();
|
Time.foo();
|
||||||
chanOffset = 5 - new Date().getTimezoneOffset() / 60;
|
|
||||||
if ($.isDST()) {
|
|
||||||
chanOffset--;
|
|
||||||
}
|
|
||||||
this.parse = Date.parse('10/11/11(Tue)18:53') === 1318351980000 ? function(text) {
|
|
||||||
return new Date(Date.parse(text) + chanOffset * $.HOUR);
|
|
||||||
} : function(text) {
|
|
||||||
var day, hour, min, month, year, _, _ref;
|
|
||||||
_ref = text.match(/(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/), _ = _ref[0], month = _ref[1], day = _ref[2], year = _ref[3], hour = _ref[4], min = _ref[5];
|
|
||||||
year = "20" + year;
|
|
||||||
month--;
|
|
||||||
hour = chanOffset + Number(hour);
|
|
||||||
return new Date(year, month, day, hour, min);
|
|
||||||
};
|
|
||||||
return Main.callbacks.push(this.node);
|
return Main.callbacks.push(this.node);
|
||||||
},
|
},
|
||||||
node: function(post) {
|
node: function(post) {
|
||||||
@ -2823,7 +2758,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node = $('.postInfo > .dateTime', post.el);
|
node = $('.postInfo > .dateTime', post.el);
|
||||||
Time.date = Time.parse(node.textContent);
|
Time.date = new Date(node.dataset.utc * 1000);
|
||||||
return node.textContent = Time.funk(Time);
|
return node.textContent = Time.funk(Time);
|
||||||
},
|
},
|
||||||
foo: function() {
|
foo: function() {
|
||||||
|
|||||||
@ -344,63 +344,6 @@ $.extend $,
|
|||||||
return
|
return
|
||||||
open: (url) ->
|
open: (url) ->
|
||||||
(GM_openInTab or window.open) location.protocol + url, '_blank'
|
(GM_openInTab or window.open) location.protocol + url, '_blank'
|
||||||
isDST: ->
|
|
||||||
###
|
|
||||||
http://en.wikipedia.org/wiki/Eastern_Time_Zone
|
|
||||||
Its UTC time offset is −5 hrs (UTC−05) during standard time and −4
|
|
||||||
hrs (UTC−04) during daylight saving time.
|
|
||||||
|
|
||||||
Since 2007, the local time changes at 02:00 EST to 03:00 EDT on the second
|
|
||||||
Sunday in March and returns at 02:00 EDT to 01:00 EST on the first Sunday
|
|
||||||
in November, in the U.S. as well as in Canada.
|
|
||||||
|
|
||||||
0200 EST (UTC-05) = 0700 UTC
|
|
||||||
0200 EDT (UTC-04) = 0600 UTC
|
|
||||||
###
|
|
||||||
|
|
||||||
D = new Date()
|
|
||||||
date = D.getUTCDate()
|
|
||||||
day = D.getUTCDay()
|
|
||||||
hours = D.getUTCHours()
|
|
||||||
month = D.getUTCMonth()
|
|
||||||
|
|
||||||
#this is the easy part
|
|
||||||
if month < 2 or 10 < month
|
|
||||||
return false
|
|
||||||
if 2 < month < 10
|
|
||||||
return true
|
|
||||||
|
|
||||||
# (sunday's date) = (today's date) - (number of days past sunday)
|
|
||||||
# date is not zero-indexed
|
|
||||||
sunday = date - day
|
|
||||||
|
|
||||||
if month is 2
|
|
||||||
#before second sunday
|
|
||||||
if sunday < 8
|
|
||||||
return false
|
|
||||||
|
|
||||||
#during second sunday
|
|
||||||
if sunday < 15 and day is 0
|
|
||||||
if hours < 7
|
|
||||||
return false
|
|
||||||
return true
|
|
||||||
|
|
||||||
#after second sunday
|
|
||||||
return true
|
|
||||||
|
|
||||||
#month is 10
|
|
||||||
# before first sunday
|
|
||||||
if sunday < 1
|
|
||||||
return true
|
|
||||||
|
|
||||||
# during first sunday
|
|
||||||
if sunday < 8 and day is 0
|
|
||||||
if hours < 6
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
#after first sunday
|
|
||||||
return false
|
|
||||||
|
|
||||||
$.cache.requests = {}
|
$.cache.requests = {}
|
||||||
|
|
||||||
@ -2202,30 +2145,12 @@ RevealSpoilers =
|
|||||||
Time =
|
Time =
|
||||||
init: ->
|
init: ->
|
||||||
Time.foo()
|
Time.foo()
|
||||||
|
|
||||||
# GMT -8 is given as +480; would GMT +8 be -480 ?
|
|
||||||
chanOffset = 5 - new Date().getTimezoneOffset() / 60
|
|
||||||
# 4chan = EST = GMT -5
|
|
||||||
chanOffset-- if $.isDST()
|
|
||||||
|
|
||||||
@parse =
|
|
||||||
if Date.parse('10/11/11(Tue)18:53') is 1318351980000
|
|
||||||
(text) -> new Date Date.parse(text) + chanOffset*$.HOUR
|
|
||||||
else # Firefox and Opera do not parse 4chan's time format correctly
|
|
||||||
(text) ->
|
|
||||||
[_, month, day, year, hour, min] =
|
|
||||||
text.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/
|
|
||||||
year = "20#{year}"
|
|
||||||
month-- # Months start at 0
|
|
||||||
hour = chanOffset + Number hour
|
|
||||||
new Date year, month, day, hour, min
|
|
||||||
|
|
||||||
Main.callbacks.push @node
|
Main.callbacks.push @node
|
||||||
node: (post) ->
|
node: (post) ->
|
||||||
return if post.isInlined and not post.isCrosspost
|
return if post.isInlined and not post.isCrosspost
|
||||||
node = $ '.postInfo > .dateTime', post.el
|
node = $ '.postInfo > .dateTime', post.el
|
||||||
Time.date = Time.parse node.textContent
|
Time.date = new Date node.dataset.utc * 1000
|
||||||
node.textContent = Time.funk(Time)
|
node.textContent = Time.funk Time
|
||||||
foo: ->
|
foo: ->
|
||||||
code = Conf['time'].replace /%([A-Za-z])/g, (s, c) ->
|
code = Conf['time'].replace /%([A-Za-z])/g, (s, c) ->
|
||||||
if c of Time.formatters
|
if c of Time.formatters
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user