KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > chrono > GJDayOfWeekDateTimeField


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time.chrono;
17
18 import java.util.Locale JavaDoc;
19
20 import org.joda.time.DateTimeConstants;
21 import org.joda.time.DateTimeFieldType;
22 import org.joda.time.DurationField;
23 import org.joda.time.field.PreciseDurationDateTimeField;
24
25 /**
26  * GJDayOfWeekDateTimeField provides time calculations for the
27  * day of the week component of time.
28  *
29  * @since 1.0
30  * @author Guy Allard
31  * @author Stephen Colebourne
32  * @author Brian S O'Neill
33  */

34 final class GJDayOfWeekDateTimeField extends PreciseDurationDateTimeField {
35     
36     /** Serialization version */
37     private static final long serialVersionUID = -3857947176719041436L;
38
39     private final BasicChronology iChronology;
40
41     /**
42      * Restricted constructor.
43      */

44     GJDayOfWeekDateTimeField(BasicChronology chronology, DurationField days) {
45         super(DateTimeFieldType.dayOfWeek(), days);
46         iChronology = chronology;
47     }
48
49     /**
50      * Get the value of the specified time instant.
51      *
52      * @param instant the time instant in millis to query
53      * @return the day of the week extracted from the input
54      */

55     public int get(long instant) {
56         return iChronology.getDayOfWeek(instant);
57     }
58
59     /**
60      * Get the textual value of the specified time instant.
61      *
62      * @param fieldValue the field value to query
63      * @param locale the locale to use
64      * @return the day of the week, such as 'Monday'
65      */

66     public String JavaDoc getAsText(int fieldValue, Locale JavaDoc locale) {
67         return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToText(fieldValue);
68     }
69
70     /**
71      * Get the abbreviated textual value of the specified time instant.
72      *
73      * @param fieldValue the field value to query
74      * @param locale the locale to use
75      * @return the day of the week, such as 'Mon'
76      */

77     public String JavaDoc getAsShortText(int fieldValue, Locale JavaDoc locale) {
78         return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToShortText(fieldValue);
79     }
80
81     /**
82      * Convert the specified text and locale into a value.
83      *
84      * @param text the text to convert
85      * @param locale the locale to convert using
86      * @return the value extracted from the text
87      * @throws IllegalArgumentException if the text is invalid
88      */

89     protected int convertText(String JavaDoc text, Locale JavaDoc locale) {
90         return GJLocaleSymbols.forLocale(locale).dayOfWeekTextToValue(text);
91     }
92
93     public DurationField getRangeDurationField() {
94         return iChronology.weeks();
95     }
96
97     /**
98      * Get the minimum value that this field can have.
99      *
100      * @return the field's minimum value
101      */

102     public int getMinimumValue() {
103         return DateTimeConstants.MONDAY;
104     }
105
106     /**
107      * Get the maximum value that this field can have.
108      *
109      * @return the field's maximum value
110      */

111     public int getMaximumValue() {
112         return DateTimeConstants.SUNDAY;
113     }
114
115     /**
116      * Get the maximum length of the text returned by this field.
117      *
118      * @param locale the locale to use
119      * @return the maximum textual length
120      */

121     public int getMaximumTextLength(Locale JavaDoc locale) {
122         return GJLocaleSymbols.forLocale(locale).getDayOfWeekMaxTextLength();
123     }
124
125     /**
126      * Get the maximum length of the abbreviated text returned by this field.
127      *
128      * @param locale the locale to use
129      * @return the maximum abbreviated textual length
130      */

131     public int getMaximumShortTextLength(Locale JavaDoc locale) {
132         return GJLocaleSymbols.forLocale(locale).getDayOfWeekMaxShortTextLength();
133     }
134
135     /**
136      * Serialization singleton
137      */

138     private Object JavaDoc readResolve() {
139         return iChronology.dayOfWeek();
140     }
141 }
142
Popular Tags