Subversion Repositories XServices

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
83 brianR 1
/*
2
 *   Copyright 2012 Brian Rosenberger (Brutex Network)
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 net.brutex.xservices.types;
17
 
18
import java.text.SimpleDateFormat;
19
import java.util.Date;
20
import java.util.GregorianCalendar;
21
import java.util.TimeZone;
22
 
23
import javax.xml.bind.annotation.XmlElement;
24
import javax.xml.bind.annotation.XmlType;
25
 
26
import net.brutex.xservices.util.BrutexNamespaces;
27
 
28
 
29
 
30
 
31
/**
32
 * Date object representation with different formats
33
 *
34
 * @author Brian Rosenberger, bru@brutex.de
35
 */
36
@XmlType(name=DateInfoType.XML_NAME, namespace=BrutexNamespaces.WS_XSERVICES,
37
		propOrder={"isoDate","rfcDate", "millis"})
38
public class DateInfoType {
39
 
40
	public static final String XML_NAME="DateInfoType";
41
	private final GregorianCalendar date;
42
	private final TimeZone zone;
43
 
44
	/**
45
	 * Create a new DateInfoType
46
	 * @param date	date/time
47
	 */
48
	public DateInfoType(GregorianCalendar date, TimeZone zone) {
49
		this.date = date;
50
		this.zone = zone;
51
	}
52
 
53
	/**
54
	 * Create a new DateInfoType with current date/time
55
	 */
56
	public DateInfoType() {
57
		this.zone = TimeZone.getDefault();
58
		this.date = new GregorianCalendar(zone);
59
	}
60
 
61
	/**
62
	 * @return milliseconds since 01.01.1970
63
	 */
64
	@XmlElement(name="timestamp")
65
	public long getMillis() {
66
		return date.getTimeInMillis();
67
	}
68
 
69
 
70
	/**
71
	 * Get date formated according to ISO8601 (done by jaxb->xsd:datetime conversion)
72
	 * @return date
73
	 */
74
	@XmlElement(name="iso8601date")
75
	public Date getIsoDate() {
76
		//String format = DateFormatType.ISO8601.format();
77
		//SimpleDateFormat f = new SimpleDateFormat(format);
78
		//String text = f.format(date.getTime());
79
		//Fix missing colon in java timezone
80
		//return text.substring(0, 22) + ":" + text.substring(22);
81
		return date.getTime();
82
	}
83
 
84
	/**
85
	 * Get date formated according to RFC822 (also java standard)
86
	 * @return date string
87
	 */
88
	@XmlElement(name="rfc822date")
89
	public String getRfcDate() {
90
		return DateFormatType.RFC822.format(date.getTime(), null, null);
91
 
92
	}
93
 
94
 
95
 
96
}