From 4cdfa487195300b55ca46c5511212f569aeb5341 Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Tue, 15 Apr 2014 17:56:34 +0200 Subject: [PATCH] Adding date.format to make date strings customisable to fit your locale --- client/src/helpers/utils.js | 115 ++++++++++++++++++++++- client/src/translations/en-gb.po | 155 +++++++++++++++++++++++++++++++ client/src/translations/fr.po | 155 +++++++++++++++++++++++++++++++ 3 files changed, 424 insertions(+), 1 deletion(-) diff --git a/client/src/helpers/utils.js b/client/src/helpers/utils.js index 8931c87..d0da27a 100644 --- a/client/src/helpers/utils.js +++ b/client/src/helpers/utils.js @@ -379,8 +379,121 @@ function formatIRCMsg (msg) { function formatDate (d) { + /* + date.format.js + A JavaScript date format library that uses the same method as PHP's date() function. + + https://github.com/jacwright/date.format + */ + Date.shortMonths = [_kiwi.global.i18n.translate('client.libs.date_format.short_months.january').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.february').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.march').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.april').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.may').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.june').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.july').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.august').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.september').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.october').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.november').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_months.december').fetch()]; + Date.longMonths = [_kiwi.global.i18n.translate('client.libs.date_format.long_months.january').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.february').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.march').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.april').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.may').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.june').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.july').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.august').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.september').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.october').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.november').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_months.december').fetch()]; + Date.shortDays = [_kiwi.global.i18n.translate('client.libs.date_format.short_days.monday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.tuesday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.wednesday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.thursday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.friday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.saturday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.short_days.sunday').fetch()]; + Date.longDays = [_kiwi.global.i18n.translate('client.libs.date_format.long_days.monday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.tuesday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.wednesday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.thursday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.friday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.saturday').fetch(), + _kiwi.global.i18n.translate('client.libs.date_format.long_days.sunday').fetch()]; + + // defining patterns + var replaceChars = { + // Day + d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); }, + D: function() { return Date.shortDays[this.getDay()]; }, + j: function() { return this.getDate(); }, + l: function() { return Date.longDays[this.getDay()]; }, + N: function() { return this.getDay() + 1; }, + S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); }, + w: function() { return this.getDay(); }, + z: function() { var d = new Date(this.getFullYear(),0,1); return Math.ceil((this - d) / 86400000); }, // Fixed now + // Week + W: function() { var d = new Date(this.getFullYear(), 0, 1); return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7); }, // Fixed now + // Month + F: function() { return Date.longMonths[this.getMonth()]; }, + m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); }, + M: function() { return Date.shortMonths[this.getMonth()]; }, + n: function() { return this.getMonth() + 1; }, + t: function() { var d = new Date(); return new Date(d.getFullYear(), d.getMonth(), 0).getDate() }, // Fixed now, gets #days of date + // Year + L: function() { var year = this.getFullYear(); return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)); }, // Fixed now + o: function() { var d = new Date(this.valueOf()); d.setDate(d.getDate() - ((this.getDay() + 6) % 7) + 3); return d.getFullYear();}, //Fixed now + Y: function() { return this.getFullYear(); }, + y: function() { return ('' + this.getFullYear()).substr(2); }, + // Time + a: function() { return this.getHours() < 12 ? 'am' : 'pm'; }, + A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; }, + B: function() { return Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24); }, // Fixed now + g: function() { return this.getHours() % 12 || 12; }, + G: function() { return this.getHours(); }, + h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); }, + H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); }, + i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); }, + s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); }, + u: function() { var m = this.getMilliseconds(); return (m < 10 ? '00' : (m < 100 ? + '0' : '')) + m; }, + // Timezone + e: function() { return "Not Yet Supported"; }, + I: function() { + var DST = null; + for (var i = 0; i < 12; ++i) { + var d = new Date(this.getFullYear(), i, 1); + var offset = d.getTimezoneOffset(); + + if (DST === null) DST = offset; + else if (offset < DST) { DST = offset; break; } else if (offset > DST) break; + } + return (this.getTimezoneOffset() == DST) | 0; + }, + O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; }, + P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':00'; }, // Fixed now + T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;}, + Z: function() { return -this.getTimezoneOffset() * 60; }, + // Full Date/Time + c: function() { return this.format("Y-m-d\\TH:i:sP"); }, // Fixed now + r: function() { return this.toString(); }, + U: function() { return this.getTime() / 1000; } + }; + + // Simulates PHP's date function + Date.prototype.format = function(format) { + var date = this; + return format.replace(/(\\?)(.)/g, function(_, esc, chr) { + return (esc === '' && replaceChars[chr]) ? replaceChars[chr].call(date) : chr; + }); + }; + /* End of date.format */ + d = d || new Date(); - return d.toLocaleDateString() + ', ' + d.getHours().toString() + ':' + d.getMinutes().toString() + ':' + d.getSeconds().toString(); + return d.format(_kiwi.global.i18n.translate('client_date_format').fetch()); } function escapeRegex (str) { diff --git a/client/src/translations/en-gb.po b/client/src/translations/en-gb.po index d9590e5..e5ef11a 100755 --- a/client/src/translations/en-gb.po +++ b/client/src/translations/en-gb.po @@ -524,3 +524,158 @@ msgstr "%s AM" msgid "client_views_panel_timestamp_pm" msgstr "%s PM" +#: Date format +msgid "client_date_format" +msgstr "m/d/Y" + +#: client.libs.date_format.shortMonths.January +msgid "client.libs.date_format.short_months.january" +msgstr "Jan" + +#: client.libs.date_format.shortMonths.february +msgid "client.libs.date_format.short_months.february" +msgstr "Feb" + +#: client.libs.date_format.shortMonths.march +msgid "client.libs.date_format.short_months.march" +msgstr "Mar" + +#: client.libs.date_format.shortMonths.april +msgid "client.libs.date_format.short_months.april" +msgstr "Apr" + +#: client.libs.date_format.shortMonths.may +msgid "client.libs.date_format.short_months.may" +msgstr "May" + +#: client.libs.date_format.shortMonths.june +msgid "client.libs.date_format.short_months.june" +msgstr "Jun" + +#: client.libs.date_format.shortMonths.july +msgid "client.libs.date_format.short_months.july" +msgstr "Jul" + +#: client.libs.date_format.shortMonths.august +msgid "client.libs.date_format.short_months.august" +msgstr "Aug" + +#: client.libs.date_format.shortMonths.september +msgid "client.libs.date_format.short_months.september" +msgstr "Sep" + +#: client.libs.date_format.shortMonths.october +msgid "client.libs.date_format.short_months.october" +msgstr "Oct" + +#: client.libs.date_format.shortMonths.november +msgid "client.libs.date_format.short_months.november" +msgstr "Nov" + +#: client.libs.date_format.shortMonths.december +msgid "client.libs.date_format.short_months.december" +msgstr "Dec" + +#: client.libs.date_format.longMonts.January +msgid "client.libs.date_format.long_months.january" +msgstr "January" + +#: client.libs.date_format.longMonts.february +msgid "client.libs.date_format.long_months.february" +msgstr "February" + +#: client.libs.date_format.longMonts.march +msgid "client.libs.date_format.long_months.march" +msgstr "March" + +#: client.libs.date_format.longMonts.april +msgid "client.libs.date_format.long_months.april" +msgstr "April" + +#: client.libs.date_format.longMonts.may +msgid "client.libs.date_format.long_months.may" +msgstr "May" + +#: client.libs.date_format.longMonts.june +msgid "client.libs.date_format.long_months.june" +msgstr "June" + +#: client.libs.date_format.longMonts.july +msgid "client.libs.date_format.long_months.july" +msgstr "July" + +#: client.libs.date_format.longMonts.august +msgid "client.libs.date_format.long_months.august" +msgstr "August" + +#: client.libs.date_format.longMonts.september +msgid "client.libs.date_format.long_months.september" +msgstr "September" + +#: client.libs.date_format.longMonths.october +msgid "client.libs.date_format.long_months.october" +msgstr "October" + +#: client.libs.date_format.longMonths.november +msgid "client.libs.date_format.long_months.november" +msgstr "November" + +#: client.libs.date_format.longMonths.december +msgid "client.libs.date_format.long_months.december" +msgstr "December" + +#: client.libs.date_format.shortDays.monday +msgid "client.libs.date_format.short_days.monday" +msgstr "Mon" + +#: client.libs.date_format.shortDays.tuesday +msgid "client.libs.date_format.short_days.tuesday" +msgstr "Tue" + +#: client.libs.date_format.shortDays.wednesday +msgid "client.libs.date_format.short_days.wednesday" +msgstr "Wed" + +#: client.libs.date_format.shortDays.thursday +msgid "client.libs.date_format.short_days.thursday" +msgstr "Thu" + +#: client.libs.date_format.shortDays.friday +msgid "client.libs.date_format.short_days.friday" +msgstr "Fri" + +#: client.libs.date_format.shortDays.saturday +msgid "client.libs.date_format.short_days.saturday" +msgstr "Sat" + +#: client.libs.date_format.shortDays.sunday +msgid "client.libs.date_format.short_days.sunday" +msgstr "Sun" + +#: client.libs.date_format.longDays.monday +msgid "client.libs.date_format.long_days.monday" +msgstr "Monday" + +#: client.libs.date_format.longDays.tuesday +msgid "client.libs.date_format.long_days.tuesday" +msgstr "Tueday" + +#: client.libs.date_format.longDays.wednesday +msgid "client.libs.date_format.long_days.wednesday" +msgstr "Wednesday" + +#: client.libs.date_format.longDays.thursday +msgid "client.libs.date_format.long_days.thursday" +msgstr "Thursday" + +#: client.libs.date_format.longDays.friday +msgid "client.libs.date_format.long_days.friday" +msgstr "Friday" + +#: client.libs.date_format.longDays.saturday +msgid "client.libs.date_format.long_days.saturday" +msgstr "Saturday" + +#: client.libs.date_format.longDays.sunday +msgid "client.libs.date_format.long_days.sunday" +msgstr "Sunday" diff --git a/client/src/translations/fr.po b/client/src/translations/fr.po index 50322ed..387e007 100644 --- a/client/src/translations/fr.po +++ b/client/src/translations/fr.po @@ -524,3 +524,158 @@ msgstr "%s AM" msgid "client_views_panel_timestamp_pm" msgstr "%s PM" +#: Date format +msgid "client_date_format" +msgstr "d/m/Y" + +#: client.libs.date_format.shortMonths.January +msgid "client.libs.date_format.short_months.january" +msgstr "Jan" + +#: client.libs.date_format.shortMonths.february +msgid "client.libs.date_format.short_months.february" +msgstr "Fev" + +#: client.libs.date_format.shortMonths.march +msgid "client.libs.date_format.short_months.march" +msgstr "Mar" + +#: client.libs.date_format.shortMonths.april +msgid "client.libs.date_format.short_months.april" +msgstr "Avr" + +#: client.libs.date_format.shortMonths.may +msgid "client.libs.date_format.short_months.may" +msgstr "Mai" + +#: client.libs.date_format.shortMonths.june +msgid "client.libs.date_format.short_months.june" +msgstr "Juin" + +#: client.libs.date_format.shortMonths.july +msgid "client.libs.date_format.short_months.july" +msgstr "Juil" + +#: client.libs.date_format.shortMonths.august +msgid "client.libs.date_format.short_months.august" +msgstr "Août" + +#: client.libs.date_format.shortMonths.september +msgid "client.libs.date_format.short_months.september" +msgstr "Sept" + +#: client.libs.date_format.shortMonths.october +msgid "client.libs.date_format.short_months.october" +msgstr "Oct" + +#: client.libs.date_format.shortMonths.november +msgid "client.libs.date_format.short_months.november" +msgstr "Nov" + +#: client.libs.date_format.shortMonths.december +msgid "client.libs.date_format.short_months.december" +msgstr "Dec" + +#: client.libs.date_format.longMonts.January +msgid "client.libs.date_format.long_months.january" +msgstr "Janvier" + +#: client.libs.date_format.longMonts.february +msgid "client.libs.date_format.long_months.february" +msgstr "Février" + +#: client.libs.date_format.longMonts.march +msgid "client.libs.date_format.long_months.march" +msgstr "Mars" + +#: client.libs.date_format.longMonts.april +msgid "client.libs.date_format.long_months.april" +msgstr "Avril" + +#: client.libs.date_format.longMonts.may +msgid "client.libs.date_format.long_months.may" +msgstr "Mai" + +#: client.libs.date_format.longMonts.june +msgid "client.libs.date_format.long_months.june" +msgstr "Juin" + +#: client.libs.date_format.longMonts.july +msgid "client.libs.date_format.long_months.july" +msgstr "Juillet" + +#: client.libs.date_format.longMonts.august +msgid "client.libs.date_format.long_months.august" +msgstr "Août" + +#: client.libs.date_format.longMonts.september +msgid "client.libs.date_format.long_months.september" +msgstr "Septembre" + +#: client.libs.date_format.longMonths.october +msgid "client.libs.date_format.long_months.october" +msgstr "Octobre" + +#: client.libs.date_format.longMonths.november +msgid "client.libs.date_format.long_months.november" +msgstr "Novembre" + +#: client.libs.date_format.longMonths.december +msgid "client.libs.date_format.long_months.december" +msgstr "Décembre" + +#: client.libs.date_format.shortDays.monday +msgid "client.libs.date_format.short_days.monday" +msgstr "Lu" + +#: client.libs.date_format.shortDays.tuesday +msgid "client.libs.date_format.short_days.tuesday" +msgstr "Ma" + +#: client.libs.date_format.shortDays.wednesday +msgid "client.libs.date_format.short_days.wednesday" +msgstr "Me" + +#: client.libs.date_format.shortDays.thursday +msgid "client.libs.date_format.short_days.thursday" +msgstr "Je" + +#: client.libs.date_format.shortDays.friday +msgid "client.libs.date_format.short_days.friday" +msgstr "Ve" + +#: client.libs.date_format.shortDays.saturday +msgid "client.libs.date_format.short_days.saturday" +msgstr "Sa" + +#: client.libs.date_format.shortDays.sunday +msgid "client.libs.date_format.short_days.sunday" +msgstr "Di" + +#: client.libs.date_format.longDays.monday +msgid "client.libs.date_format.long_days.monday" +msgstr "Lundi" + +#: client.libs.date_format.longDays.tuesday +msgid "client.libs.date_format.long_days.tuesday" +msgstr "Mardi" + +#: client.libs.date_format.longDays.wednesday +msgid "client.libs.date_format.long_days.wednesday" +msgstr "Mercredi" + +#: client.libs.date_format.longDays.thursday +msgid "client.libs.date_format.long_days.thursday" +msgstr "Jeudi" + +#: client.libs.date_format.longDays.friday +msgid "client.libs.date_format.long_days.friday" +msgstr "Vendredi" + +#: client.libs.date_format.longDays.saturday +msgid "client.libs.date_format.long_days.saturday" +msgstr "Samedi" + +#: client.libs.date_format.longDays.sunday +msgid "client.libs.date_format.long_days.sunday" +msgstr "Dimanche" \ No newline at end of file -- 2.25.1