// parses a datetime string that adhears to the given pattern and returns a java.util.Date object public static java.util.Calendar parse(String input, String pattern) throws IllegalArgumentException { if (pattern == null) pattern = DEFAULT_DATETIME_PATTERN; java.util.Calendar output = null; if (input != null) { if (pattern.equals("datetime")) { output = javax.xml.bind.DatatypeConverter.parseDateTime(input); } else if (pattern.equals("date")) { output = javax.xml.bind.DatatypeConverter.parseDate(input); } else if (pattern.equals("time")) { output = javax.xml.bind.DatatypeConverter.parseTime(input); } else if (pattern.equals("milliseconds")) { output = java.util.Calendar.getInstance(); output.setTimeInMillis(Long.parseLong(input)); } else { java.text.DateFormat formatter = new java.text.SimpleDateFormat(pattern); formatter.setLenient(false); output = java.util.Calendar.getInstance(); try { output.setTime(formatter.parse(input)); } catch (java.text.ParseException ex) { throw new IllegalArgumentException(tundra.exception.message(ex)); } } } return output; }
public static final void getTimeZoneOffsetFromGMT(IData pipeline) throws ServiceException { // --- <<IS-START(getTimeZoneOffsetFromGMT)>> --- // @subtype unknown // @sigtype java 3.5 // [i] field:0:required inTimeZone // [o] field:0:required outOffset // pipeline IDataCursor pipelineCursor = pipeline.getCursor(); String inTimeZone = IDataUtil.getString(pipelineCursor, "inTimeZone"); pipelineCursor.destroy(); java.util.TimeZone inTZ = java.util.TimeZone.getTimeZone(inTimeZone); java.util.Calendar inCalendar = new java.util.GregorianCalendar(inTZ); int offset = inCalendar.get(java.util.Calendar.ZONE_OFFSET) + inCalendar.get(java.util.Calendar.DST_OFFSET); // pipeline IDataCursor pipelineCursor_1 = pipeline.getCursor(); IDataUtil.put(pipelineCursor_1, "outOffset", String.valueOf(offset)); pipelineCursor_1.destroy(); // --- <<IS-END>> --- }
// compares two datetimes public static int compare(java.util.Calendar cx, java.util.Calendar cy) { if (cx == null && cy == null) return 0; if (cx == null && cy != null) return -1; if (cx != null && cy == null) return 1; return cx.compareTo(cy); }
// adds the given xml duration to the given xml datetime returning the result public static java.util.Calendar add( java.util.Calendar calendar, javax.xml.datatype.Duration duration) { if (calendar == null || duration == null) return calendar; java.util.Calendar clone = (java.util.Calendar) calendar.clone(); duration.addTo(clone); return clone; }
// returns the given datetime formatted as a string adhering to the given pattern public static String emit(java.util.Calendar input, String pattern) { if (pattern == null) pattern = DEFAULT_DATETIME_PATTERN; String output = null; if (input != null) { if (pattern.equals("datetime")) { output = javax.xml.bind.DatatypeConverter.printDateTime(input); } else if (pattern.equals("date")) { output = javax.xml.bind.DatatypeConverter.printDate(input); } else if (pattern.equals("time")) { output = javax.xml.bind.DatatypeConverter.printTime(input); } else if (pattern.equals("milliseconds")) { output = "" + input.getTimeInMillis(); } else { java.text.DateFormat formatter = new java.text.SimpleDateFormat(pattern); formatter.setLenient(false); output = formatter.format(input.getTime()); } } return output; }
// returns the current datetime as an xml datetime string public static String now() { return emit(java.util.Calendar.getInstance()); }
// returns the xml duration between two given xml datetimes public static javax.xml.datatype.Duration duration( java.util.Calendar start, java.util.Calendar end) { if (start == null || end == null) return null; return tundra.duration.parse( "" + (end.getTimeInMillis() - start.getTimeInMillis()), "milliseconds"); }
// adds two dates together public static java.util.Calendar concatenate(java.util.Calendar date, java.util.Calendar time) { java.util.Calendar localDateTime = new java.util.GregorianCalendar(); localDateTime.setTimeInMillis(date.getTimeInMillis() + time.getTimeInMillis()); return localDateTime; }