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