From 171d0f19744bd877fbcd07cd0543c55869ad1dec Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 20 May 2011 20:40:39 +0200 Subject: [PATCH 1/2] AM/PM localized time. Close #5 --- 4chan_x.js | 10 ++++++++-- script.coffee | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index d0d201249..460957cdf 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -104,6 +104,7 @@ 'Anonymize': [false, 'Make everybody anonymous'], 'Keybinds': [false, 'Binds actions to keys'], 'Localize Time': [true, 'Show times based on your timezone'], + 'Localized am/pm': [false, 'Change localized time to the 12-hour clock convention'], 'Report Button': [true, 'Add report buttons'], 'Comment Expansion': [true, 'Expand too long comments'], 'Thread Expansion': [true, 'View all replies'], @@ -1640,7 +1641,7 @@ localize = { init: function() { return g.callbacks.push(function(root) { - var date, day, dotw, hour, min_sec, month, s, span, year, _, _i, _len, _ref, _ref2, _results; + var date, day, dotw, hour, meridiem, min_sec, month, s, span, year, _, _i, _len, _ref, _ref2, _results; _ref = $$('span[id^=no]', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1650,13 +1651,18 @@ year = "20" + year; month -= 1; hour = g.chanOffset + Number(hour); + meridiem = ''; + if ($.config('Localized am/pm')) { + meridiem = hour < 12 ? ' a.m.' : ' p.m.'; + hour = hour === 0 ? 12 : hour > 12 ? hour - 12 : void 0; + } date = new Date(year, month, day, hour); year = date.getFullYear() - 2000; month = $.zeroPad(date.getMonth() + 1); day = $.zeroPad(date.getDate()); hour = $.zeroPad(date.getHours()); dotw = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; - _results.push(s.textContent = " " + month + "/" + day + "/" + year + "(" + dotw + ")" + hour + ":" + min_sec + " "); + _results.push(s.textContent = " " + month + "/" + day + "/" + year + "(" + dotw + ")" + hour + ":" + min_sec + meridiem + " "); } return _results; }); diff --git a/script.coffee b/script.coffee index 19c4fae5a..f85b9a4de 100644 --- a/script.coffee +++ b/script.coffee @@ -42,6 +42,7 @@ config = 'Anonymize': [false, 'Make everybody anonymous'] 'Keybinds': [false, 'Binds actions to keys'] 'Localize Time': [true, 'Show times based on your timezone'] + 'Localized am/pm': [false, 'Change localized time to the 12-hour clock convention'] 'Report Button': [true, 'Add report buttons'] 'Comment Expansion': [true, 'Expand too long comments'] 'Thread Expansion': [true, 'View all replies'] @@ -1329,6 +1330,10 @@ localize = year = "20#{year}" month -= 1 #months start at 0 hour = g.chanOffset + Number hour + meridiem = '' + if $.config 'Localized am/pm' + meridiem = if hour < 12 then ' a.m.' else ' p.m.' + hour = if hour is 0 then 12 else if hour > 12 then hour - 12 date = new Date year, month, day, hour year = date.getFullYear() - 2000 month = $.zeroPad date.getMonth() + 1 @@ -1343,7 +1348,7 @@ localize = 'Fri' 'Sat' ][date.getDay()] - s.textContent = " #{month}/#{day}/#{year}(#{dotw})#{hour}:#{min_sec} " + s.textContent = " #{month}/#{day}/#{year}(#{dotw})#{hour}:#{min_sec}#{meridiem} " titlePost = init: -> From d4a8a8dcf91d6518e54702578ea35efb3c29c5fd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 20 May 2011 21:33:18 +0200 Subject: [PATCH 2/2] Tell me your secrets. --- 4chan_x.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 460957cdf..2ca70e92c 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1654,7 +1654,7 @@ meridiem = ''; if ($.config('Localized am/pm')) { meridiem = hour < 12 ? ' a.m.' : ' p.m.'; - hour = hour === 0 ? 12 : hour > 12 ? hour - 12 : void 0; + hour = hour % 12 || 12; } date = new Date(year, month, day, hour); year = date.getFullYear() - 2000; diff --git a/script.coffee b/script.coffee index f85b9a4de..02d218ec7 100644 --- a/script.coffee +++ b/script.coffee @@ -1333,7 +1333,7 @@ localize = meridiem = '' if $.config 'Localized am/pm' meridiem = if hour < 12 then ' a.m.' else ' p.m.' - hour = if hour is 0 then 12 else if hour > 12 then hour - 12 + hour = hour % 12 or 12 date = new Date year, month, day, hour year = date.getFullYear() - 2000 month = $.zeroPad date.getMonth() + 1