diff options
Diffstat (limited to 'js/dojo-1.7.2/dojox/date/islamic')
| -rw-r--r-- | js/dojo-1.7.2/dojox/date/islamic/Date.js | 425 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/date/islamic/locale.js | 417 |
2 files changed, 842 insertions, 0 deletions
diff --git a/js/dojo-1.7.2/dojox/date/islamic/Date.js b/js/dojo-1.7.2/dojox/date/islamic/Date.js new file mode 100644 index 0000000..938e0b3 --- /dev/null +++ b/js/dojo-1.7.2/dojox/date/islamic/Date.js @@ -0,0 +1,425 @@ +//>>built +define("dojox/date/islamic/Date", ["dojo/_base/kernel", "dojo/_base/declare", "dojo/date"], function(dojo, declare, dd){ + +dojo.getObject("date.buddhist.Date", true, dojox); +dojo.experimental("dojox.date.buddhist.Date"); + +dojo.declare("dojox.date.islamic.Date", null, { + // summary: The component defines the Islamic (Hijri) Calendar Object + // + // description: + // This module is similar to the Date() object provided by JavaScript + // + // example: + // | dojo.require("dojox.date.islamic.Date"); + // | + // | var date = new dojox.date.islamic.Date(); + // | document.writeln(date.getFullYear()+'\'+date.getMonth()+'\'+date.getDate()); + + + _date: 0, + _month: 0, + _year: 0, + _hours: 0, + _minutes: 0, + _seconds: 0, + _milliseconds: 0, + _day: 0, + _GREGORIAN_EPOCH : 1721425.5, + _ISLAMIC_EPOCH : 1948439.5, + + constructor: function(){ + // summary: This is the constructor + // description: + // This function initialize the date object values + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | + // | var date2 = new dojox.date.islamic.Date("12\2\1429"); + // | + // | var date3 = new dojox.date.islamic.Date(date2); + // | + // | var date4 = new dojox.date.islamic.Date(1429,2,12); + + var len = arguments.length; + if(!len){// use the current date value, added "" to the similarity to date + this.fromGregorian(new Date()); + }else if(len == 1){ + var arg0 = arguments[0]; + if(typeof arg0 == "number"){ // this is time "valueof" + arg0 = new Date(arg0); + } + + if(arg0 instanceof Date){ + this.fromGregorian(arg0); + }else if(arg0 == ""){ + // date should be invalid. Dijit relies on this behavior. + this._date = new Date(""); //TODO: should this be NaN? _date is not a Date object + }else{ // this is Islamic.Date object + this._year = arg0._year; + this._month = arg0._month; + this._date = arg0._date; + this._hours = arg0._hours; + this._minutes = arg0._minutes; + this._seconds = arg0._seconds; + this._milliseconds = arg0._milliseconds; + } + }else if(len >=3){ + // YYYY MM DD arguments passed, month is from 0-12 + this._year += arguments[0]; + this._month += arguments[1]; + this._date += arguments[2]; + this._hours += arguments[3] || 0; + this._minutes += arguments[4] || 0; + this._seconds += arguments[5] || 0; + this._milliseconds += arguments[6] || 0; + } + }, + + getDate:function(){ + // summary: This function returns the date value (1 - 30) + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | + // | document.writeln(date1.getDate); + return this._date; + }, + + getMonth:function(){ + // summary: This function return the month value ( 0 - 11 ) + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | + // | document.writeln(date1.getMonth()+1); + + return this._month; + }, + + getFullYear:function(){ + // summary: This function return the Year value + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | + // | document.writeln(date1.getFullYear()); + + return this._year; + }, + + getDay:function(){ + // summary: This function return Week Day value ( 0 - 6 ) + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | + // | document.writeln(date1.getDay()); + + return this.toGregorian().getDay(); + }, + + getHours:function(){ + //summary: returns the Hour value + return this._hours; + }, + + getMinutes:function(){ + //summary: returns the Minuites value + return this._minutes; + }, + + getSeconds:function(){ + //summary: returns the seconde value + return this._seconds; + }, + + getMilliseconds:function(){ + //summary: returns the Milliseconds value + return this._milliseconds; + }, + + setDate: function(/*number*/date){ + // summary: This function sets the Date + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | date1.setDate(2); + + date = parseInt(date); + + if(date > 0 && date <= this.getDaysInIslamicMonth(this._month, this._year)){ + this._date = date; + }else{ + var mdays; + if(date>0){ + for(mdays = this.getDaysInIslamicMonth(this._month, this._year); + date > mdays; + date -= mdays,mdays =this.getDaysInIslamicMonth(this._month, this._year)){ + this._month++; + if(this._month >= 12){this._year++; this._month -= 12;} + } + + this._date = date; + }else{ + for(mdays = this.getDaysInIslamicMonth((this._month-1)>=0 ?(this._month-1) :11 ,((this._month-1)>=0)? this._year: this._year-1); + date <= 0; + mdays = this.getDaysInIslamicMonth((this._month-1)>=0 ? (this._month-1) :11,((this._month-1)>=0)? this._year: this._year-1)){ + this._month--; + if(this._month < 0){this._year--; this._month += 12;} + + date+=mdays; + } + this._date = date; + } + } + return this; + }, + + setFullYear:function(/*number*/year){ + // summary: This function set Year + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | date1.setYear(1429); + + this._year = +year; + }, + + setMonth: function(/*number*/month) { + // summary: This function set Month + // + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | date1.setMonth(2); + + this._year += Math.floor(month / 12); + if(month > 0){ + this._month = Math.floor(month % 12); + }else{ + this._month = Math.floor(((month % 12) + 12) % 12); + } + }, + + setHours:function(){ + //summary: set the Hours + var hours_arg_no = arguments.length; + var hours = 0; + if(hours_arg_no >= 1){ + hours = parseInt(arguments[0]); + } + + if(hours_arg_no >= 2){ + this._minutes = parseInt(arguments[1]); + } + + if(hours_arg_no >= 3){ + this._seconds = parseInt(arguments[2]); + } + + if(hours_arg_no == 4){ + this._milliseconds = parseInt(arguments[3]); + } + + while(hours >= 24){ + this._date++; + var mdays = this.getDaysInIslamicMonth(this._month, this._year); + if(this._date > mdays){ + this._month ++; + if(this._month >= 12){this._year++; this._month -= 12;} + this._date -= mdays; + } + hours -= 24; + } + this._hours = hours; + }, + + _addMinutes: function(/*Number*/minutes){ + minutes += this._minutes; + this.setMinutes(minutes); + this.setHours(this._hours + parseInt(minutes / 60)); + return this; + }, + + _addSeconds: function(/*Number*/seconds){ + seconds += this._seconds; + this.setSeconds(seconds); + this._addMinutes(parseInt(seconds / 60)); + return this; + }, + + _addMilliseconds: function(/*Number*/milliseconds){ + milliseconds += this._milliseconds; + this.setMilliseconds(milliseconds); + this._addSeconds(parseInt(milliseconds / 1000)); + return this; + }, + + setMinutes: function(/*Number*/minutes){ + //summary: sets the minutes (0-59) only. + this._minutes = minutes % 60; + return this; + }, + + setSeconds: function(/*Number*/seconds){ + //summary: sets the seconds (0-59) only. + this._seconds = seconds % 60; + return this; + }, + + setMilliseconds: function(/*Number*/milliseconds){ + this._milliseconds = milliseconds % 1000; + return this; + }, + + toString:function(){ + // summary: This returns a string representation of the date in "DDDD MMMM DD YYYY HH:MM:SS" format + // example: + // | var date1 = new dojox.date.islamic.Date(); + // | document.writeln(date1.toString()); + + //FIXME: TZ/DST issues? + var x = new Date(); + x.setHours(this._hours); + x.setMinutes(this._minutes); + x.setSeconds(this._seconds); + x.setMilliseconds(this._milliseconds); + return this._month+" "+ this._date + " " + this._year + " " + x.toTimeString(); + }, + + + toGregorian:function(){ + // summary: This returns the equevalent Grogorian date value in Date object + // example: + // | var dateIslamic = new dojox.date.islamic.Date(1429,11,20); + // | var dateGregorian = dateIslamic.toGregorian(); + + var hYear = this._year; + var hMonth = this._month; + var hDate = this._date; + var julianDay = hDate + Math.ceil(29.5 * hMonth) + (hYear - 1) * 354 + + Math.floor((3 + (11 * hYear)) / 30) + this._ISLAMIC_EPOCH - 1; + + var wjd = Math.floor(julianDay - 0.5) + 0.5, + depoch = wjd - this._GREGORIAN_EPOCH, + quadricent = Math.floor(depoch / 146097), + dqc = this._mod(depoch, 146097), + cent = Math.floor(dqc / 36524), + dcent = this._mod(dqc, 36524), + quad = Math.floor(dcent / 1461), + dquad = this._mod(dcent, 1461), + yindex = Math.floor(dquad / 365), + year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex; + if(!(cent == 4 || yindex == 4)){ + year++; + } + + var gYearStart = this._GREGORIAN_EPOCH + (365 * (year - 1)) + Math.floor((year - 1) / 4) + - ( Math.floor((year - 1) / 100)) + Math.floor((year - 1) / 400); + + var yearday = wjd - gYearStart; + + var tjd = (this._GREGORIAN_EPOCH - 1) + (365 * (year - 1)) + Math.floor((year - 1) / 4) + -( Math.floor((year - 1) / 100)) + Math.floor((year - 1) / 400) + Math.floor( (739 / 12) + + ( (dd.isLeapYear(new Date(year,3,1)) ? -1 : -2)) + 1); + + var leapadj = ((wjd < tjd ) ? 0 : (dd.isLeapYear(new Date(year,3,1)) ? 1 : 2)); + + var month = Math.floor((((yearday + leapadj) * 12) + 373) / 367); + var tjd2 = (this._GREGORIAN_EPOCH - 1) + (365 * (year - 1)) + + Math.floor((year - 1) / 4) - (Math.floor((year - 1) / 100)) + + Math.floor((year - 1) / 400) + Math.floor((((367 * month) - 362) / 12) + + ((month <= 2) ? 0 : (dd.isLeapYear(new Date(year,month,1)) ? -1 : -2)) + 1); + + var day = (wjd - tjd2) + 1; + + var gdate = new Date(year, (month - 1), day, this._hours, this._minutes, this._seconds, this._milliseconds); + + return gdate; + }, + + //TODO: would it make more sense to make this a constructor option? or a static? + // ported from the Java class com.ibm.icu.util.IslamicCalendar from ICU4J v3.6.1 at http://www.icu-project.org/ + fromGregorian:function(/*Date*/gdate){ + // summary: This function returns the equivalent Islamic Date value for the Gregorian Date + // example: + // | var dateIslamic = new dojox.date.islamic.Date(); + // | var dateGregorian = new Date(2008,10,12); + // | dateIslamic.fromGregorian(dateGregorian); + + var date = new Date(gdate); + var gYear = date.getFullYear(), + gMonth = date.getMonth(), + gDay = date.getDate(); + + var julianDay = (this._GREGORIAN_EPOCH - 1) + (365 * (gYear - 1)) + Math.floor((gYear - 1) / 4) + + (-Math.floor((gYear - 1) / 100)) + Math.floor((gYear - 1) / 400) + + Math.floor((((367 * (gMonth+1)) - 362) / 12) + + (((gMonth+1) <= 2) ? 0 : (dd.isLeapYear(date) ? -1 : -2)) + gDay); + julianDay = Math.floor(julianDay) + 0.5; + + var days = julianDay - this._ISLAMIC_EPOCH; + var hYear = Math.floor( (30 * days + 10646) / 10631.0 ); + var hMonth = Math.ceil((days - 29 - this._yearStart(hYear)) / 29.5 ); + hMonth = Math.min(hMonth, 11); + var hDay = Math.ceil(days - this._monthStart(hYear, hMonth)) + 1; + + this._date = hDay; + this._month = hMonth; + this._year = hYear; + this._hours = date.getHours(); + this._minutes = date.getMinutes(); + this._seconds = date.getSeconds(); + this._milliseconds = date.getMilliseconds(); + this._day = date.getDay(); + return this; + }, + + valueOf:function(){ + // summary: This function returns The stored time value in milliseconds + // since midnight, January 1, 1970 UTC + + return this.toGregorian().valueOf(); + }, + + // ported from the Java class com.ibm.icu.util.IslamicCalendar from ICU4J v3.6.1 at http://www.icu-project.org/ + _yearStart:function(/*Number*/year){ + //summary: return start of Islamic year + return (year-1)*354 + Math.floor((3+11*year)/30.0); + }, + + // ported from the Java class com.ibm.icu.util.IslamicCalendar from ICU4J v3.6.1 at http://www.icu-project.org/ + _monthStart:function(/*Number*/year, /*Number*/month){ + //summary: return the start of Islamic Month + return Math.ceil(29.5*month) + + (year-1)*354 + Math.floor((3+11*year)/30.0); + }, + + // ported from the Java class com.ibm.icu.util.IslamicCalendar from ICU4J v3.6.1 at http://www.icu-project.org/ + _civilLeapYear:function(/*Number*/year){ + //summary: return Boolean value if Islamic leap year + return (14 + 11 * year) % 30 < 11; + }, + + // ported from the Java class com.ibm.icu.util.IslamicCalendar from ICU4J v3.6.1 at http://www.icu-project.org/ + getDaysInIslamicMonth:function(/*Number*/month, /*Number*/ year){ + //summary: returns the number of days in the given Islamic Month + var length = 0; + length = 29 + ((month+1) % 2); + if(month == 11 && this._civilLeapYear(year)){ + length++; + } + return length; + }, + + _mod:function(a, b){ + return a - (b * Math.floor(a / b)); + } +}); + +//TODOC +dojox.date.islamic.Date.getDaysInIslamicMonth = function(/*dojox.date.islamic.Date*/month){ + return new dojox.date.islamic.Date().getDaysInIslamicMonth(month.getMonth(),month.getFullYear()); // dojox.date.islamic.Date +}; +return dojox.date.islamic.Date; +}); diff --git a/js/dojo-1.7.2/dojox/date/islamic/locale.js b/js/dojo-1.7.2/dojox/date/islamic/locale.js new file mode 100644 index 0000000..484f23f --- /dev/null +++ b/js/dojo-1.7.2/dojox/date/islamic/locale.js @@ -0,0 +1,417 @@ +//>>built +define("dojox/date/islamic/locale", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/array", "dojo/date", "dojo/i18n", "dojo/regexp", "dojo/string", "./Date", "dojo/i18n!dojo/cldr/nls/islamic"], + function(dojo, dlang, darray, dd, i18n, regexp, string, islamicDate){ + + dojo.getObject("date.islamic.locale", true, dojox); + dojo.experimental("dojox.date.islamic.locale"); + + dojo.requireLocalization("dojo.cldr", "islamic"); + + // Format a pattern without literals + function formatPattern(dateObject, bundle, locale, fullYear, pattern){ + + return pattern.replace(/([a-z])\1*/ig, function(match){ + var s, pad; + var c = match.charAt(0); + var l = match.length; + var widthList = ["abbr", "wide", "narrow"]; + + switch(c){ + case 'G': + s = bundle["eraAbbr"][0]; + break; + case 'y': + s = String(dateObject.getFullYear()); + break; + case 'M': + var m = dateObject.getMonth(); + if(l<3){ + s = m+1; pad = true; + }else{ + var propM = ["months", "format", widthList[l-3]].join("-"); + s = bundle[propM][m]; + } + break; + case 'd': + s = dateObject.getDate(true); pad = true; + break; + case 'E': + var d = dateObject.getDay(); + if(l<3){ + s = d+1; pad = true; + }else{ + var propD = ["days", "format", widthList[l-3]].join("-"); + s = bundle[propD][d]; + } + break; + case 'a': + var timePeriod = (dateObject.getHours() < 12) ? 'am' : 'pm'; + s = bundle['dayPeriods-format-wide-' + timePeriod]; + break; + case 'h': + case 'H': + case 'K': + case 'k': + var h = dateObject.getHours(); + switch (c){ + case 'h': // 1-12 + s = (h % 12) || 12; + break; + case 'H': // 0-23 + s = h; + break; + case 'K': // 0-11 + s = (h % 12); + break; + case 'k': // 1-24 + s = h || 24; + break; + } + pad = true; + break; + case 'm': + s = dateObject.getMinutes(); pad = true; + break; + case 's': + s = dateObject.getSeconds(); pad = true; + break; + case 'S': + s = Math.round(dateObject.getMilliseconds() * Math.pow(10, l-3)); pad = true; + break; + case 'z': + // We only have one timezone to offer; the one from the browser + s = dd.getTimezoneName(dateObject.toGregorian()); + if(s){ break; } + l = 4; + // fallthrough... use GMT if tz not available + case 'Z': + var offset = dateObject.toGregorian().getTimezoneOffset(); + var tz = [ + (offset <= 0 ? "+" : "-"), + string.pad(Math.floor(Math.abs(offset) / 60), 2), + string.pad(Math.abs(offset) % 60, 2) + ]; + if(l == 4){ + tz.splice(0, 0, "GMT"); + tz.splice(3, 0, ":"); + } + s = tz.join(""); + break; + default: + throw new Error("dojox.date.islamic.locale.formatPattern: invalid pattern char: "+pattern); + } + if(pad){ s = string.pad(s, l); } + return s; + }); + } + + // based on and similar to dojo.date.locale.format + dojox.date.islamic.locale.format = function(/*islamic.Date*/dateObject, /*Object?*/options){ + // summary: + // Format a Date object as a String, using settings. + options = options || {}; + + var locale = i18n.normalizeLocale(options.locale); + var formatLength = options.formatLength || 'short'; + var bundle = dojox.date.islamic.locale._getIslamicBundle(locale); + var str = []; + + var sauce = dojo.hitch(this, formatPattern, dateObject, bundle, locale, options.fullYear); + if(options.selector == "year"){ + var year = dateObject.getFullYear(); + return year; + } + if(options.selector != "time"){ + var datePattern = options.datePattern || bundle["dateFormat-"+formatLength]; + if(datePattern){str.push(_processPattern(datePattern, sauce));} + } + if(options.selector != "date"){ + var timePattern = options.timePattern || bundle["timeFormat-"+formatLength]; + if(timePattern){str.push(_processPattern(timePattern, sauce));} + } + var result = str.join(" "); //TODO: use locale-specific pattern to assemble date + time + + return result; // String + }; + + dojox.date.islamic.locale.regexp = function(/*object?*/options){ + // based on and similar to dojo.date.locale.regexp + // summary: + // Builds the regular needed to parse a islamic.Date + return dojox.date.islamic.locale._parseInfo(options).regexp; // String + }; + + dojox.date.islamic.locale._parseInfo = function(/*oblect?*/options){ + /* based on and similar to dojo.date.locale._parseInfo */ + + options = options || {}; + var locale = i18n.normalizeLocale(options.locale); + var bundle = dojox.date.islamic.locale._getIslamicBundle(locale); + var formatLength = options.formatLength || 'short'; + var datePattern = options.datePattern || bundle["dateFormat-" + formatLength]; + var timePattern = options.timePattern || bundle["timeFormat-" + formatLength]; + + var pattern; + if(options.selector == 'date'){ + pattern = datePattern; + }else if(options.selector == 'time'){ + pattern = timePattern; + }else{ + pattern = (typeof (timePattern) == "undefined") ? datePattern : datePattern + ' ' + timePattern; + } + + var tokens = []; + + var re = _processPattern(pattern, dojo.hitch(this, _buildDateTimeRE, tokens, bundle, options)); + return {regexp: re, tokens: tokens, bundle: bundle}; + }; + + dojox.date.islamic.locale.parse = function(/*String*/value, /*Object?*/options){ + // based on and similar to dojo.date.locale.parse + // summary: This function parse string date value according to options + + value = value.replace(/[\u200E\u200F\u202A\u202E]/g, ""); //remove bidi non-printing chars + + if(!options){ options={}; } + var info = dojox.date.islamic.locale._parseInfo(options); + + var tokens = info.tokens, bundle = info.bundle; + var regexp = info.regexp.replace(/[\u200E\u200F\u202A\u202E]/g, ""); //remove bidi non-printing chars from the pattern + var re = new RegExp("^" + regexp + "$"); + + var match = re.exec(value); + + var locale = i18n.normalizeLocale(options.locale); + + if(!match){ + console.debug("dojox.date.islamic.locale.parse: value "+value+" doesn't match pattern " + re); + return null; + } // null + + var date, date1; + + var result = [1389,0,1,0,0,0,0]; //FIXME: islamic date for [1970,0,1,0,0,0,0] used in gregorian locale + var amPm = ""; + var mLength = 0; + var widthList = ["abbr", "wide", "narrow"]; + var valid = dojo.every(match, function(v, i){ + if(!i){return true;} + var token=tokens[i-1]; + var l=token.length; + switch(token.charAt(0)){ + case 'y': + result[0] = Number(v); + break; + case 'M': + if(l>2){ + var months = bundle['months-format-' + widthList[l-3]].concat(); + if(!options.strict){ + //Tolerate abbreviating period in month part + //Case-insensitive comparison + v = v.replace(".","").toLowerCase(); + months = dojo.map(months, function(s){ return s ? s.replace(".","").toLowerCase() : s; } ); + } + v = dojo.indexOf(months, v); + if(v == -1){ + return false; + } + mLength = l; + }else{ + v--; + } + result[1] = Number(v); + break; + case 'D': + result[1] = 0; + // fallthrough... + case 'd': + result[2] = Number(v); + break; + case 'a': //am/pm + var am = options.am || bundle['dayPeriods-format-wide-am'], + pm = options.pm || bundle['dayPeriods-format-wide-pm']; + if(!options.strict){ + var period = /\./g; + v = v.replace(period,'').toLowerCase(); + am = am.replace(period,'').toLowerCase(); + pm = pm.replace(period,'').toLowerCase(); + } + if(options.strict && v != am && v != pm){ + return false; + } + + // we might not have seen the hours field yet, so store the state and apply hour change later + amPm = (v == pm) ? 'p' : (v == am) ? 'a' : ''; + break; + case 'K': //hour (1-24) + if(v == 24){ v = 0; } + // fallthrough... + case 'h': //hour (1-12) + case 'H': //hour (0-23) + case 'k': //hour (0-11) + //in the 12-hour case, adjusting for am/pm requires the 'a' part + //which could come before or after the hour, so we will adjust later + result[3] = Number(v); + break; + case 'm': //minutes + result[4] = Number(v); + break; + case 's': //seconds + result[5] = Number(v); + break; + case 'S': //milliseconds + result[6] = Number(v); + } + return true; + }); + + var hours = +result[3]; + if(amPm === 'p' && hours < 12){ + result[3] = hours + 12; //e.g., 3pm -> 15 + }else if(amPm === 'a' && hours == 12){ + result[3] = 0; //12am -> 0 + } + var dateObject = new islamicDate(result[0], result[1], result[2], result[3], result[4], result[5], result[6]); + return dateObject; + }; + + function _processPattern(pattern, applyPattern, applyLiteral, applyAll){ + //summary: Process a pattern with literals in it + + // Break up on single quotes, treat every other one as a literal, except '' which becomes ' + var identity = function(x){return x;}; + applyPattern = applyPattern || identity; + applyLiteral = applyLiteral || identity; + applyAll = applyAll || identity; + + //split on single quotes (which escape literals in date format strings) + //but preserve escaped single quotes (e.g., o''clock) + var chunks = pattern.match(/(''|[^'])+/g); + var literal = pattern.charAt(0) == "'"; + + dojo.forEach(chunks, function(chunk, i){ + if(!chunk){ + chunks[i]=''; + }else{ + chunks[i]=(literal ? applyLiteral : applyPattern)(chunk); + literal = !literal; + } + }); + return applyAll(chunks.join('')); + } + + function _buildDateTimeRE (tokens, bundle, options, pattern){ + // based on and similar to dojo.date.locale._buildDateTimeRE + // + + pattern = regexp.escapeString(pattern); + var locale = i18n.normalizeLocale(options.locale); + + return pattern.replace(/([a-z])\1*/ig, function(match){ + + // Build a simple regexp. Avoid captures, which would ruin the tokens list + var s; + var c = match.charAt(0); + var l = match.length; + var p2 = '', p3 = ''; + if(options.strict){ + if(l > 1){ p2 = '0' + '{'+(l-1)+'}'; } + if(l > 2){ p3 = '0' + '{'+(l-2)+'}'; } + }else{ + p2 = '0?'; p3 = '0{0,2}'; + } + switch(c){ + case 'y': + s = '\\d+'; + break; + case 'M': + s = (l>2) ? '\\S+ ?\\S+' : p2+'[1-9]|1[0-2]'; + break; + case 'd': + s = '[12]\\d|'+p2+'[1-9]|3[01]'; + break; + case 'E': + s = '\\S+'; + break; + case 'h': //hour (1-12) + s = p2+'[1-9]|1[0-2]'; + break; + case 'k': //hour (0-11) + s = p2+'\\d|1[01]'; + break; + case 'H': //hour (0-23) + s = p2+'\\d|1\\d|2[0-3]'; + break; + case 'K': //hour (1-24) + s = p2+'[1-9]|1\\d|2[0-4]'; + break; + case 'm': + case 's': + s = p2+'\\d|[0-5]\\d'; + break; + case 'S': + s = '\\d{'+l+'}'; + break; + case 'a': + var am = options.am || bundle['dayPeriods-format-wide-am'], + pm = options.pm || bundle['dayPeriods-format-wide-pm']; + if(options.strict){ + s = am + '|' + pm; + }else{ + s = am + '|' + pm; + if(am != am.toLowerCase()){ s += '|' + am.toLowerCase(); } + if(pm != pm.toLowerCase()){ s += '|' + pm.toLowerCase(); } + } + break; + default: + s = ".*"; + } + if(tokens){ tokens.push(match); } + return "(" + s + ")"; // add capture + }).replace(/[\xa0 ]/g, "[\\s\\xa0]"); // normalize whitespace. Need explicit handling of \xa0 for IE. */ + } + + var _customFormats = []; + dojox.date.islamic.locale.addCustomFormats = function(/*String*/packageName, /*String*/bundleName){ + // summary: + // Add a reference to a bundle containing localized custom formats to be + // used by date/time formatting and parsing routines. + _customFormats.push({pkg:packageName,name:bundleName}); + }; + + dojox.date.islamic.locale._getIslamicBundle = function(/*String*/locale){ + var islamic = {}; + dojo.forEach(_customFormats, function(desc){ + var bundle = i18n.getLocalization(desc.pkg, desc.name, locale); + islamic = dojo.mixin(islamic, bundle); + }, this); + return islamic; /*Object*/ + }; + + dojox.date.islamic.locale.addCustomFormats("dojo.cldr","islamic"); + + dojox.date.islamic.locale.getNames = function(/*String*/item, /*String*/type, /*String?*/context, /*String?*/locale, /*islamic Date Object?*/date){ + // summary: + // Used to get localized strings from dojo.cldr for day or month names. + var label; + var lookup = dojox.date.islamic.locale._getIslamicBundle(locale); + var props = [item, context, type]; + if(context == 'standAlone'){ + var key = props.join('-'); + label = lookup[key]; + // Fall back to 'format' flavor of name + if(label[0] == 1){ label = undefined; } // kludge, in the absence of real aliasing support in dojo.cldr + } + props[1] = 'format'; + + // return by copy so changes won't be made accidentally to the in-memory model + return (label || lookup[props.join('-')]).concat(); /*Array*/ + }; + + + dojox.date.islamic.locale.weekDays = dojox.date.islamic.locale.getNames('days', 'wide', 'format'); + + dojox.date.islamic.locale.months = dojox.date.islamic.locale.getNames('months', 'wide', 'format'); + + return dojox.date.islamic.locale; +});
\ No newline at end of file |
