PageRenderTime 143ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ftr-gwt-date-emulation/src/test/java/eu/future/earth/gwt/emul/java/util/Calendar.java

http://ftr-gwt-library.googlecode.com/
Java | 416 lines | 66 code | 55 blank | 295 comment | 0 complexity | 574946f5548a88a790829512f51d8c9d MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. * This class gets copy-and-pasted between the eu.future.earth.gwt.emul.java.util (used for
  3. * development and testing) and com.google.gwt.emul.java.util packages (used for gwt
  4. * compilation). Change the comments on the package declaration appropriately.
  5. */
  6. package eu.future.earth.gwt.emul.java.util;
  7. //package java.util;
  8. import java.util.Date;
  9. public abstract class Calendar implements Cloneable {
  10. protected Calendar(){
  11. super();
  12. }
  13. /**
  14. * Field number for <code>get</code> and <code>set</code> indicating the
  15. * year. This is a calendar-specific value; see subclass documentation.
  16. */
  17. public final static int YEAR = 1;
  18. /**
  19. * Field number for <code>get</code> and <code>set</code> indicating the
  20. * month. This is a calendar-specific value. The first month of
  21. * the year in the Gregorian and Julian calendars is
  22. * <code>JANUARY</code> which is 0; the last depends on the number
  23. * of months in a year.
  24. *
  25. * @see #JANUARY
  26. * @see #FEBRUARY
  27. * @see #MARCH
  28. * @see #APRIL
  29. * @see #MAY
  30. * @see #JUNE
  31. * @see #JULY
  32. * @see #AUGUST
  33. * @see #SEPTEMBER
  34. * @see #OCTOBER
  35. * @see #NOVEMBER
  36. * @see #DECEMBER
  37. * @see #UNDECIMBER
  38. */
  39. public final static int MONTH = 2;
  40. /**
  41. * Field number for <code>get</code> and <code>set</code> indicating the
  42. * week number within the current year. The first week of the year, as
  43. * defined by <code>getFirstDayOfWeek()</code> and
  44. * <code>getMinimalDaysInFirstWeek()</code>, has value 1. Subclasses define
  45. * the value of <code>WEEK_OF_YEAR</code> for days before the first week of
  46. * the year.
  47. *
  48. * @see #getFirstDayOfWeek
  49. * @see #getMinimalDaysInFirstWeek
  50. */
  51. public final static int WEEK_OF_YEAR = 3;
  52. /**
  53. * Field number for <code>get</code> and <code>set</code> indicating the
  54. * week number within the current month. The first week of the month, as
  55. * defined by <code>getFirstDayOfWeek()</code> and
  56. * <code>getMinimalDaysInFirstWeek()</code>, has value 1. Subclasses define
  57. * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
  58. * the month.
  59. *
  60. * @see #getFirstDayOfWeek
  61. * @see #getMinimalDaysInFirstWeek
  62. */
  63. public final static int WEEK_OF_MONTH = 4;
  64. /**
  65. * Field number for <code>get</code> and <code>set</code> indicating the
  66. * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
  67. * The first day of the month has value 1.
  68. *
  69. * @see #DAY_OF_MONTH
  70. */
  71. public final static int DATE = 5;
  72. /**
  73. * Field number for <code>get</code> and <code>set</code> indicating the
  74. * day of the month. This is a synonym for <code>DATE</code>.
  75. * The first day of the month has value 1.
  76. *
  77. * @see #DATE
  78. */
  79. public final static int DAY_OF_MONTH = 5;
  80. /**
  81. * Field number for <code>get</code> and <code>set</code> indicating the day
  82. * number within the current year. The first day of the year has value 1.
  83. */
  84. public final static int DAY_OF_YEAR = 6;
  85. /**
  86. * Field number for <code>get</code> and <code>set</code> indicating the day
  87. * of the week. This field takes values <code>SUNDAY</code>,
  88. * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
  89. * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
  90. *
  91. * @see #SUNDAY
  92. * @see #MONDAY
  93. * @see #TUESDAY
  94. * @see #WEDNESDAY
  95. * @see #THURSDAY
  96. * @see #FRIDAY
  97. * @see #SATURDAY
  98. */
  99. public final static int DAY_OF_WEEK = 7;
  100. /**
  101. * Field number for <code>get</code> and <code>set</code> indicating the
  102. * ordinal number of the day of the week within the current month. Together
  103. * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
  104. * within a month. Unlike <code>WEEK_OF_MONTH</code> and
  105. * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
  106. * <code>getFirstDayOfWeek()</code> or
  107. * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code>
  108. * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
  109. * 1</code>; <code>8</code> through <code>14</code> correspond to
  110. * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
  111. * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
  112. * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the
  113. * end of the month, so the last Sunday of a month is specified as
  114. * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because
  115. * negative values count backward they will usually be aligned differently
  116. * within the month than positive values. For example, if a month has 31
  117. * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
  118. * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
  119. *
  120. * @see #DAY_OF_WEEK
  121. * @see #WEEK_OF_MONTH
  122. */
  123. public final static int DAY_OF_WEEK_IN_MONTH = 8;
  124. /**
  125. * Field number for <code>get</code> and <code>set</code> indicating
  126. * whether the <code>HOUR</code> is before or after noon.
  127. * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
  128. *
  129. * @see #AM
  130. * @see #PM
  131. * @see #HOUR
  132. */
  133. public final static int AM_PM = 9;
  134. /**
  135. * Field number for <code>get</code> and <code>set</code> indicating the
  136. * hour of the morning or afternoon. <code>HOUR</code> is used for the
  137. * 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12.
  138. * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
  139. *
  140. * @see #AM_PM
  141. * @see #HOUR_OF_DAY
  142. */
  143. public final static int HOUR = 10;
  144. /**
  145. * Field number for <code>get</code> and <code>set</code> indicating the
  146. * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
  147. * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
  148. *
  149. * @see #HOUR
  150. */
  151. public final static int HOUR_OF_DAY = 11;
  152. /**
  153. * Field number for <code>get</code> and <code>set</code> indicating the
  154. * minute within the hour.
  155. * E.g., at 10:04:15.250 PM the <code>MINUTE</code> is 4.
  156. */
  157. public final static int MINUTE = 12;
  158. /**
  159. * Field number for <code>get</code> and <code>set</code> indicating the
  160. * second within the minute.
  161. * E.g., at 10:04:15.250 PM the <code>SECOND</code> is 15.
  162. */
  163. public final static int SECOND = 13;
  164. /**
  165. * Field number for <code>get</code> and <code>set</code> indicating the
  166. * millisecond within the second.
  167. * E.g., at 10:04:15.250 PM the <code>MILLISECOND</code> is 250.
  168. */
  169. public final static int MILLISECOND = 14;
  170. /**
  171. * Value of the {@link #DAY_OF_WEEK} field indicating
  172. * Sunday.
  173. */
  174. public final static int SUNDAY = 1;
  175. /**
  176. * Value of the {@link #DAY_OF_WEEK} field indicating
  177. * Monday.
  178. */
  179. public final static int MONDAY = 2;
  180. /**
  181. * Value of the {@link #DAY_OF_WEEK} field indicating
  182. * Tuesday.
  183. */
  184. public final static int TUESDAY = 3;
  185. /**
  186. * Value of the {@link #DAY_OF_WEEK} field indicating
  187. * Wednesday.
  188. */
  189. public final static int WEDNESDAY = 4;
  190. /**
  191. * Value of the {@link #DAY_OF_WEEK} field indicating
  192. * Thursday.
  193. */
  194. public final static int THURSDAY = 5;
  195. /**
  196. * Value of the {@link #DAY_OF_WEEK} field indicating
  197. * Friday.
  198. */
  199. public final static int FRIDAY = 6;
  200. /**
  201. * Value of the {@link #DAY_OF_WEEK} field indicating
  202. * Saturday.
  203. */
  204. public final static int SATURDAY = 7;
  205. /**
  206. * Value of the {@link #MONTH} field indicating the
  207. * first month of the year in the Gregorian and Julian calendars.
  208. */
  209. public final static int JANUARY = 0;
  210. /**
  211. * Value of the {@link #MONTH} field indicating the
  212. * second month of the year in the Gregorian and Julian calendars.
  213. */
  214. public final static int FEBRUARY = 1;
  215. /**
  216. * Value of the {@link #MONTH} field indicating the
  217. * third month of the year in the Gregorian and Julian calendars.
  218. */
  219. public final static int MARCH = 2;
  220. /**
  221. * Value of the {@link #MONTH} field indicating the
  222. * fourth month of the year in the Gregorian and Julian calendars.
  223. */
  224. public final static int APRIL = 3;
  225. /**
  226. * Value of the {@link #MONTH} field indicating the
  227. * fifth month of the year in the Gregorian and Julian calendars.
  228. */
  229. public final static int MAY = 4;
  230. /**
  231. * Value of the {@link #MONTH} field indicating the
  232. * sixth month of the year in the Gregorian and Julian calendars.
  233. */
  234. public final static int JUNE = 5;
  235. /**
  236. * Value of the {@link #MONTH} field indicating the
  237. * seventh month of the year in the Gregorian and Julian calendars.
  238. */
  239. public final static int JULY = 6;
  240. /**
  241. * Value of the {@link #MONTH} field indicating the
  242. * eighth month of the year in the Gregorian and Julian calendars.
  243. */
  244. public final static int AUGUST = 7;
  245. /**
  246. * Value of the {@link #MONTH} field indicating the
  247. * ninth month of the year in the Gregorian and Julian calendars.
  248. */
  249. public final static int SEPTEMBER = 8;
  250. /**
  251. * Value of the {@link #MONTH} field indicating the
  252. * tenth month of the year in the Gregorian and Julian calendars.
  253. */
  254. public final static int OCTOBER = 9;
  255. /**
  256. * Value of the {@link #MONTH} field indicating the
  257. * eleventh month of the year in the Gregorian and Julian calendars.
  258. */
  259. public final static int NOVEMBER = 10;
  260. /**
  261. * Value of the {@link #MONTH} field indicating the
  262. * twelfth month of the year in the Gregorian and Julian calendars.
  263. */
  264. public final static int DECEMBER = 11;
  265. /**
  266. * Value of the {@link #MONTH} field indicating the
  267. * thirteenth month of the year. Although <code>GregorianCalendar</code>
  268. * does not use this value, lunar calendars do.
  269. */
  270. public final static int UNDECIMBER = 12;
  271. /**
  272. * Value of the {@link #AM_PM} field indicating the
  273. * period of the day from midnight to just before noon.
  274. */
  275. public final static int AM = 0;
  276. /**
  277. * Value of the {@link #AM_PM} field indicating the
  278. * period of the day from noon to just before midnight.
  279. */
  280. public final static int PM = 1;
  281. /**
  282. * Returns a <code>Date</code> object representing this
  283. * <code>Calendar</code>'s time value (millisecond offset from the <a
  284. * href="#Epoch">Epoch</a>").
  285. *
  286. * @return a <code>Date</code> representing the time value.
  287. * @see #setTime(Date)
  288. * @see #getTimeInMillis()
  289. */
  290. public abstract Date getTime();
  291. /**
  292. * Sets this Calendar's time with the given <code>Date</code>.
  293. * <p>
  294. * Note: Calling <code>setTime()</code> with
  295. * <code>Date(Long.MAX_VALUE)</code> or <code>Date(Long.MIN_VALUE)</code>
  296. * may yield incorrect field values from <code>get()</code>.
  297. *
  298. * @param date the given Date.
  299. * @see #getTime()
  300. * @see #setTimeInMillis(long)
  301. */
  302. public abstract void setTime(Date date);
  303. /**
  304. * Returns this Calendar's time value in milliseconds.
  305. *
  306. * @return the current time as UTC milliseconds from the epoch.
  307. * @see #getTime()
  308. * @see #setTimeInMillis(long)
  309. */
  310. public abstract long getTimeInMillis();
  311. /**
  312. * Sets this Calendar's current time from the given long value.
  313. *
  314. * @param millis the new time in UTC milliseconds from the epoch.
  315. * @see #setTime(Date)
  316. * @see #getTimeInMillis()
  317. */
  318. public abstract void setTimeInMillis(long millis);
  319. public abstract int get(int field);
  320. /**
  321. * Sets the given calendar field to the given value. The value is not
  322. * interpreted by this method regardless of the leniency mode.
  323. *
  324. * @param field the given calendar field.
  325. * @param value the value to be set for the given calendar field.
  326. * @throws ArrayIndexOutOfBoundsException if the specified field is out of range
  327. * (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
  328. * in non-lenient mode.
  329. * @see #set(int,int,int)
  330. * @see #set(int,int,int,int,int)
  331. * @see #set(int,int,int,int,int,int)
  332. * @see #get(int)
  333. */
  334. public abstract void set(int field, int value);
  335. public abstract void add(int field, int value);
  336. public int getFirstDayOfWeek() {
  337. return firstDayOfWeek;
  338. }
  339. public void setFirstDayOfWeek(int newFirstDayOfWeek) {
  340. this.firstDayOfWeek = newFirstDayOfWeek;
  341. }
  342. public int getMinimalDaysInFirstWeek() {
  343. return minimalDaysInFirstWeek;
  344. }
  345. public void setMinimalDaysInFirstWeek(int newMinimalDaysInFirstWeek) {
  346. this.minimalDaysInFirstWeek = newMinimalDaysInFirstWeek;
  347. }
  348. /**
  349. * The first day of the week, with possible values <code>SUNDAY</code>,
  350. * <code>MONDAY</code>, etc. This is a locale-dependent value.
  351. * @serial
  352. */
  353. private int firstDayOfWeek = SUNDAY;
  354. /**
  355. * The number of days required for the first week in a month or year,
  356. * with possible values from 1 to 7. This is a locale-dependent value.
  357. * @serial
  358. */
  359. private int minimalDaysInFirstWeek = 1;
  360. public abstract Object clone();
  361. }