added DateService.dateAdd operation: Add or substract a time span from a date.

git-svn-id: https://brutex.net/svn/xservices/trunk@68 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2011-05-25 18:55:28 +00:00
parent c72e7a9ae6
commit 258118899c
2 changed files with 41 additions and 1 deletions

View File

@ -54,10 +54,12 @@ public interface DateService {
public static final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced"; public static final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
public static final String OPERATION_DATETIMEDIFF = "dateTimeDiff"; public static final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
public static final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2"; public static final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
public static final String OPERATION_DATEADD = "dateAdd";
public static final String PARAM_TIMEZONE = "timezone"; public static final String PARAM_TIMEZONE = "timezone";
public static final String PARAM_DATETIME = "datetime"; public static final String PARAM_DATETIME = "datetime";
public static final String PARAM_FORMAT = "format"; public static final String PARAM_FORMAT = "format";
public static final String PARAM_UNIT = "unit";
/** /**
* Get current date and time. * Get current date and time.
@ -142,5 +144,21 @@ public interface DateService {
public abstract BigInteger dateTimeDiff2( public abstract BigInteger dateTimeDiff2(
@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal, @WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal, @WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal,
@WebParam(name="unit") DateTimeUnits unit) throws XServicesFault; @WebParam(name="PARAM_UNIT") DateTimeUnits unit) throws XServicesFault;
/**
* Add or substract a time span from a date.
*
* @param cal
* @param unit
* @return New date and time.
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_DATEADD)
@WSDLDocumentation(value="Add or substract a time span from a date.")
public abstract GregorianCalendar dateAdd(
@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
@WebParam(name="value") @XmlElement(required=true) BigInteger value,
@WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
} }

View File

@ -149,6 +149,28 @@ public class DateServiceImpl implements DateService {
return d; return d;
} }
@Override
public GregorianCalendar dateAdd(GregorianCalendar cal, BigInteger value, DateTimeUnits unit)
throws XServicesFault {
switch (unit) {
case SECONDS:
cal.add(GregorianCalendar.SECOND, value.intValue());
break;
case MINUTES:
cal.add(GregorianCalendar.MINUTE, value.intValue());
break;
case HOURS:
cal.add(GregorianCalendar.HOUR_OF_DAY, value.intValue());
break;
case DAYS:
cal.add(GregorianCalendar.DAY_OF_MONTH, value.intValue());
break;
default:
cal.add(GregorianCalendar.MILLISECOND, value.intValue());
}
return cal;
}
private boolean isValidTimezone(String id) { private boolean isValidTimezone(String id) {
boolean yes = false; boolean yes = false;
for( String s: TimeZone.getAvailableIDs()) { for( String s: TimeZone.getAvailableIDs()) {