1 Clazz.declarePackage ("java.text");
2 Clazz.load (["java.text.DateFormat", "java.util.Hashtable", "java.text.DecimalFormat", "java.util.Calendar", "$.TimeZone", "jssun.util.calendar.ZoneInfo"], "java.text.SimpleDateFormat", ["java.lang.IllegalArgumentException", "$.NullPointerException", "$.Number", "$.StringBuffer", "$.StringBuilder", "java.text.MessageFormat", "java.util.Date", "java.text.CharacterIteratorFieldDelegate", "$.DateFormatSymbols", "$.DontCareFieldPosition", "$.NumberFormat", "java.util.GregorianCalendar", "$.Locale", "jssun.util.calendar.CalendarUtils", "jssun.util.resources.LocaleData"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.serialVersionOnStream = 1;
6 this.compiledPattern = null;
8 this.formatData = null;
9 this.defaultCenturyStart = null;
10 this.defaultCenturyStartYear = 0;
12 this.$useDateFormatSymbols = false;
13 Clazz.instantialize (this, arguments);
14 }, java.text, "SimpleDateFormat", java.text.DateFormat);
15 Clazz.makeConstructor (c$,
17 this.construct (3, 3, java.util.Locale.getDefault ());
19 Clazz.makeConstructor (c$,
21 this.construct (pattern, java.util.Locale.getDefault ());
23 Clazz.makeConstructor (c$,
24 function (pattern, locale) {
25 Clazz.superConstructor (this, java.text.SimpleDateFormat, []);
26 if (pattern == null || locale == null) {
27 throw new NullPointerException ();
28 }this.initializeCalendar (locale);
29 this.pattern = pattern;
30 this.formatData = java.text.DateFormatSymbols.getInstance (locale);
32 this.initialize (locale);
33 }, "~S,java.util.Locale");
34 Clazz.makeConstructor (c$,
35 function (pattern, formatSymbols) {
36 Clazz.superConstructor (this, java.text.SimpleDateFormat, []);
37 if (pattern == null || formatSymbols == null) {
38 throw new NullPointerException ();
39 }this.pattern = pattern;
40 this.formatData = formatSymbols.clone ();
41 this.locale = java.util.Locale.getDefault ();
42 this.initializeCalendar (this.locale);
43 this.initialize (this.locale);
44 this.$useDateFormatSymbols = true;
45 }, "~S,java.text.DateFormatSymbols");
46 Clazz.makeConstructor (c$,
47 function (timeStyle, dateStyle, loc) {
48 Clazz.superConstructor (this, java.text.SimpleDateFormat, []);
50 throw new NullPointerException ();
52 this.initializeCalendar (loc);
53 var key = this.getKey ();
54 var dateTimePatterns = java.text.SimpleDateFormat.cachedLocaleData.get (key);
55 if (dateTimePatterns == null) {
56 var r = jssun.util.resources.LocaleData.getDateFormatData (loc);
57 if (!this.isGregorianCalendar ()) {
59 dateTimePatterns = r.getStringArray (this.getCalendarName () + ".DateTimePatterns");
61 if (Clazz.exceptionOf (e, java.util.MissingResourceException)) {
66 }if (dateTimePatterns == null) {
67 dateTimePatterns = r.getStringArray ("DateTimePatterns");
68 }java.text.SimpleDateFormat.cachedLocaleData.put (key, dateTimePatterns);
69 }this.formatData = java.text.DateFormatSymbols.getInstance (loc);
70 if ((timeStyle >= 0) && (dateStyle >= 0)) {
71 var dateTimeArgs = Clazz.newArray (-1, [dateTimePatterns[timeStyle], dateTimePatterns[dateStyle + 4]]);
72 this.pattern = java.text.MessageFormat.format (dateTimePatterns[8], dateTimeArgs);
73 } else if (timeStyle >= 0) {
74 this.pattern = dateTimePatterns[timeStyle];
75 } else if (dateStyle >= 0) {
76 this.pattern = dateTimePatterns[dateStyle + 4];
78 throw new IllegalArgumentException ("No date or time style specified");
79 }this.initialize (loc);
80 }, "~N,~N,java.util.Locale");
81 Clazz.defineMethod (c$, "initialize",
83 this.compiledPattern = this.compile (this.pattern);
84 this.numberFormat = java.text.SimpleDateFormat.cachedNumberFormatData.get (loc);
85 if (this.numberFormat == null) {
86 this.numberFormat = java.text.NumberFormat.getIntegerInstance (loc);
87 this.numberFormat.setGroupingUsed (false);
88 java.text.SimpleDateFormat.cachedNumberFormatData.put (loc, this.numberFormat);
89 }this.numberFormat = this.numberFormat.clone ();
90 this.initializeDefaultCentury ();
91 }, "java.util.Locale");
92 Clazz.defineMethod (c$, "initializeCalendar",
94 if (this.calendar == null) {
95 this.calendar = java.util.Calendar.getInstance (java.util.TimeZone.getDefault (), loc);
96 }}, "java.util.Locale");
97 Clazz.defineMethod (c$, "getKey",
99 var sb = new StringBuilder ();
100 sb.append (this.getCalendarName ()).append ('.');
101 sb.append (this.locale.getLanguage ()).append ('_').append (this.locale.getCountry ()).append ('_').append (this.locale.getVariant ());
102 return sb.toString ();
104 Clazz.defineMethod (c$, "compile",
106 var length = pattern.length;
108 var compiledPattern = new StringBuilder (length * 2);
109 var tmpBuffer = null;
112 for (var i = 0; i < length; i++) {
113 var c = pattern.charAt (i);
115 if ((i + 1) < length) {
116 c = pattern.charAt (i + 1);
120 java.text.SimpleDateFormat.encode (lastTag, count, compiledPattern);
124 tmpBuffer.append (c);
126 compiledPattern.append (String.fromCharCode (25600 | c.charCodeAt (0)));
130 java.text.SimpleDateFormat.encode (lastTag, count, compiledPattern);
133 }if (tmpBuffer == null) {
134 tmpBuffer = new StringBuilder (length);
136 tmpBuffer.setLength (0);
139 var len = tmpBuffer.length ();
141 var ch = tmpBuffer.charAt (0);
142 if (ch.charCodeAt (0) < 128) {
143 compiledPattern.append (String.fromCharCode (25600 | ch.charCodeAt (0)));
145 compiledPattern.append (String.fromCharCode (25857));
146 compiledPattern.append (ch);
148 java.text.SimpleDateFormat.encode (101, len, compiledPattern);
149 compiledPattern.append (tmpBuffer);
153 tmpBuffer.append (c);
155 }if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) {
157 java.text.SimpleDateFormat.encode (lastTag, count, compiledPattern);
160 }if (c.charCodeAt (0) < 128) {
161 compiledPattern.append (String.fromCharCode (25600 | c.charCodeAt (0)));
164 for (j = i + 1; j < length; j++) {
165 var d = pattern.charAt (j);
166 if (d == '\'' || (d >= 'a' && d <= 'z' || d >= 'A' && d <= 'Z')) {
169 compiledPattern.append (String.fromCharCode (25856 | (j - i)));
171 compiledPattern.append (pattern.charAt (i));
176 if ((tag = "GyMdkHmsSEDFwWahKzZ".indexOf (c)) == -1) {
177 throw new IllegalArgumentException ("Illegal pattern character \'" + c + "'");
178 }if (lastTag == -1 || lastTag == tag) {
182 }java.text.SimpleDateFormat.encode (lastTag, count, compiledPattern);
187 throw new IllegalArgumentException ("Unterminated quote");
189 java.text.SimpleDateFormat.encode (lastTag, count, compiledPattern);
190 }var len = compiledPattern.length ();
191 var r = Clazz.newCharArray (len, '\0');
192 compiledPattern.getChars (0, len, r, 0);
195 c$.encode = Clazz.defineMethod (c$, "encode",
196 function (tag, length, buffer) {
198 buffer.append (String.fromCharCode (tag << 8 | length));
200 buffer.append (String.fromCharCode ((tag << 8) | 0xff));
201 buffer.append (String.fromCharCode (length >>> 16));
202 buffer.append (String.fromCharCode (length & 0xffff));
203 }}, "~N,~N,StringBuilder");
204 Clazz.defineMethod (c$, "initializeDefaultCentury",
206 this.calendar.setTime ( new java.util.Date ());
207 this.calendar.add (1, -80);
208 this.parseAmbiguousDatesAsAfter (this.calendar.getTime ());
210 Clazz.defineMethod (c$, "parseAmbiguousDatesAsAfter",
211 function (startDate) {
212 this.defaultCenturyStart = startDate;
213 this.calendar.setTime (startDate);
214 this.defaultCenturyStartYear = this.calendar.get (1);
215 }, "java.util.Date");
216 Clazz.defineMethod (c$, "set2DigitYearStart",
217 function (startDate) {
218 this.parseAmbiguousDatesAsAfter (startDate);
219 }, "java.util.Date");
220 Clazz.defineMethod (c$, "get2DigitYearStart",
222 return this.defaultCenturyStart;
224 Clazz.defineMethod (c$, "format",
225 function (date, toAppendTo, pos) {
226 pos.beginIndex = pos.endIndex = 0;
227 return this.format (date, toAppendTo, pos.getFieldDelegate ());
228 }, "java.util.Date,StringBuffer,java.text.FieldPosition");
229 Clazz.defineMethod (c$, "format",
230 function (date, toAppendTo, delegate) {
231 this.calendar.setTime (date);
232 var useDateFormatSymbols = this.useDateFormatSymbols ();
233 for (var i = 0; i < this.compiledPattern.length; ) {
234 var tag = (this.compiledPattern[i]).charCodeAt (0) >>> 8;
235 var count = (this.compiledPattern[i++]).charCodeAt (0) & 0xff;
237 count = (this.compiledPattern[i++]).charCodeAt (0) << 16;
238 count |= (this.compiledPattern[i++]).charCodeAt (0);
241 toAppendTo.append (String.fromCharCode (count));
244 toAppendTo.append (this.compiledPattern, i, count);
248 this.subFormat (tag, count, delegate, toAppendTo, useDateFormatSymbols);
253 }, "java.util.Date,StringBuffer,java.text.Format.FieldDelegate");
254 Clazz.overrideMethod (c$, "formatToCharacterIterator",
256 var sb = new StringBuffer ();
257 var delegate = new java.text.CharacterIteratorFieldDelegate ();
258 if (Clazz.instanceOf (obj, java.util.Date)) {
259 this.format (obj, sb, delegate);
260 } else if (Clazz.instanceOf (obj, Number)) {
261 this.format ( new java.util.Date ((obj).longValue ()), sb, delegate);
262 } else if (obj == null) {
263 throw new NullPointerException ("formatToCharacterIterator must be passed non-null object");
265 throw new IllegalArgumentException ("Cannot format given Object as a Date");
266 }return delegate.getIterator (sb.toString ());
268 Clazz.defineMethod (c$, "subFormat",
269 function (patternCharIndex, count, delegate, buffer, useDateFormatSymbols) {
270 var maxIntCount = 2147483647;
272 var beginOffset = buffer.length ();
273 var field = java.text.SimpleDateFormat.PATTERN_INDEX_TO_CALENDAR_FIELD[patternCharIndex];
274 var value = this.calendar.get (field);
275 var style = (count >= 4) ? 2 : 1;
276 if (!useDateFormatSymbols) {
277 current = this.calendar.getDisplayName (field, style, this.locale);
278 }switch (patternCharIndex) {
280 if (useDateFormatSymbols) {
281 var eras = this.formatData.getEras ();
282 if (value < eras.length) current = eras[value];
283 }if (current == null) current = "";
286 if (Clazz.instanceOf (this.calendar, java.util.GregorianCalendar)) {
287 if (count >= 4) this.zeroPaddingNumber (value, count, maxIntCount, buffer);
288 else this.zeroPaddingNumber (value, 2, 2, buffer);
290 if (current == null) {
291 this.zeroPaddingNumber (value, style == 2 ? 1 : count, maxIntCount, buffer);
294 if (useDateFormatSymbols) {
297 months = this.formatData.getMonths ();
298 current = months[value];
299 } else if (count == 3) {
300 months = this.formatData.getShortMonths ();
301 current = months[value];
305 }}if (current == null) {
306 this.zeroPaddingNumber (value + 1, count, maxIntCount, buffer);
309 if (current == null) {
310 if (value == 0) this.zeroPaddingNumber (this.calendar.getMaximum (11) + 1, count, maxIntCount, buffer);
311 else this.zeroPaddingNumber (value, count, maxIntCount, buffer);
314 if (useDateFormatSymbols) {
317 weekdays = this.formatData.getWeekdays ();
318 current = weekdays[value];
320 weekdays = this.formatData.getShortWeekdays ();
321 current = weekdays[value];
324 if (useDateFormatSymbols) {
325 var ampm = this.formatData.getAmPmStrings ();
326 current = ampm[value];
329 if (current == null) {
330 if (value == 0) this.zeroPaddingNumber (this.calendar.getLeastMaximum (10) + 1, count, maxIntCount, buffer);
331 else this.zeroPaddingNumber (value, count, maxIntCount, buffer);
334 if (current == null) {
335 var id = this.calendar.getTimeZone ().getID ();
339 value = Clazz.doubleToInt ((this.calendar.get (15) + this.calendar.get (16)) / 60000);
345 }var num = (Clazz.doubleToInt (value / 60)) * 100 + (value % 60);
346 jssun.util.calendar.CalendarUtils.sprintf0d (buffer, num, width);
349 if (current == null) {
350 this.zeroPaddingNumber (value, count, maxIntCount, buffer);
353 if (current != null) {
354 buffer.append (current);
355 }var fieldID = java.text.SimpleDateFormat.PATTERN_INDEX_TO_DATE_FORMAT_FIELD[patternCharIndex];
356 var f = java.text.SimpleDateFormat.PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID[patternCharIndex];
357 delegate.formatted (fieldID, f, f, beginOffset, buffer.length (), buffer);
358 }, "~N,~N,java.text.Format.FieldDelegate,StringBuffer,~B");
359 Clazz.defineMethod (c$, "zeroPaddingNumber",
360 function (value, minDigits, maxDigits, buffer) {
362 if (this.zeroDigit.charCodeAt (0) == 0) {
363 this.zeroDigit = (this.numberFormat).getDecimalFormatSymbols ().getZeroDigit ();
365 if (value < 100 && minDigits >= 1 && minDigits <= 2) {
367 if (minDigits == 2) {
368 buffer.append (this.zeroDigit);
369 }buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + value));
371 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + Clazz.doubleToInt (value / 10)));
372 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + value % 10));
374 } else if (value >= 1000 && value < 10000) {
375 if (minDigits == 4) {
376 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + Clazz.doubleToInt (value / 1000)));
378 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + Clazz.doubleToInt (value / 100)));
380 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + Clazz.doubleToInt (value / 10)));
381 buffer.append (String.fromCharCode (this.zeroDigit.charCodeAt (0) + value % 10));
383 }if (minDigits == 2 && maxDigits == 2) {
384 this.zeroPaddingNumber (value % 100, 2, 2, buffer);
387 if (Clazz.exceptionOf (e, Exception)) {
392 this.numberFormat.setMinimumIntegerDigits (minDigits);
393 this.numberFormat.setMaximumIntegerDigits (maxDigits);
394 this.numberFormat.format (value, buffer, java.text.DontCareFieldPosition.INSTANCE);
395 }, "~N,~N,~N,StringBuffer");
396 Clazz.defineMethod (c$, "parse",
397 function (text, pos) {
399 var i0 = pos.index; pos.index = Math.min(80, text.length()); while
400 (pos.index >= i0) { var d = new Date(text.substring(i0,
401 pos.index)); var x = d.getMilliseconds(); if (!isNaN(x))
402 return d; pos.index--; }
405 }}, "~S,java.text.ParsePosition");
406 Clazz.defineMethod (c$, "getCalendarName",
408 return this.calendar.getClass ().getName ();
410 Clazz.defineMethod (c$, "useDateFormatSymbols",
412 if (this.$useDateFormatSymbols) {
414 }return this.isGregorianCalendar () || this.locale == null;
416 Clazz.defineMethod (c$, "isGregorianCalendar",
418 return "java.util.GregorianCalendar".equals (this.getCalendarName ());
420 Clazz.defineMethod (c$, "translatePattern",
421 function (pattern, from, to) {
422 var result = new StringBuilder ();
424 for (var i = 0; i < pattern.length; ++i) {
425 var c = pattern.charAt (i);
427 if (c == '\'') inQuote = false;
429 if (c == '\'') inQuote = true;
430 else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
431 var ci = from.indexOf (c);
432 if (ci == -1) throw new IllegalArgumentException ("Illegal pattern character \'" + c + "'");
436 if (inQuote) throw new IllegalArgumentException ("Unfinished quote in pattern");
437 return result.toString ();
439 Clazz.defineMethod (c$, "toPattern",
443 Clazz.defineMethod (c$, "toLocalizedPattern",
445 return this.translatePattern (this.pattern, "GyMdkHmsSEDFwWahKzZ", this.formatData.getLocalPatternChars ());
447 Clazz.defineMethod (c$, "applyPattern",
449 this.compiledPattern = this.compile (pattern);
450 this.pattern = pattern;
452 Clazz.defineMethod (c$, "applyLocalizedPattern",
454 var p = this.translatePattern (pattern, this.formatData.getLocalPatternChars (), "GyMdkHmsSEDFwWahKzZ");
455 this.compiledPattern = this.compile (p);
458 Clazz.defineMethod (c$, "getDateFormatSymbols",
460 return this.formatData.clone ();
462 Clazz.defineMethod (c$, "setDateFormatSymbols",
463 function (newFormatSymbols) {
464 this.formatData = newFormatSymbols.clone ();
465 this.$useDateFormatSymbols = true;
466 }, "java.text.DateFormatSymbols");
467 Clazz.defineMethod (c$, "clone",
469 var other = Clazz.superCall (this, java.text.SimpleDateFormat, "clone", []);
470 other.formatData = this.formatData.clone ();
473 Clazz.overrideMethod (c$, "hashCode",
475 return this.pattern.hashCode ();
477 Clazz.defineMethod (c$, "equals",
479 if (!Clazz.superCall (this, java.text.SimpleDateFormat, "equals", [obj])) return false;
481 return (this.pattern.equals (that.pattern) && this.formatData.equals (that.formatData));
483 Clazz.defineStatics (c$,
484 "currentSerialVersion", 1,
485 "TAG_QUOTE_ASCII_CHAR", 100,
486 "TAG_QUOTE_CHARS", 101,
487 "millisPerHour", 3600000,
488 "millisPerMinute", 60000,
490 c$.cachedLocaleData = c$.prototype.cachedLocaleData = new java.util.Hashtable (3);
491 c$.cachedNumberFormatData = c$.prototype.cachedNumberFormatData = new java.util.Hashtable (3);
492 Clazz.defineStatics (c$,
493 "PATTERN_INDEX_TO_CALENDAR_FIELD", Clazz.newIntArray (-1, [0, 1, 2, 5, 11, 11, 12, 13, 14, 7, 6, 8, 3, 4, 9, 10, 10, 15, 15]),
494 "PATTERN_INDEX_TO_DATE_FORMAT_FIELD", Clazz.newIntArray (-1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 17]));
495 c$.PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID = c$.prototype.PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID = Clazz.newArray (-1, [java.text.DateFormat.Field.ERA, java.text.DateFormat.Field.YEAR, java.text.DateFormat.Field.MONTH, java.text.DateFormat.Field.DAY_OF_MONTH, java.text.DateFormat.Field.HOUR_OF_DAY1, java.text.DateFormat.Field.HOUR_OF_DAY0, java.text.DateFormat.Field.MINUTE, java.text.DateFormat.Field.SECOND, java.text.DateFormat.Field.MILLISECOND, java.text.DateFormat.Field.DAY_OF_WEEK, java.text.DateFormat.Field.DAY_OF_YEAR, java.text.DateFormat.Field.DAY_OF_WEEK_IN_MONTH, java.text.DateFormat.Field.WEEK_OF_YEAR, java.text.DateFormat.Field.WEEK_OF_MONTH, java.text.DateFormat.Field.AM_PM, java.text.DateFormat.Field.HOUR1, java.text.DateFormat.Field.HOUR0, java.text.DateFormat.Field.TIME_ZONE, java.text.DateFormat.Field.TIME_ZONE]);