1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.dateformat;
20
21 /**
22 * A simple object that contains the current parsing state when parsing
23 * a string into a date.
24 * <p>
25 * This encapsulates all the properties of a SimpleDateFormatter which
26 * are modified during the parsing of a specific input string.
27 *
28 * @since 1.1.7
29 */
30 public class ParserContext
31 {
32 /**
33 * Set during various string-parsing operations to indicate the
34 * offset of the next unparsed character.
35 */
36 int newIndex;
37
38 /**
39 * Set during string-parsing operations if a parsing error occurred.
40 * Normally, an error status is also returned from the method.
41 */
42 boolean invalid = false;
43
44 /**
45 * Controls how "weekYear" and "weekOfWeekYear" map to ymd dates.
46 * <p>
47 * Values are 0=sunday, 1=monday, 6=saturday (the java.util.Date
48 * return values for getDay). Note that java.util.Calendar uses
49 * 1=sunday, 2=monday, 7=saturday.
50 * <p>
51 * This value is a mandatory parameter to the constructor of
52 * this class. Normally, callers will pass 1 (the ISO standard).
53 */
54 int firstDayOfWeek;
55
56 /**
57 * Set to true if the input string had a year specifier of less
58 * than 4 digits, meaning we have to guess the century.
59 */
60 boolean ambiguousYear;
61
62 /**
63 * Set to true if the input string had a weekYear specifier of less
64 * than 4 digits, meaning we have to guess the century.
65 */
66 boolean ambiguousWeekYear;
67
68 // --------------------------------------------------
69 // standard properties parsed out of the input string
70 // --------------------------------------------------
71
72 /**
73 * Year is relative to 0AD, unless ambiguousYear is set.
74 */
75 int year;
76
77 /** Month is in range 0..11 */
78 int month;
79
80 /** Day is in range 1..31 */
81 int day = 1;
82
83 /** mon=1, sun=7 */
84 int dayOfWeek;
85
86 /** The hour value used for formatter "H", in range 00-23. */
87 int hour;
88
89 /**
90 * The hour value used for "h" formatter; in range 1..12.
91 * <ul>
92 * <li>00:00 is 12:00 am (this field is 12)
93 * <li>01:00 is 01:00 am (this field is 1)
94 * <li>11:59 is 11:59 am (this field is 11)
95 * <li>12:00 is 12:00 pm (this field is 12)
96 * <li>13:00 is 01:00 pm (this field is 1)
97 * <li>23:59 is 11:59 pm (this field is 11)
98 * </ul>
99 */
100 int hourAmpm;
101
102 /** minutes in range 0-59 */
103 int min;
104
105 /** seconds in range 0-59 */
106 int sec;
107
108 /** 0 = am, 1 = pm (index into ampm strings in symbols class) */
109 int ampm;
110
111 /**
112 * The year in which the weekOfWeekYear value lies.
113 * Note that date yyyy-01-01 may be week 5n of the previous year.
114 */
115 int weekYear;
116
117 /** The week number (1..53). */
118 int weekOfWeekYear;
119
120 public ParserContext(int dow) {
121 firstDayOfWeek = dow;
122 }
123 }