JAL-1807 update
[jalviewjs.git] / site / j2s / java / text / DateFormat.js
1 Clazz.declarePackage ("java.text");
2 Clazz.load (["java.text.Format", "java.util.HashMap"], "java.text.DateFormat", ["java.io.InvalidObjectException", "java.lang.IllegalArgumentException", "$.Number", "$.StringBuffer", "java.util.Date", "java.text.DontCareFieldPosition", "$.ParseException", "$.ParsePosition", "java.util.Locale"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.calendar = null;
5 this.numberFormat = null;
6 Clazz.instantialize (this, arguments);
7 }, java.text, "DateFormat", java.text.Format);
8 Clazz.defineMethod (c$, "format", 
9 function (obj, toAppendTo, fieldPosition) {
10 if (Clazz.instanceOf (obj, java.util.Date)) return this.format (obj, toAppendTo, fieldPosition);
11  else if (Clazz.instanceOf (obj, Number)) return this.format ( new java.util.Date ((obj).longValue ()), toAppendTo, fieldPosition);
12  else throw  new IllegalArgumentException ("Cannot format given Object as a Date");
13 }, "~O,StringBuffer,java.text.FieldPosition");
14 Clazz.defineMethod (c$, "format", 
15 function (date) {
16 return this.format (date,  new StringBuffer (), java.text.DontCareFieldPosition.INSTANCE).toString ();
17 }, "java.util.Date");
18 Clazz.defineMethod (c$, "parse", 
19 function (source) {
20 var pos =  new java.text.ParsePosition (0);
21 var result = this.parse (source, pos);
22 if (pos.index == 0) throw  new java.text.ParseException ("Unparseable date: \"" + source + "\"", pos.errorIndex);
23 return result;
24 }, "~S");
25 Clazz.defineMethod (c$, "parseObject", 
26 function (source, pos) {
27 return this.parse (source, pos);
28 }, "~S,java.text.ParsePosition");
29 c$.getTimeInstance = Clazz.defineMethod (c$, "getTimeInstance", 
30 function () {
31 return java.text.DateFormat.get (2, 0, 1, java.util.Locale.getDefault ());
32 });
33 c$.getTimeInstance = Clazz.defineMethod (c$, "getTimeInstance", 
34 function (style) {
35 return java.text.DateFormat.get (style, 0, 1, java.util.Locale.getDefault ());
36 }, "~N");
37 c$.getTimeInstance = Clazz.defineMethod (c$, "getTimeInstance", 
38 function (style, aLocale) {
39 return java.text.DateFormat.get (style, 0, 1, aLocale);
40 }, "~N,java.util.Locale");
41 c$.getDateInstance = Clazz.defineMethod (c$, "getDateInstance", 
42 function () {
43 return java.text.DateFormat.get (0, 2, 2, java.util.Locale.getDefault ());
44 });
45 c$.getDateInstance = Clazz.defineMethod (c$, "getDateInstance", 
46 function (style) {
47 return java.text.DateFormat.get (0, style, 2, java.util.Locale.getDefault ());
48 }, "~N");
49 c$.getDateInstance = Clazz.defineMethod (c$, "getDateInstance", 
50 function (style, aLocale) {
51 return java.text.DateFormat.get (0, style, 2, aLocale);
52 }, "~N,java.util.Locale");
53 c$.getDateTimeInstance = Clazz.defineMethod (c$, "getDateTimeInstance", 
54 function () {
55 return java.text.DateFormat.get (2, 2, 3, java.util.Locale.getDefault ());
56 });
57 c$.getDateTimeInstance = Clazz.defineMethod (c$, "getDateTimeInstance", 
58 function (dateStyle, timeStyle) {
59 return java.text.DateFormat.get (timeStyle, dateStyle, 3, java.util.Locale.getDefault ());
60 }, "~N,~N");
61 c$.getDateTimeInstance = Clazz.defineMethod (c$, "getDateTimeInstance", 
62 function (dateStyle, timeStyle, aLocale) {
63 return java.text.DateFormat.get (timeStyle, dateStyle, 3, aLocale);
64 }, "~N,~N,java.util.Locale");
65 c$.getInstance = Clazz.defineMethod (c$, "getInstance", 
66 function () {
67 return java.text.DateFormat.getDateTimeInstance (3, 3);
68 });
69 Clazz.defineMethod (c$, "setCalendar", 
70 function (newCalendar) {
71 this.calendar = newCalendar;
72 }, "java.util.Calendar");
73 Clazz.defineMethod (c$, "getCalendar", 
74 function () {
75 return this.calendar;
76 });
77 Clazz.defineMethod (c$, "setNumberFormat", 
78 function (newNumberFormat) {
79 this.numberFormat = newNumberFormat;
80 }, "java.text.NumberFormat");
81 Clazz.defineMethod (c$, "getNumberFormat", 
82 function () {
83 return this.numberFormat;
84 });
85 Clazz.defineMethod (c$, "setTimeZone", 
86 function (zone) {
87 this.calendar.setTimeZone (zone);
88 }, "java.util.TimeZone");
89 Clazz.defineMethod (c$, "getTimeZone", 
90 function () {
91 return this.calendar.getTimeZone ();
92 });
93 Clazz.defineMethod (c$, "setLenient", 
94 function (lenient) {
95 this.calendar.setLenient (lenient);
96 }, "~B");
97 Clazz.defineMethod (c$, "isLenient", 
98 function () {
99 return this.calendar.isLenient ();
100 });
101 Clazz.overrideMethod (c$, "hashCode", 
102 function () {
103 return this.numberFormat.hashCode ();
104 });
105 Clazz.defineMethod (c$, "equals", 
106 function (obj) {
107 if (this === obj) return true;
108 if (obj == null || this.getClass () !== obj.getClass ()) return false;
109 var other = obj;
110 return (this.calendar.getFirstDayOfWeek () == other.calendar.getFirstDayOfWeek () && this.calendar.getMinimalDaysInFirstWeek () == other.calendar.getMinimalDaysInFirstWeek () && this.calendar.isLenient () == other.calendar.isLenient () && this.calendar.getTimeZone ().equals (other.calendar.getTimeZone ()) && this.numberFormat.equals (other.numberFormat));
111 }, "~O");
112 Clazz.defineMethod (c$, "clone", 
113 function () {
114 var other = Clazz.superCall (this, java.text.DateFormat, "clone", []);
115 other.calendar = this.calendar.clone ();
116 other.numberFormat = this.numberFormat.clone ();
117 return other;
118 });
119 c$.get = Clazz.defineMethod (c$, "get", 
120  function (timeStyle, dateStyle, flags, loc) {
121 if ((flags & 1) != 0) {
122 if (timeStyle < 0 || timeStyle > 3) {
123 throw  new IllegalArgumentException ("Illegal time style " + timeStyle);
124 }} else {
125 timeStyle = -1;
126 }if ((flags & 2) != 0) {
127 if (dateStyle < 0 || dateStyle > 3) {
128 throw  new IllegalArgumentException ("Illegal date style " + dateStyle);
129 }} else {
130 dateStyle = -1;
131 }try {
132 return  new java.text.SimpleDateFormat (timeStyle, dateStyle, loc);
133 } catch (e) {
134 if (Clazz.exceptionOf (e, java.util.MissingResourceException)) {
135 return  new java.text.SimpleDateFormat ("M/d/yy h:mm a");
136 } else {
137 throw e;
138 }
139 }
140 }, "~N,~N,~N,java.util.Locale");
141 Clazz.makeConstructor (c$, 
142 function () {
143 Clazz.superConstructor (this, java.text.DateFormat, []);
144 });
145 Clazz.pu$h(self.c$);
146 c$ = Clazz.decorateAsClass (function () {
147 this.calendarField = 0;
148 Clazz.instantialize (this, arguments);
149 }, java.text.DateFormat, "Field", java.text.Format.Field);
150 c$.ofCalendarField = Clazz.defineMethod (c$, "ofCalendarField", 
151 function (a) {
152 if (a < 0 || a >= java.text.DateFormat.Field.calendarToFieldMapping.length) {
153 throw  new IllegalArgumentException ("Unknown Calendar constant " + a);
154 }return java.text.DateFormat.Field.calendarToFieldMapping[a];
155 }, "~N");
156 Clazz.makeConstructor (c$, 
157 function (a, b) {
158 Clazz.superConstructor (this, java.text.DateFormat.Field, [a]);
159 this.calendarField = b;
160 if (this.getClass () === java.text.DateFormat.Field) {
161 java.text.DateFormat.Field.$instanceMap.put (a, this);
162 if (b >= 0) {
163 java.text.DateFormat.Field.calendarToFieldMapping[b] = this;
164 }}}, "~S,~N");
165 Clazz.defineMethod (c$, "getCalendarField", 
166 function () {
167 return this.calendarField;
168 });
169 Clazz.overrideMethod (c$, "readResolve", 
170 function () {
171 if (this.getClass () !== java.text.DateFormat.Field) {
172 throw  new java.io.InvalidObjectException ("subclass didn't correctly implement readResolve");
173 }var a = java.text.DateFormat.Field.$instanceMap.get (this.getName ());
174 if (a != null) {
175 return a;
176 } else {
177 throw  new java.io.InvalidObjectException ("unknown attribute name");
178 }});
179 c$.$instanceMap = c$.prototype.$instanceMap =  new java.util.HashMap (18);
180 c$.calendarToFieldMapping = c$.prototype.calendarToFieldMapping =  new Array (17);
181 c$.ERA = c$.prototype.ERA =  new java.text.DateFormat.Field ("era", 0);
182 c$.YEAR = c$.prototype.YEAR =  new java.text.DateFormat.Field ("year", 1);
183 c$.MONTH = c$.prototype.MONTH =  new java.text.DateFormat.Field ("month", 2);
184 c$.DAY_OF_MONTH = c$.prototype.DAY_OF_MONTH =  new java.text.DateFormat.Field ("day of month", 5);
185 c$.HOUR_OF_DAY1 = c$.prototype.HOUR_OF_DAY1 =  new java.text.DateFormat.Field ("hour of day 1", -1);
186 c$.HOUR_OF_DAY0 = c$.prototype.HOUR_OF_DAY0 =  new java.text.DateFormat.Field ("hour of day", 11);
187 c$.MINUTE = c$.prototype.MINUTE =  new java.text.DateFormat.Field ("minute", 12);
188 c$.SECOND = c$.prototype.SECOND =  new java.text.DateFormat.Field ("second", 13);
189 c$.MILLISECOND = c$.prototype.MILLISECOND =  new java.text.DateFormat.Field ("millisecond", 14);
190 c$.DAY_OF_WEEK = c$.prototype.DAY_OF_WEEK =  new java.text.DateFormat.Field ("day of week", 7);
191 c$.DAY_OF_YEAR = c$.prototype.DAY_OF_YEAR =  new java.text.DateFormat.Field ("day of year", 6);
192 c$.DAY_OF_WEEK_IN_MONTH = c$.prototype.DAY_OF_WEEK_IN_MONTH =  new java.text.DateFormat.Field ("day of week in month", 8);
193 c$.WEEK_OF_YEAR = c$.prototype.WEEK_OF_YEAR =  new java.text.DateFormat.Field ("week of year", 3);
194 c$.WEEK_OF_MONTH = c$.prototype.WEEK_OF_MONTH =  new java.text.DateFormat.Field ("week of month", 4);
195 c$.AM_PM = c$.prototype.AM_PM =  new java.text.DateFormat.Field ("am pm", 9);
196 c$.HOUR1 = c$.prototype.HOUR1 =  new java.text.DateFormat.Field ("hour 1", -1);
197 c$.HOUR0 = c$.prototype.HOUR0 =  new java.text.DateFormat.Field ("hour", 10);
198 c$.TIME_ZONE = c$.prototype.TIME_ZONE =  new java.text.DateFormat.Field ("time zone", -1);
199 c$ = Clazz.p0p ();
200 Clazz.defineStatics (c$,
201 "ERA_FIELD", 0,
202 "YEAR_FIELD", 1,
203 "MONTH_FIELD", 2,
204 "DATE_FIELD", 3,
205 "HOUR_OF_DAY1_FIELD", 4,
206 "HOUR_OF_DAY0_FIELD", 5,
207 "MINUTE_FIELD", 6,
208 "SECOND_FIELD", 7,
209 "MILLISECOND_FIELD", 8,
210 "DAY_OF_WEEK_FIELD", 9,
211 "DAY_OF_YEAR_FIELD", 10,
212 "DAY_OF_WEEK_IN_MONTH_FIELD", 11,
213 "WEEK_OF_YEAR_FIELD", 12,
214 "WEEK_OF_MONTH_FIELD", 13,
215 "AM_PM_FIELD", 14,
216 "HOUR1_FIELD", 15,
217 "HOUR0_FIELD", 16,
218 "TIMEZONE_FIELD", 17,
219 "FULL", 0,
220 "LONG", 1,
221 "MEDIUM", 2,
222 "SHORT", 3,
223 "DEFAULT", 2);
224 });