From ef1ff8bc42f4ba1f5a8866547e289f1b7b146eb5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 9 Jan 2017 04:21:45 -0500 Subject: [PATCH] Fix #64, Non-English month parsing doesn't work in Standalone Month values from the Firefox language packs are included in a JSON file used by `Zotero.Date.getMonths()`. `getMonths(true)` includes English months as well. The JSON file should be bundled with the connectors as well, and Zotero.Date.init() should be updated to populate the month data from that. --- chrome/content/zotero/xpcom/date.js | 96 +- chrome/content/zotero/xpcom/zotero.js | 2 +- resource/schema/dateFormats.json | 1292 +++++++++++++++++++++++++ test/tests/dateTest.js | 118 +++ 4 files changed, 1477 insertions(+), 31 deletions(-) create mode 100644 resource/schema/dateFormats.json diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index 22fa710e87..a56e2e8df6 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -39,39 +39,75 @@ Zotero.Date = new function(){ this.getLocaleDateOrder = getLocaleDateOrder; var _localeDateOrder = null; - var _months = null; + var _months; + var _monthsWithEnglish; - /** - * Load dateFormat bundle into _dateFormatsBundle - */ - this.getMonths = function() { - if(_months) return _months; - - if(Zotero.isFx && !Zotero.isBookmarklet) { - var src = 'chrome://global/locale/dateFormat.properties'; - var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']. - getService(Components.interfaces.nsILocaleService); - var appLocale = localeService.getApplicationLocale(); - - var bundle = - Components.classes["@mozilla.org/intl/stringbundle;1"] - .getService(Components.interfaces.nsIStringBundleService).createBundle(src, appLocale); - - _months = {"short":[], "long":[]}; - for(var i=1; i<=12; i++) { - _months.short.push(bundle.GetStringFromName("month."+i+".Mmm")); - _months.long.push(bundle.GetStringFromName("month."+i+".name")); - } - } else { - // TODO localize for Chrome/Safari - _months = { - "short":["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec"], - "long":["January", "February", "March", "April", "May", "June", "July", - "August", "September", "October", "November", "December"]}; + this.init = Zotero.Promise.coroutine(function* () { + if (!Zotero.isFx || Zotero.isBookmarklet) { + throw new Error("Unimplemented"); } - return _months; + var json = (yield Zotero.HTTP.request( + 'GET', 'resource://zotero/schema/dateFormats.json', { responseType: 'json' } + )).response; + var locale = Zotero.locale; + var english = locale.startsWith('en'); + // If no exact match, try first two characters ('de') + if (!json[locale]) { + locale = locale.substr(0, 2); + } + // Try first two characters repeated ('de-DE') + if (!json[locale]) { + locale = locale + "-" + locale.toUpperCase(); + } + // Look for another locale with same first two characters + if (!json[locale]) { + let sameLang = Object.keys(json).filter(l => l.startsWith(locale.substr(0, 2))); + if (sameLang.length) { + locale = sameLang[0]; + } + } + // If all else fails, use English + if (!json[locale]) { + locale = 'en-US'; + english = true; + } + _months = json[locale]; + + // Add English versions if not already added + if (english) { + _monthsWithEnglish = _months; + } + else { + _monthsWithEnglish = {}; + for (let key in _months) { + _monthsWithEnglish[key] = _months[key].concat(json['en-US'][key]); + } + } + }); + + + /** + * @param {Boolean} [withEnglish = false] - Include English months + * @return {Object} - Object with 'short' and 'long' arrays + */ + this.getMonths = function (withEnglish) { + if (withEnglish) { + if (_monthsWithEnglish) return _monthsWithEnglish; + } + else { + if (_months) return _months; + } + + if (Zotero.isFx && !Zotero.isBookmarklet) { + throw new Error("Months not cached"); + } + + // TODO: Use JSON file for connectors + return _months = _monthsWithEnglish = { + short: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + long: ["January", "February", "March", "April", "May", "June", "July", "August", + "September", "October", "November", "December"]}; } /** diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index e7fce87de8..dea8b33a32 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -717,7 +717,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); // Initialize keyboard shortcuts Zotero.Keys.init(); - // Initialize Locate Manager + yield Zotero.Date.init(); Zotero.LocateManager.init(); yield Zotero.ID.init(); yield Zotero.Collections.init(); diff --git a/resource/schema/dateFormats.json b/resource/schema/dateFormats.json new file mode 100644 index 0000000000..d707f65d15 --- /dev/null +++ b/resource/schema/dateFormats.json @@ -0,0 +1,1292 @@ +{ + "en-US": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" + ], + "long": [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + ] + }, + "af-ZA": { + "short": [ + "Jan", + "Feb", + "Mrt", + "Apr", + "Mei", + "Jun", + "Jul", + "Aug", + "Sep", + "Okt", + "Nov", + "Des" + ], + "long": [ + "Januarie", + "Februarie", + "Maart", + "April", + "Mei", + "Junie", + "Julie", + "Augustus", + "September", + "Oktober", + "November", + "Desember" + ] + }, + "ar": { + "short": [ + "يناير", + "فبراير", + "مارس", + "أبريل", + "مايو", + "يونيو", + "يوليو", + "أغسطس", + "سبتمبر", + "أكتوبر", + "نوفمبر", + "ديسمبر" + ], + "long": [ + "يناير", + "فبراير", + "مارس", + "أبريل", + "مايو", + "يونيو", + "يوليو", + "أغسطس", + "سبتمبر", + "أكتوبر", + "نوفمبر", + "ديسمبر" + ] + }, + "bg-BG": { + "short": [ + "Яну", + "Фев", + "Мар", + "Апр", + "Май", + "Юни", + "Юли", + "Авг", + "Сеп", + "Окт", + "Ное", + "Дек" + ], + "long": [ + "Януари", + "Февруари", + "Март", + "Април", + "Май", + "Юни", + "Юли", + "Август", + "Септември", + "Октомври", + "Ноември", + "Декември" + ] + }, + "ca-AD": { + "short": [ + "gen", + "febr", + "març", + "abr", + "maig", + "juny", + "jul", + "ag", + "set", + "oct", + "nov", + "des" + ], + "long": [ + "gener", + "febrer", + "març", + "abril", + "maig", + "juny", + "juliol", + "agost", + "setembre", + "octubre", + "novembre", + "desembre" + ] + }, + "cs-CZ": { + "short": [ + "Led", + "Úno", + "Bře", + "Dub", + "Kvě", + "Čvn", + "Čnc", + "Srp", + "Zář", + "Říj", + "Lis", + "Pro" + ], + "long": [ + "leden", + "únor", + "březen", + "duben", + "květen", + "červen", + "červenec", + "srpen", + "září", + "říjen", + "listopad", + "prosinec" + ] + }, + "da-DK": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Maj", + "Jun", + "Jul", + "Aug", + "Sep", + "Okt", + "Nov", + "Dec" + ], + "long": [ + "Januar", + "Februar", + "Marts", + "April", + "Maj", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "December" + ] + }, + "de": { + "short": [ + "Jan", + "Feb", + "Mär", + "Apr", + "Mai", + "Jun", + "Jul", + "Aug", + "Sep", + "Okt", + "Nov", + "Dez" + ], + "long": [ + "Januar", + "Februar", + "März", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Dezember" + ] + }, + "el-GR": { + "short": [ + "Ιαν", + "Φεβ", + "Μαρ", + "Απρ", + "Ιουν", + "Ιουλ", + "Αυγ", + "Σεπ", + "Οκτ", + "Νοε", + "Δεκ", + "May" + ], + "long": [ + "January", + "October", + "November", + "December", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September" + ] + }, + "es-ES": { + "short": [ + "Ene", + "Feb", + "Mar", + "Abr", + "May", + "Jun", + "Jul", + "Ago", + "Sep", + "Oct", + "Nov", + "Dic" + ], + "long": [ + "Enero", + "Febrero", + "Marzo", + "Abril", + "Mayo", + "Junio", + "Julio", + "Agosto", + "Septiembre", + "Octubre", + "Noviembre", + "Diciembre" + ] + }, + "fr-FR": { + "short": [ + "jan", + "fév", + "mar", + "avr", + "mai", + "jun", + "jul", + "aoû", + "sep", + "oct", + "nov", + "dec" + ], + "long": [ + "janvier", + "février", + "mars", + "avril", + "mai", + "juin", + "juillet", + "août", + "septembre", + "octobre", + "novembre", + "décembre" + ] + }, + "et-EE": { + "short": [ + "jaan", + "veebr", + "märts", + "apr", + "mai", + "juun", + "juul", + "aug", + "sept", + "okt", + "nov", + "dets" + ], + "long": [ + "jaanuar", + "veebruar", + "märts", + "aprill", + "mai", + "juuni", + "juuli", + "august", + "september", + "oktoober", + "november", + "detsember" + ] + }, + "eu-ES": { + "short": [ + "urt", + "ots", + "mar", + "api", + "mai", + "eka", + "uzt", + "abu", + "ira", + "urr", + "aza", + "abe" + ], + "long": [ + "urtarrila", + "otsaila", + "martxoa", + "apirila", + "maiatza", + "ekaina", + "uztaila", + "abuztua", + "iraila", + "urria", + "azaroa", + "abendua" + ] + }, + "fa": { + "short": [ + "ژانویه", + "فوریه", + "مارس", + "آوریل", + "مه", + "ژوئن", + "ژوئیه", + "اوت", + "سپتامبر", + "اکتبر", + "نوامبر", + "دسامبر" + ], + "long": [ + "ژانویه", + "فوریه", + "مارس", + "آوریل", + "مه", + "ژوئن", + "ژوئیه", + "اوت", + "سپتامبر", + "اکتبر", + "نوامبر", + "دسامبر" + ] + }, + "fi-FI": { + "short": [ + "tammi", + "helmi", + "maalis", + "huhti", + "touko", + "kesä", + "heinä", + "elo", + "syys", + "loka", + "marras", + "joulu" + ], + "long": [ + "tammikuu", + "helmikuu", + "maaliskuu", + "huhtikuu", + "toukokuu", + "kesäkuu", + "heinäkuu", + "elokuu", + "syyskuu", + "lokakuu", + "marraskuu", + "joulukuu" + ] + }, + "he-IL": { + "short": [ + "ינ'", + "פב'", + "מרץ", + "אפ'", + "מאי", + "יוני", + "יולי", + "אוג'", + "ספט'", + "אוק'", + "נוב'", + "דצ'" + ], + "long": [ + "ינואר", + "פברואר", + "מרץ", + "אפריל", + "מאי", + "יוני", + "יולי", + "אוגוסט", + "ספטמבר", + "אוקטובר", + "נובמבר", + "דצמבר" + ] + }, + "hr-HR": { + "short": [ + "Sij", + "Vel", + "Ožu", + "Tra", + "Svi", + "Lip", + "Srp", + "Kol", + "Ruj", + "Lis", + "Stu", + "Pro" + ], + "long": [ + "Siječanj", + "Veljača", + "Ožujak", + "Travanj", + "Svibanj", + "Lipanj", + "Srpanj", + "Kolovoz", + "Rujan", + "Listopad", + "Studeni", + "Prosinac" + ] + }, + "hu-HU": { + "short": [ + "Jan.", + "Febr.", + "Márc.", + "Ápr.", + "Máj.", + "Jún.", + "Júl.", + "Aug.", + "Szept.", + "Okt.", + "Nov.", + "Dec." + ], + "long": [ + "Január", + "Február", + "Március", + "Április", + "Május", + "Június", + "Július", + "Augusztus", + "Szeptember", + "Október", + "November", + "December" + ] + }, + "id-ID": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Mei", + "Jun", + "Jul", + "Agu", + "Sep", + "Okt", + "Nov", + "Des" + ], + "long": [ + "Januari", + "Februari", + "Maret", + "April", + "Mei", + "Juni", + "Juli", + "Agustus", + "September", + "Oktober", + "November", + "Desember" + ] + }, + "is-IS": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Maí", + "Jún", + "Júl", + "Ágú", + "Sep", + "Okt", + "Nóv", + "Des" + ], + "long": [ + "Janúar", + "Febrúar", + "Mars", + "Apríl", + "Maí", + "Júní", + "Júlí", + "Ágúst", + "September", + "Október", + "Nóvember", + "Desember" + ] + }, + "it-IT": { + "short": [ + "Gen", + "Feb", + "Mar", + "Apr", + "Mag", + "Giu", + "Lug", + "Ago", + "Set", + "Ott", + "Nov", + "Dic" + ], + "long": [ + "Gennaio", + "Febbraio", + "Marzo", + "Aprile", + "Maggio", + "Giugno", + "Luglio", + "Agosto", + "Settembre", + "Ottobre", + "Novembre", + "Dicembre" + ] + }, + "ja-JP": { + "short": [ + "(1月)", + "(2月)", + "(3月)", + "(4月)", + "(5月)", + "(6月)", + "(7月)", + "(8月)", + "(9月)", + "(10月)", + "(11月)", + "(12月)" + ], + "long": [ + "1月", + "2月", + "3月", + "4月", + "5月", + "6月", + "7月", + "8月", + "9月", + "10月", + "11月", + "12月" + ] + }, + "km": { + "short": [ + "មករា", + "កុម្ភៈ", + "មីនា", + "មេសា", + "ឧសភា", + "មិថុនា", + "កក្កដា", + "សីហា", + "កញ្ញា", + "តុលា", + "វិច្ឆិកា", + "ធ្នូ" + ], + "long": [ + "មករា", + "កុម្ភៈ", + "មីនា", + "មេសា", + "ឧសភា", + "មិថុនា", + "កក្កដា", + "សីហា", + "កញ្ញា", + "តុលា", + "វិច្ឆិកា", + "ធ្នូ" + ] + }, + "ko-KR": { + "short": [ + "1월", + "2월", + "3월", + "4월", + "5월", + "6월", + "7월", + "8월", + "9월", + "10월", + "11월", + "12월" + ], + "long": [ + "1월", + "2월", + "3월", + "4월", + "5월", + "6월", + "7월", + "8월", + "9월", + "10월", + "11월", + "12월" + ] + }, + "lt-LT": { + "short": [ + "Sau", + "Vas", + "Kov", + "Bal", + "Geg", + "Bir", + "Lie", + "Rgp", + "Rgs", + "Spl", + "Lap", + "Grd" + ], + "long": [ + "sausio", + "vasario", + "kovo", + "balandžio", + "gegužės", + "birželio", + "liepos", + "rugpjūčio", + "rugsėjo", + "spalio", + "lapkričio", + "gruodžio" + ] + }, + "nb-NO": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Mai", + "Jun", + "Jul", + "Aug", + "Sep", + "Okt", + "Nov", + "Des" + ], + "long": [ + "Januar", + "Februar", + "Mars", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Desember" + ] + }, + "nn-NO": { + "short": [ + "jan", + "feb", + "mar", + "apr", + "mai", + "jun", + "jul", + "aug", + "sep", + "okt", + "nov", + "des" + ], + "long": [ + "Januar", + "Februar", + "Mars", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Desember" + ] + }, + "nl-NL": { + "short": [ + "jan", + "feb", + "mrt", + "apr", + "mei", + "jun", + "jul", + "aug", + "sep", + "okt", + "nov", + "dec" + ], + "long": [ + "januari", + "februari", + "maart", + "april", + "mei", + "juni", + "juli", + "augustus", + "september", + "oktober", + "november", + "december" + ] + }, + "pl-PL": { + "short": [ + "Sty", + "Lut", + "Mar", + "Kwi", + "Maj", + "Cze", + "Lip", + "Sie", + "Wrz", + "Paź", + "Lis", + "Gru" + ], + "long": [ + "Styczeń", + "Luty", + "Marzec", + "Kwiecień", + "Maj", + "Czerwiec", + "Lipiec", + "Sierpień", + "Wrzesień", + "Październik", + "Listopad", + "Grudzień" + ] + }, + "pt-BR": { + "short": [ + "Jan", + "Fev", + "Mar", + "Abr", + "Mai", + "Jun", + "Jul", + "Ago", + "Set", + "Out", + "Nov", + "Dez" + ], + "long": [ + "Janeiro", + "Fevereiro", + "Março", + "Abril", + "Maio", + "Junho", + "Julho", + "Agosto", + "Setembro", + "Outubro", + "Novembro", + "Dezembro" + ] + }, + "pt-PT": { + "short": [ + "Jan", + "Fev", + "Mar", + "Abr", + "Mai", + "Jun", + "Jul", + "Ago", + "Set", + "Out", + "Nov", + "Dez" + ], + "long": [ + "janeiro", + "fevereiro", + "março", + "abril", + "maio", + "junho", + "julho", + "agosto", + "setembro", + "outubro", + "novembro", + "dezembro" + ] + }, + "ro-RO": { + "short": [ + "Ian", + "Feb", + "Mar", + "Apr", + "Mai", + "Iun", + "Iul", + "Aug", + "Sep", + "Oct", + "Noi", + "Dec" + ], + "long": [ + "Ianuarie", + "Februarie", + "Martie", + "Aprilie", + "Mai", + "Iunie", + "Iulie", + "August", + "Septembrie", + "Octombrie", + "Noiembrie", + "Decembrie" + ] + }, + "ru-RU": { + "short": [ + "Январь", + "Февраль", + "Март", + "Апрель", + "Май", + "Июнь", + "Июль", + "Август", + "Сентябрь", + "Октябрь", + "Ноябрь", + "Декабрь" + ], + "long": [ + "Январь", + "Февраль", + "Март", + "Апрель", + "Май", + "Июнь", + "Июль", + "Август", + "Сентябрь", + "Октябрь", + "Ноябрь", + "Декабрь" + ] + }, + "sk-SK": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Máj", + "Jún", + "Júl", + "Aug", + "Sep", + "Okt", + "Nov", + "Dec" + ], + "long": [ + "Január", + "Február", + "Marec", + "Apríl", + "Máj", + "Jún", + "Júl", + "August", + "September", + "Október", + "November", + "December" + ] + }, + "sl-SI": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Maj", + "Jun", + "Jul", + "Avg", + "Sep", + "Okt", + "Nov", + "Dec" + ], + "long": [ + "Januar", + "Februar", + "Marec", + "April", + "Maj", + "Junij", + "Julij", + "Avgust", + "September", + "Oktober", + "November", + "December" + ] + }, + "sr-RS": { + "short": [ + "Јан", + "Феб", + "Мар", + "Апр", + "Мај", + "Јун", + "Јул", + "Авг", + "Сеп", + "Окт", + "Нов", + "Дец" + ], + "long": [ + "Јануар", + "Фебруар", + "Март", + "Април", + "Мај", + "Јун", + "Јул", + "Август", + "Септембар", + "Октобар", + "Новембар", + "Децембар" + ] + }, + "sv-SE": { + "short": [ + "Jan", + "Feb", + "Mar", + "Apr", + "Maj", + "Jun", + "Jul", + "Aug", + "Sep", + "Okt", + "Nov", + "Dec" + ], + "long": [ + "Januari", + "Februari", + "Mars", + "April", + "Maj", + "Juni", + "Juli", + "Augusti", + "September", + "Oktober", + "November", + "December" + ] + }, + "th-TH": { + "short": [ + "ม.ค.", + "ก.พ.", + "มี.ค.", + "เม.ย.", + "พ.ค.", + "มิ.ย.", + "ก.ค.", + "ส.ค.", + "ก.ย.", + "ต.ค.", + "พ.ย.", + "ธ.ค." + ], + "long": [ + "มกราคม", + "กุมภาพันธ์", + "มีนาคม", + "เมษายน", + "พฤษภาคม", + "มิถุนายน", + "กรกฎาคม", + "สิงหาคม", + "กันยายน", + "ตุลาคม", + "พฤศจิกายน", + "ธันวาคม" + ] + }, + "tr-TR": { + "short": [ + "Oca", + "Şub", + "Mar", + "Nis", + "May", + "Haz", + "Tem", + "Ağu", + "Eyl", + "Eki", + "Kas", + "Ara" + ], + "long": [ + "Ocak", + "Şubat", + "Mart", + "Nisan", + "Mayıs", + "Haziran", + "Temmuz", + "Ağustos", + "Eylül", + "Ekim", + "Kasım", + "Aralık" + ] + }, + "uk-UA": { + "short": [ + "Січ", + "Лют", + "Бер", + "Кві", + "Тра", + "Чер", + "Лип", + "Сер", + "Вер", + "Жов", + "Лис", + "Гру" + ], + "long": [ + "Січень", + "Лютий", + "Березень", + "Квітень", + "Травень", + "Червень", + "Липень", + "Серпень", + "Вересень", + "Жовтень", + "Листопад", + "Грудень" + ] + }, + "vi-VN": { + "short": [ + "Thg01", + "Thg02", + "Thg03", + "Thg04", + "Thg05", + "Thg06", + "Thg07", + "Thg08", + "Thg09", + "Thg10", + "Thg11", + "Thg12" + ], + "long": [ + "Tháng Một", + "Tháng Hai", + "Tháng Ba", + "Tháng Tư", + "Tháng Năm", + "Tháng Sáu", + "Tháng Bảy", + "Tháng Tám", + "Tháng Chín", + "Tháng Mười", + "Tháng Mười Một", + "Tháng Mười Hai" + ] + }, + "zh-CN": { + "short": [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月", + "七月", + "八月", + "九月", + "十月", + "十一月", + "十二月" + ], + "long": [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月", + "七月", + "八月", + "九月", + "十月", + "十一月", + "十二月" + ] + }, + "zh-TW": { + "short": [ + "1 月", + "2 月", + "3 月", + "4 月", + "5 月", + "6 月", + "7 月", + "8 月", + "9 月", + "10 月", + "11 月", + "12 月" + ], + "long": [ + "1 月", + "2 月", + "3 月", + "4 月", + "5 月", + "6 月", + "7 月", + "8 月", + "9 月", + "10 月", + "11 月", + "12 月" + ] + } +} \ No newline at end of file diff --git a/test/tests/dateTest.js b/test/tests/dateTest.js index c1235863d3..8e7083c76a 100644 --- a/test/tests/dateTest.js +++ b/test/tests/dateTest.js @@ -1,4 +1,122 @@ describe("Zotero.Date", function() { + describe("#getMonths()", function () { + var origLocale; + var englishShort = [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + ]; + var englishLong = [ + "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December" + ]; + var frenchShort = [ + "jan", "fév", "mar", "avr", "mai", "jun", "jul", "aoû", "sep", "oct", "nov", "dec" + ]; + var frenchLong = [ + "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", + "octobre", "novembre", "décembre" + ]; + + before(function () { + origLocale = Zotero.locale; + }); + + after(function () { + Zotero.locale = origLocale; + }); + + describe("English", function () { + beforeEach(function* () { + if (Zotero.locale != 'en-US') { + Zotero.locale = 'en-US'; + yield Zotero.Date.init(); + } + }); + + it("should get English short months", function () { + let months = Zotero.Date.getMonths().short; + assert.lengthOf(months, 12); + assert.sameMembers(months, englishShort); + }); + + it("should get English long months", function () { + let months = Zotero.Date.getMonths().long; + assert.lengthOf(months, 12); + assert.sameMembers(months, englishLong); + }); + + it("shouldn't repeat months in 'withEnglish' mode", function () { + let months = Zotero.Date.getMonths(true).short; + assert.lengthOf(months, 12); + assert.sameMembers(months, englishShort); + }); + + it("should resolve to English from unknown locale", function* () { + Zotero.locale = 'zz'; + yield Zotero.Date.init(); + let months = Zotero.Date.getMonths().short; + assert.lengthOf(months, 12); + assert.sameMembers(months, englishShort); + }); + + it("shouldn't repeat English with unknown locale", function* () { + Zotero.locale = 'zz'; + yield Zotero.Date.init(); + let months = Zotero.Date.getMonths(true).short; + assert.lengthOf(months, 12); + assert.sameMembers(months, englishShort); + }); + }); + + describe("French", function () { + beforeEach(function* () { + if (Zotero.locale != 'fr-FR') { + Zotero.locale = 'fr-FR'; + yield Zotero.Date.init(); + } + }); + + it("should get French short months", function () { + let months = Zotero.Date.getMonths().short; + assert.lengthOf(months, 12); + assert.sameMembers(months, frenchShort); + }); + + it("should get French long months", function () { + let months = Zotero.Date.getMonths().long; + assert.lengthOf(months, 12); + assert.sameMembers(months, frenchLong); + }); + + it("should get French short months with English", function () { + let months = Zotero.Date.getMonths(true).short; + assert.lengthOf(months, 24); + assert.sameMembers(months, frenchShort.concat(englishShort)); + }); + + it("should get French long months with English", function () { + let months = Zotero.Date.getMonths(true).long; + assert.lengthOf(months, 24); + assert.sameMembers(months, frenchLong.concat(englishLong)); + }); + + it("should resolve from two-letter locale", function* () { + Zotero.locale = 'fr'; + yield Zotero.Date.init(); + let months = Zotero.Date.getMonths().short; + assert.lengthOf(months, 12); + assert.sameMembers(months, frenchShort); + }); + + it("should resolve from unknown four-letter locale with common prefix", function* () { + Zotero.locale = 'fr-ZZ'; + yield Zotero.Date.init(); + let months = Zotero.Date.getMonths().short; + assert.lengthOf(months, 12); + assert.sameMembers(months, frenchShort); + }); + }); + }); + describe("#sqlToDate()", function () { it("should convert an SQL local date into a JS Date object", function* () { var d1 = new Date();