/** * Returns the fractional second value as a float. */ public float getFractSecond() { float fractionOfSec = 0; if (tm != null) { fractionOfSec = tm.getFractSecond(); } //end if return fractionOfSec; } //end method
/** * Returns the GMT offset value as an integer. */ public int getGMTOffset() { int offSet = 0; if (tm != null) { offSet = tm.getGMTOffset(); } //end if return offSet; } //end method
/** * Returns the hour as an integer. */ public int getHour() { int hour = 0; if (tm != null) { hour = tm.getHour(); } //end if return hour; } //end method
/** * Convenience setter which sets the value using a {@link Calendar} object. Passing in <code>null</code> clears any existing value. * * Note: Sets fields using precision up to the minute * * @param theCalendar The calendar object from which to retrieve values * @since 1.1 */ public void setValueToMinute(Calendar theCalendar) throws DataTypeException { if (theCalendar == null) { setValue((String)null); return; } int hr = theCalendar.get(Calendar.HOUR_OF_DAY); int min = theCalendar.get(Calendar.MINUTE); setHourMinutePrecision(hr, min); }
/** * Convenience setter which sets the value using a {@link Calendar} object. Passing in <code>null</code> clears any existing value. * * Note: Sets fields using precision up to the second * * @param theCalendar The calendar object from which to retrieve values * @since 1.1 */ public void setValueToSecond(Calendar theCalendar) throws DataTypeException { if (theCalendar == null) { setValue((String)null); return; } int hr = theCalendar.get(Calendar.HOUR_OF_DAY); int min = theCalendar.get(Calendar.MINUTE); int sec = theCalendar.get(Calendar.SECOND); setHourMinSecondPrecision(hr, min, sec); }
/** * <p>Return the value as a calendar object.</p> * * <b>Note that only the time component of the return value is set to * the value from this object. Returned value will have today's date</b> * @since 1.1 */ public Calendar getValueAsCalendar() { int gmtOff = getGMTOffset(); Calendar retVal; if (gmtOff != GMT_OFFSET_NOT_SET_VALUE && !omitOffsetFg) { int hrOffset = gmtOff / 100; int minOffset = Math.abs(gmtOff % 100); String timeZone = String.format("GMT%+d:%02d", hrOffset, minOffset); retVal = new GregorianCalendar(TimeZone.getTimeZone(timeZone)); } else { retVal = Calendar.getInstance(); } retVal.set(Calendar.HOUR_OF_DAY, getHour()); retVal.set(Calendar.MINUTE, getMinute()); retVal.set(Calendar.SECOND, getSecond()); float fractSecond = getFractSecond(); retVal.set(Calendar.MILLISECOND, (int) Math.round(fractSecond * 1000.0)); return retVal; }
CommonTM tm = new CommonTM(); tm.setHourMinSecondPrecision(calHour, calMin, calSecFloat); tm.setOffset(calOffset); val = tm.getValue();
/** * Convenience setter which sets the value using a {@link Calendar} object. Passing in <code>null</code> clears any existing value. * * Note: Sets fields using precision up to the millisecond, including timezone offset * * @param theCalendar The calendar object from which to retrieve values * @since 1.1 */ public void setValue(Calendar theCalendar) throws DataTypeException { if (theCalendar == null) { setValue((String)null); return; } int hr = theCalendar.get(Calendar.HOUR_OF_DAY); int min = theCalendar.get(Calendar.MINUTE); float sec = theCalendar.get(Calendar.SECOND) + (theCalendar.get(Calendar.MILLISECOND) / 1000.0F); setHourMinSecondPrecision(hr, min, sec); // 3410095: care for integer overflow and timezones not at the full hour, e.g. India int hourOffset= theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60); int minuteOffset = (theCalendar.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60; int zoneOffset = hourOffset * 100 + minuteOffset; setOffset(zoneOffset); }
/** * This method takes in the four digit (signed) GMT offset and sets the offset * field */ public void setOffset(int signedOffset) throws DataTypeException { try { //create new time object is there isn't one if (tm == null) { tm = new CommonTM(); } //set the offset value of the time object to the input value tm.setOffset(signedOffset); } catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException(e); } //end catch } //end method
/** * This method takes in integer values for the year, month, day, hour * and minute and performs validations, it then sets the value in the object * formatted as an HL7 Time Stamp value with year&month&day&hour&minute precision (YYYYMMDDHHMM). */ public void setDateMinutePrecision(int yr, int mnth, int dy, int hr, int min) throws DataTypeException { try { //set the value of the date object to the input date value this.setDatePrecision(yr, mnth, dy); //create new time object is there isn't one if (tm == null) { tm = new CommonTM(); } //set the value of the time object to the minute precision with the input values tm.setHourMinutePrecision(hr, min); } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException(e); } //end catch } //end method
/** * This method takes in integer values for the year, month, day, hour, minute, seconds, * and fractional seconds (going to the tenthousandths precision). * The method performs validations and then sets the value in the object formatted as an * HL7 time value with a precision that starts from the year and goes down to the tenthousandths * of a second (YYYYMMDDHHMMSS.SSSS). * The Gmt Offset will not be effected. * Note: all of the precisions from tenths down to * tenthousandths of a second are optional. If the precision goes below tenthousandths * of a second then the second value will be rounded to the nearest tenthousandths of a second. */ public void setDateSecondPrecision(int yr, int mnth, int dy, int hr, int min, float sec) throws DataTypeException { try { //set the value of the date object to the input date value this.setDatePrecision(yr, mnth, dy); //create new time object is there isn't one if (tm == null) { tm = new CommonTM(); } //set the value of the time object to the second precision with the input values tm.setHourMinSecondPrecision(hr, min, sec); } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException(e); } //end catch } //end method
if (tm.getValue() != null && !tm.getValue().equals("")) { if (tm.getValue().equals("\"\"") && dt.getValue().equals("\"\"")) { value = value + tm.getValue(); if (tm.getValue() == null || tm.getValue().equals("")) { int offset = tm.getGMTOffset(); String offsetStr = ""; if (offset != CommonTM.GMT_OFFSET_NOT_SET_VALUE) { offsetStr = DataTypeUtil.preAppendZeroes(Math.abs(offset), 4); if (tm.getGMTOffset() >= 0) { offsetStr = "+" + offsetStr;
/** * @see CommonTM#setHourMinutePrecision(int, int) * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until * this method is called. */ public void setHourMinutePrecision(int hr, int min) throws DataTypeException { getDetail().setHourMinutePrecision(hr,min); }
/** * Returns the second as an integer. */ public int getSecond() { int seconds = 0; if (tm != null) { seconds = tm.getSecond(); } //end if return seconds; } //end method
/** * <p>Return the value as a date object</p> * * <b>Note that only the time component of the return value is set to * the value from this object. Returned value will have today's date</b> * Note: Date is timezone-agnostic, representing always GMT time * @since 1.1 */ public Date getValueAsDate() { return getValueAsCalendar().getTime(); }
/** * Returns the minute as an integer. */ public int getMinute() { int minute = 0; if (tm != null) { minute = tm.getMinute(); } //end if return minute; } //end method
/** * @see CommonTM#setHourMinSecondPrecision(int, int, float) * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until * this method is called. */ public void setHourMinSecondPrecision(int hr, int min, float sec) throws DataTypeException { getDetail().setHourMinSecondPrecision(hr,min,sec); }
/** * @see AbstractPrimitive#getValue */ public String getValue() { String result = super.getValue(); if (myDetail != null) { result = myDetail.getValue(); } return result; }
private CommonTM getDetail() throws DataTypeException { if (myDetail == null) { myDetail = new CommonTM(getValue()); } return myDetail; }