Subversion Repositories XServices

Rev

Rev 70 | Rev 83 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
66 brianR 1
/*
2
 *   Copyright 2011 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
 
17
package net.brutex.xservices.ws;
18
 
19
import java.math.BigInteger;
20
import java.util.GregorianCalendar;
21
 
22
import javax.jws.WebMethod;
23
import javax.jws.WebParam;
24
import javax.jws.WebService;
25
import javax.xml.bind.annotation.XmlElement;
26
 
27
import net.brutex.xservices.types.DateFormatType;
28
import net.brutex.xservices.types.DateTimeUnits;
29
import net.brutex.xservices.util.BrutexNamespaces;
30
 
31
import org.apache.cxf.annotations.WSDLDocumentation;
32
import org.apache.cxf.annotations.WSDLDocumentationCollection;
33
 
34
/**
35
 * Date and time related services.
36
 * @author Brian Rosenberger
37
 *
38
 */
39
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
40
@WSDLDocumentationCollection(
41
    {
42
    	@WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
43
    }
44
)
45
public interface DateService {
46
 
47
	public static final String SERVICE_NAME = "DateService";
69 brianR 48
	final String OPERATION_GETDATE = "getDate";
49
	final String OPERATION_GETTIMESTAMP = "getTimestamp";
71 brianR 50
	final String OPERATION_GETTIMESTAMP2 = "getTimestamp2";
69 brianR 51
	final String OPERATION_GETINTIMEZONE = "getInTimezone";
52
	final String OPERATION_FORMATDATE = "formatDate";
53
	final String OPERATION_FORMATDATEADVANCED = "formatDateAdvanced";
54
	final String OPERATION_PARSEDATE = "parseDate";
55
	final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
56
	final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
57
	final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
58
	final String OPERATION_DATEADD = "dateAdd";
66 brianR 59
 
69 brianR 60
	final String PARAM_TIMEZONE = "timezone";
61
	final String PARAM_DATETIME = "datetime";
62
	final String PARAM_FORMAT = "format";
63
	final String PARAM_UNIT = "unit";
66 brianR 64
 
65
	/**
66
	 * Get current date and time.
67
	 *
68
	 * @param timezone Optional timezone. Defaults to server timezone.
69
	 * @return Current date and time.
70
	 * @throws XServicesFault
71
	 */
72
	@WebMethod(operationName=OPERATION_GETDATE)
73
	@WSDLDocumentation(value="Get current date and time.")
74
	public abstract GregorianCalendar getDate(
75
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
76
 
77
	/**
78
	 * Get milliseconds since 01.01.1970.
79
	 *
80
	 * @return timestamp milliseconds
81
	 */
82
	@WebMethod(operationName=OPERATION_GETTIMESTAMP)
83
	@WSDLDocumentation(value="Get milliseconds since 01.01.1970 (Unix timestap).")
84
	public abstract BigInteger getTimestamp();
71 brianR 85
 
86
	/**
87
	 * Get seconds since 01.01.1970.
88
	 *
89
	 * @return timestamp seconds
90
	 */
91
	@WebMethod(operationName=OPERATION_GETTIMESTAMP2)
92
	@WSDLDocumentation(value="Get seconds since 01.01.1970 (Unix timestap).")
93
	public abstract BigInteger getTimestamp2();
66 brianR 94
 
95
	/**
96
	 * Display a date time with a different time zone.
97
	 * Changes representation only (no conversion).
98
	 *
99
	 * @param cal date time.
100
	 * @param timezone time zone
101
	 * @return date time
102
	 * @throws XServicesFault
103
	 */
104
	@WebMethod(operationName=OPERATION_GETINTIMEZONE)
105
	public abstract GregorianCalendar getInTimezone(
106
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
107
			@WebParam(name=PARAM_TIMEZONE) @XmlElement(required=true) String timezone) throws XServicesFault;
108
 
109
	/**
69 brianR 110
	 * Formats a date with pre-defined patterns.
111
	 *
112
	 * @param cal date time to be formatted
113
	 * @param format Pattern to be used for date formating
66 brianR 114
	 * @return formatted date/time string
115
	 * @throws XServicesFault
116
	 */
117
	@WebMethod(operationName=OPERATION_FORMATDATE)
118
	public abstract String formatDate(
119
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
120
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format) throws XServicesFault;
121
 
69 brianR 122
	/**
123
	 * Formats a date with a free form pattern.
124
	 * Uses SimpleDateFormat patterns
125
	 * The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
126
 
127
    Letter	Date or Time Component	Presentation	Examples
128
    G	Era designator	Text	AD
129
    y	Year	Year	1996; 96
130
    M	Month in year	Month	July; Jul; 07
131
    w	Week in year	Number	27
132
    W	Week in month	Number	2
133
    D	Day in year	Number	189
134
    d	Day in month	Number	10
135
    F	Day of week in month	Number	2
136
    E	Day in week	Text	Tuesday; Tue
137
    a	Am/pm marker	Text	PM
138
    H	Hour in day (0-23)	Number	0
139
    k	Hour in day (1-24)	Number	24
140
    K	Hour in am/pm (0-11)	Number	0
141
    h	Hour in am/pm (1-12)	Number	12
142
    m	Minute in hour	Number	30
143
    s	Second in minute	Number	55
144
    S	Millisecond	Number	978
145
    z	Time zone	General time zone	Pacific Standard Time; PST; GMT-08:00
146
    Z	Time zone	RFC 822 time zone	-0800
147
	 * @param cal Date time to be formatted
148
	 * @param format Format string
149
	 * @return Date time formatted according to format string
150
	 * @throws XServicesFault
151
	 */
66 brianR 152
	@WebMethod(operationName=OPERATION_FORMATDATEADVANCED)
153
	public abstract String formatDateAdvanced(
154
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
155
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format) throws XServicesFault;
156
 
70 brianR 157
	/**
158
	 * Converts a string into date using pre-defined date formats.
159
	 *
160
	 * @param s Date/ time as string
161
	 * @param format date format
162
	 * @param timezone timezone
163
	 * @return XML Date
164
	 * @throws XServicesFault
165
	 */
66 brianR 166
	@WebMethod(operationName=OPERATION_PARSEDATE)
167
	public abstract GregorianCalendar parseDate(
168
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
169
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format,
170
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
171
 
70 brianR 172
	/**
173
	 * Converts a string into date using any format.
174
	 * @param s date/ time as string
175
	 * @param format date format
176
	 * @param timezone timezone
177
	 * @return XML Date
178
	 * @throws XServicesFault
179
	 */
66 brianR 180
	@WebMethod(operationName=OPERATION_PARSEDATEADVANCED)
181
	public abstract GregorianCalendar parseDateAdvanced(
182
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
183
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format,
184
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
185
 
69 brianR 186
	/**
187
	 * Calculate elapsed time between two dates.
188
	 * @param fromCal First date.
189
	 * @param toCal Second date.
190
	 * @return Elapsed time in milliseconds
191
	 * @throws XServicesFault
192
	 */
66 brianR 193
	@WebMethod(operationName=OPERATION_DATETIMEDIFF)
194
	public abstract BigInteger dateTimeDiff(
195
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
196
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal) throws XServicesFault;
197
 
198
	/**
199
	 * Fully elapsed units between two dates.
200
	 * 4:15:10-4:15:55 in minutes = 0 and in seconds = 45
201
	 *
202
	 * @param fromCal
203
	 * @param toCal
204
	 * @param unit
205
	 * @return Date/time difference in unit
206
	 * @throws XServicesFault
207
	 */
208
	@WebMethod(operationName=OPERATION_DATETIMEDIFF2)
209
	@WSDLDocumentation(value="Get elapsed time between to dates.")
210
	public abstract BigInteger dateTimeDiff2(
211
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
212
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal,
68 brianR 213
			@WebParam(name="PARAM_UNIT") DateTimeUnits unit) throws XServicesFault;
214
 
215
	/**
69 brianR 216
	 * Add or subtract a time span from a date.
68 brianR 217
	 *
69 brianR 218
	 * @param cal The initial date.
219
	 * @param value The amount to add.
220
	 * @param unit The unit the amount is defined in.
68 brianR 221
	 * @return New date and time.
222
	 * @throws XServicesFault
69 brianR 223
	 *
68 brianR 224
	 */
225
	@WebMethod(operationName=OPERATION_DATEADD)
226
	@WSDLDocumentation(value="Add or substract a time span from a date.")
227
	public abstract GregorianCalendar dateAdd(
228
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
229
			@WebParam(name="value") @XmlElement(required=true) BigInteger value,
230
			@WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
231
 
66 brianR 232
}