From 258118899c23effd0e7286796880f59e842a1d1f Mon Sep 17 00:00:00 2001 From: Brian Rosenberger Date: Wed, 25 May 2011 18:55:28 +0000 Subject: [PATCH] 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 --- .../net/brutex/xservices/ws/DateService.java | 20 ++++++++++++++++- .../xservices/ws/impl/DateServiceImpl.java | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/java/net/brutex/xservices/ws/DateService.java b/src/java/net/brutex/xservices/ws/DateService.java index dbf7119..b7f355e 100644 --- a/src/java/net/brutex/xservices/ws/DateService.java +++ b/src/java/net/brutex/xservices/ws/DateService.java @@ -54,10 +54,12 @@ public interface DateService { public static final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced"; public static final String OPERATION_DATETIMEDIFF = "dateTimeDiff"; 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_DATETIME = "datetime"; public static final String PARAM_FORMAT = "format"; + public static final String PARAM_UNIT = "unit"; /** * Get current date and time. @@ -142,5 +144,21 @@ public interface DateService { public abstract BigInteger dateTimeDiff2( @WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal, @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; + } diff --git a/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java index 276e389..bb4769c 100644 --- a/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java @@ -149,6 +149,28 @@ public class DateServiceImpl implements DateService { 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) { boolean yes = false; for( String s: TimeZone.getAvailableIDs()) {