OSDN Git Service

396a580cfa692e94f74c6ed029106f354e67d6b8
[mikumikustudio/MikuMikuStudio.git] / src / com / jmex / xml / types / SchemaDateTime.java
1 /**
2  * SchemaDateTime.java
3  *
4  * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
5  *
6  * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
7  * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
8  *
9  * Refer to the XMLSpy Documentation for further details.
10  * http://www.altova.com/xmlspy
11  */
12
13
14 package com.jmex.xml.types;
15
16 import java.util.Calendar;
17
18
19 public class SchemaDateTime extends SchemaCalendarBase {
20
21   // construction
22   public SchemaDateTime() {
23     setEmpty();
24   }
25
26   public SchemaDateTime(SchemaDateTime newvalue) {
27     year = newvalue.year;
28     month = newvalue.month;
29     day = newvalue.day;
30     hour = newvalue.hour;
31     minute = newvalue.minute;
32     second = newvalue.second;
33     partsecond = newvalue.partsecond;
34     hasTZ = newvalue.hasTZ;
35     offsetTZ = newvalue.offsetTZ;
36
37     isempty = newvalue.isempty;
38   }
39
40   public SchemaDateTime(int newyear, int newmonth, int newday, int newhour, int newminute, int newsecond, double newpartsecond, int newoffsetTZ) {
41     setInternalValues( newyear, newmonth, newday, newhour, newminute, newsecond, newpartsecond, SchemaCalendarBase.TZ_OFFSET, newoffsetTZ);
42     isempty = false;
43   }
44
45   public SchemaDateTime(int newyear, int newmonth, int newday, int newhour, int newminute, int newsecond, double newpartsecond) {
46     setInternalValues( newyear, newmonth, newday, newhour, newminute, newsecond, newpartsecond, SchemaCalendarBase.TZ_MISSING, 0);
47     isempty = false;
48   }
49
50   public SchemaDateTime(Calendar newvalue) {
51     setValue( newvalue );
52   }
53
54   public SchemaDateTime(String newvalue) {
55     parse(newvalue);
56   }
57
58   public SchemaDateTime(SchemaType newvalue) {
59     assign( newvalue );
60   }
61
62   public SchemaDateTime(SchemaTypeCalendar newvalue) {
63     assign( (SchemaType)newvalue );
64   }
65
66   // getValue, setValue
67   public int getYear() {
68     return year;
69   }
70
71   public int getMonth() {
72     return month;
73   }
74
75   public int getDay() {
76     return day;
77   }
78
79   public int getHour() {
80     return hour;
81   }
82
83   public int getMinute() {
84     return minute;
85   }
86
87   public int getSecond() {
88     return second;
89   }
90
91   public double getPartSecond() {
92     return partsecond;
93   }
94
95   public int getMillisecond() {
96     return (int)java.lang.Math.round(partsecond*1000);
97   }
98
99   public int hasTimezone() {
100     return hasTZ;
101   }
102
103   public int getTimezoneOffset() {
104     if( hasTZ != TZ_OFFSET )
105       return 0;
106     return offsetTZ;
107   }
108
109   public Calendar getValue() {
110     Calendar cal = Calendar.getInstance();
111     cal.set( year, month-1, day, hour, minute, second);
112     cal.set( Calendar.MILLISECOND, getMillisecond() );
113     hasTZ = TZ_OFFSET; // necessary, because Calendar object always has timezone.
114         cal.set(Calendar.ZONE_OFFSET, offsetTZ * 60000);
115     //cal.setTimeZone( (TimeZone)new SimpleTimeZone(offsetTZ * 60000, "") );
116     return cal;
117   }
118
119   public void setYear(int newyear) {
120     year = newyear;
121     isempty = false;
122   }
123
124   public void setMonth(int newmonth) {
125     month = newmonth;
126     isempty = false;
127   }
128
129   public void setDay(int newday) {
130     day = newday;
131     isempty = false;
132   }
133
134   public void setHour(int newhour) {
135     hour = newhour;
136     isempty = false;
137   }
138
139   public void setMinute(int newminute) {
140     minute = newminute;
141     isempty = false;
142   }
143
144   public void setSecond(int newsecond) {
145     second = newsecond;
146     isempty = false;
147   }
148
149   public void setPartSecond(double newpartsecond) {
150     partsecond = newpartsecond;
151     isempty = false;
152   }
153
154   public void setMillisecond(int newmillisecond) {
155     partsecond = (double)newmillisecond / 1000;
156     isempty = false;
157   }
158
159   public void setTimezone(int newhasTZ, int newoffsetTZminutes ) {
160     hasTZ = newhasTZ;
161     offsetTZ = newoffsetTZminutes;
162     isempty = false;
163   }
164
165   public void setValue(Calendar newvalue) {
166     if( newvalue == null ) {
167       setEmpty();
168       return;
169     }
170     year = newvalue.get( Calendar.YEAR );
171     month = newvalue.get( Calendar.MONTH ) + 1;
172     day = newvalue.get( Calendar.DAY_OF_MONTH );
173     hour = newvalue.get( Calendar.HOUR_OF_DAY );
174     minute = newvalue.get( Calendar.MINUTE );
175     second = newvalue.get( Calendar.SECOND );
176     setMillisecond( newvalue.get( Calendar.MILLISECOND ) );
177     hasTZ = TZ_MISSING;
178     isempty = false;
179   }
180
181   public void parse(String s) {
182           
183         String newvalue = SchemaNormalizedString.normalize(SchemaNormalizedString.WHITESPACE_COLLAPSE, s);
184
185     if( newvalue == null  || newvalue.length() == 0)
186       setEmpty();
187     else if (!parseDateTime(newvalue, DateTimePart_Date | DateTimePart_Time))
188       throw new StringParseException(newvalue + " cannot be converted to a dateTime value", 0);
189   }
190
191   public void assign(SchemaType newvalue) {
192     if( newvalue == null || newvalue.isNull() || newvalue.isEmpty())
193       setEmpty();
194     else if( newvalue instanceof SchemaDateTime ) {
195       setInternalValues( ((SchemaDateTime)newvalue).year, ((SchemaDateTime)newvalue).month, ((SchemaDateTime)newvalue).day, ((SchemaDateTime)newvalue).hour, ((SchemaDateTime)newvalue).minute, ((SchemaDateTime)newvalue).second, ((SchemaDateTime)newvalue).partsecond, ((SchemaDateTime)newvalue).hasTZ, ((SchemaDateTime)newvalue).offsetTZ);
196       isempty = false;
197     }
198     else if( newvalue instanceof SchemaDate ) {
199       setInternalValues( ((SchemaDate)newvalue).year, ((SchemaDate)newvalue).month, ((SchemaDate)newvalue).day, 0, 0, 0, 0.0, SchemaCalendarBase.TZ_MISSING, 0);
200       isempty = false;
201     }
202     else if( newvalue instanceof SchemaString )
203       parse( newvalue.toString() );
204     else
205       throw new TypesIncompatibleException( newvalue, this );
206   }
207
208   // further
209   public Object clone() {
210     return new SchemaDateTime( this );
211   }
212
213   public String toString() {
214     if( isempty)
215       return "";
216     StringBuffer s = new StringBuffer();
217     s.append( toDateString() );
218     s.append("T");
219     s.append( toTimeString() );
220     return s.toString();
221   }
222
223   public static SchemaDateTime now() {
224     return new SchemaDateTime(Calendar.getInstance());
225   }
226
227   // ---------- interface SchemaTypeCalendar ----------
228   public int calendarType() {
229     return CALENDAR_VALUE_DATETIME;
230   }
231
232   public SchemaDateTime dateTimeValue() {
233     return new SchemaDateTime( this );
234   }
235
236   public SchemaDate dateValue() {
237     return new SchemaDate( this );
238   }
239
240   public SchemaTime timeValue() {
241       return new SchemaTime( this  ); //        result.hasTZ = hasTZ;
242   }
243 }