From: Tim Wood Date: Thu, 15 Sep 2011 05:45:42 +0000 (-0700) Subject: Finishing _date.lang addition X-Git-Tag: 0.6.0~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8942f034a7ad2991439bd9e2f2ab36c64267e61e;p=thirdparty%2Fmoment.git Finishing _date.lang addition --- diff --git a/test.js b/test.js index 4fc8ed594..f67d0c1f8 100755 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ var testrunner = require('qunit'); -testrunner.options.coverage = false; +testrunner.options.errorsOnly = true; testrunner.run({ code: "./underscore.date.js", diff --git a/test/date.js b/test/date.js index 66fd249cf..1b954e9e0 100755 --- a/test/date.js +++ b/test/date.js @@ -436,4 +436,60 @@ test("format", 48, function() { // switch back to en to prevent other tests from failing _date.lang('en'); +}); + +function nodeLangSetup() { + var testLang = require('../underscore.date.lang/test.js'); + _date.lang(testLang.key, testLang.data); + _date.lang('en'); +} + +if (typeof window === 'undefined') { + nodeLangSetup(); +} + +test("loaded module", 16, function() { + var date = _date(new Date(2010, 1, 14, 15, 25, 50, 125)), + test = [ + ['dddd, MMMM Do YYYY, h:mm:ss a', 'a.test, 2.test 14ordinal 2010, 3:25:50 pm'], + ['ddd, hA', 'a.t, 3PM'], + ['M Mo MM MMMM MMM', '2 2ordinal 02 2.test 2.t'], + ['D Do DD', '14 14ordinal 14'], + ['d do dddd ddd', '0 0ordinal a.test a.t'], + ['DDD DDDo DDDD', '45 45ordinal 045'], + ['w wo ww', '8 8ordinal 08'], + ['t\\he DDDo \\d\\ay of t\\he ye\\ar', 'the 45ordinal day of the year'] + ], + testFrom = [ + [{s:-30}, false, "s future", "future"], + [{s:30}, false, "s past", "past"], + [{s:30}, true, "s", "seconds"], + [{s:60}, true, "m", "minute"], + [{m:5}, true, "5 mm", "minutes"], + [{h:1}, true, "h", "hour"], + [{h:5}, true, "5 hh", "hours"], + [{d:1}, true, "d", "day"], + [{d:5}, true, "5 dd", "days"], + [{M:1}, true, "M", "month"], + [{M:5}, true, "5 MM", "months"], + [{y:1}, true, "y", "year"], + [{y:5}, true, "5 yy", "years"] + ], + i; + + function testLang(formatArray, fromArray) { + var start = [2007, 1, 28]; + for (i = 0; i < formatArray.length; i++) { + equal(date.format(formatArray[i][0]), formatArray[i][1], formatArray[i][0] + ' ---> ' + formatArray[i][1]); + } + + for (i = 0; i < formatArray.length; i++) { + equal(_date(start).from(_date(start).add(fromArray[i][0]), fromArray[i][1]), fromArray[i][2], fromArray[i][3]); + } + } + + _date.lang('test'); + + // test 'test' + testLang(test, testFrom); }); \ No newline at end of file diff --git a/test/test.html b/test/test.html index d573214b6..b21bc2f20 100755 --- a/test/test.html +++ b/test/test.html @@ -7,6 +7,11 @@ + + diff --git a/underscore.date.js b/underscore.date.js index 71823aff8..ae639a645 100644 --- a/underscore.date.js +++ b/underscore.date.js @@ -3,7 +3,7 @@ // (c) 2011 Tim Wood // Underscore.date is freely distributable under the terms of the MIT license. // -// Version 0.5.2 +// Version 0.6.0 (function (undefined) { @@ -322,7 +322,7 @@ _date[param] = languages[key][param] || _date[param]; } } - } + }; // set default language _date.lang('en', { diff --git a/underscore.date.lang/pt.js b/underscore.date.lang/pt.js new file mode 100644 index 000000000..7d2525743 --- /dev/null +++ b/underscore.date.lang/pt.js @@ -0,0 +1,36 @@ +(function () { + var lang = { + months : ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"], + monthsShort : ["Jan", "Feb", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"], + weekdays : ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"], + weekdaysShort : ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], + relativeTime : { + future: "em %s", + past: "%s atrás", + s: "segundos", + m: "um minuto", + mm: "%d minutos", + h: "uma hora", + hh: "%d horas", + d: "um dia", + dd: "%d dias", + M: "um mês", + MM: "%d meses", + y: "um ano", + yy: "%d anos" + }, + ordinal : function (number) { + return 'º'; + }, + }, + abbr = 'pt'; + + // Node + if (typeof module !== 'undefined') { + module.exports = {lang : lang, abbr : abbr}; + } + // Browser + if (typeof window !== 'undefined' && this._date && this._date.lang) { + this._date.lang(abbr, lang); + } +}()); \ No newline at end of file diff --git a/underscore.date.lang/test.js b/underscore.date.lang/test.js new file mode 100644 index 000000000..9f23f81d2 --- /dev/null +++ b/underscore.date.lang/test.js @@ -0,0 +1,36 @@ +(function () { + var data = { + months : ["1.test", "2.test", "3.test", "4.test", "5.test", "6.test", "7.test", "8.test", "9.test", "10.test", "11.test", "12.test"], + monthsShort : ["1.t", "2.t", "3.t", "4.t", "5.t", "6.t", "7.t", "8.t", "9.t", "10.t", "11.t", "12.t"], + weekdays : ["a.test", "b.test", "c.test", "d.test", "e.test", "f.test", "g.test"], + weekdaysShort : ["a.t", "b.t", "c.t", "d.t", "e.t", "f.t", "g.t"], + relativeTime : { + future: "%s future", + past: "%s past", + s: "s", + m: "m", + mm: "%d mm", + h: "h", + hh: "%d hh", + d: "d", + dd: "%d dd", + M: "M", + MM: "%d MM", + y: "y", + yy: "%d yy" + }, + ordinal : function (number) { + return 'ordinal'; + }, + }, + key = 'test'; + + // Node + if (typeof module !== 'undefined') { + module.exports = {data : data, key : key}; + } + // Browser + if (typeof window !== 'undefined' && this._date && this._date.lang) { + this._date.lang(key, data); + } +}()); \ No newline at end of file diff --git a/underscore.date.languages.js b/underscore.date.languages.js deleted file mode 100644 index f07b57d90..000000000 --- a/underscore.date.languages.js +++ /dev/null @@ -1,24 +0,0 @@ -exports.portuguese = function (){ - _date.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; - _date.monthsShort = ["Jan", "Feb", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]; - _date.weekdays = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - _date.weekdaysShort = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"]; - _date.relativeTime = { - future: "em %s", - past: "%s atrás", - s: "segundos", - m: "um minuto", - mm: "%d minutos", - h: "uma hora", - hh: "%d horas", - d: "um dia", - dd: "%d dias", - M: "um mês", - MM: "%d meses", - y: "um ano", - yy: "%d anos" - }; - _date.ordinal = function (number) { - return 'º'; - }; -} \ No newline at end of file diff --git a/underscore.date.min.js b/underscore.date.min.js index b9dc34c8a..9a2879472 100755 --- a/underscore.date.min.js +++ b/underscore.date.min.js @@ -1 +1,8 @@ -(function(a){function p(a){var b=Math.abs(a)/1e3,d=b/60,e=d/60,f=e/24,g=f/365;return b<45&&n("s",c(b))||c(d)===1&&n("m")||d<45&&n("mm",c(d))||c(e)===1&&n("h")||e<22&&n("hh",c(e))||c(f)===1&&n("d")||f<25&&n("dd",c(f))||f<45&&n("M")||f<345&&n("MM",c(f/30))||c(g)===1&&n("y")||n("yy",c(g))}function o(a,b){return m(a)-m(b)}function n(a,c){return b.relativeTime[a].replace(/%d/i,c||1)}function m(a){return isNaN(a)?(new l(a)).date.getTime():a}function l(b,c){b&&b.date instanceof Date?this.date=b.date:c?f(c)?this.date=k(b,c):this.date=i(b,c):this.date=b===a?new Date:b instanceof Date?b:f(b)?g(b):new Date(b)}function k(a,b){var c,d=/[0-9a-zA-Z]+/g,e=a.match(d),f=[],g=99,k,l,m;for(k=0;k70?1900:2e3);break;case"YYYY":c[0]=~~b;break;case"a":case"A":i=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b}}var c=[0],d=/[0-9a-zA-Z]+/g,e=a.match(d),f=b.match(d),h,i;for(h=0;h11?"pm":"am";case"A":return i>11?"PM":"AM";case"H":return i;case"HH":return d(i,2);case"h":return i%12||12;case"hh":return d(i%12||12,2);case"m":return j;case"mm":return d(j,2);case"s":return k;case"ss":return d(k,2);case"z":return o("zz").replace(n,"");case"zz":c=l.indexOf("(");if(c>-1)return l.slice(c+1,l.indexOf(")"));return l.slice(l.indexOf(":")).replace(n,"");default:return a.replace("\\","")}}var e=a.getMonth(),f=a.getDate(),g=a.getFullYear(),h=a.getDay(),i=a.getHours(),j=a.getMinutes(),k=a.getSeconds(),l=a.toString(),m=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?)/g,n=/[^A-Z]/g;return c.replace(m,o)}function g(a){return new Date(a[0],a[1]||0,a[2]||1,a[3]||0,a[4]||0,a[5]||0,a[6]||0)}function f(a){return Object.prototype.toString.call(a)==="[object Array]"}function e(a,b,c){var d=(b.ms||0)+(b.s||0)*1e3+(b.m||0)*6e4+(b.h||0)*36e5+(b.d||0)*864e5+(b.w||0)*6048e5,e=(b.M||0)+(b.y||0)*12,f;d&&a.setMilliseconds(a.getMilliseconds()+d*c),e&&(f=a.getDate(),a.setDate(1),a.setMonth(a.getMonth()+e*c),a.setDate(Math.min((new Date(a.getFullYear(),a.getMonth()+1,0)).getDate(),f)));return a}function d(a,b){var c=a+"";while(c.length11?"pm":"am";case"A":return i>11?"PM":"AM";case"H":return i;case"HH":return f(i,2);case"h":return i%12||12;case"hh":return f(i%12||12,2);case"m":return j;case"mm":return f(j,2);case"s":return k;case"ss":return f(k,2);case"zz":case"z":c=l.indexOf("(");if(c>-1)return l.slice(c+1,l.indexOf(")")).replace(n,"");return l.slice(l.indexOf(":")).replace(n,"");default:return a.replace("\\","")}}var d=a.getMonth(),e=a.getDate(),g=a.getFullYear(),h=a.getDay(),i=a.getHours(),j=a.getMinutes(),k=a.getSeconds(),l=a.toString(),m=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?)/g,n=/[^A-Z]/g;return c.replace(m,o)}function k(a,b){function j(a,b){switch(a){case"M":case"MM":c[1]=~~b-1;break;case"D":case"DD":case"DDD":case"DDDD":c[2]=~~b;break;case"YY":b=~~b,c[0]=b+(b>70?1900:2e3);break;case"YYYY":c[0]=~~b;break;case"a":case"A":h=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b}}var c=[0],d=/[0-9a-zA-Z]+/g,e=a.match(d),f=b.match(d),g,h;for(g=0;g