/** * Returns the day as an integer. */ public int getDay() { int day = 0; if (dt != null) { day = dt.getDay(); } //end if return day; } //end method
/** * Returns the month as an integer. */ public int getMonth() { int month = 0; if (dt != null) { month = dt.getMonth(); } //end if return month; } //end method
/** * Return the value as a date object * @since 1.1 */ public Date getValueAsDate() { return getValueAsCalendar().getTime(); }
/** * Return the value as a calendar object * @since 1.1 */ public Calendar getValueAsCalendar() { Calendar retVal = Calendar.getInstance(); retVal.set(Calendar.DATE, getDay()); retVal.set(Calendar.MONTH, getMonth() - 1); retVal.set(Calendar.YEAR, getYear()); // Truncate retVal.set(Calendar.HOUR_OF_DAY, 0); retVal.set(Calendar.MINUTE, 0); retVal.set(Calendar.SECOND, 0); retVal.set(Calendar.MILLISECOND, 0); return retVal; }
/** * Returns a string value representing the input Gregorian Calendar object in * an Hl7 Date Format. */ public static String toHl7DTFormat(GregorianCalendar cal) throws DataTypeException { String val = ""; try { //set the input cal object so that it can report errors //on it's value cal.setLenient(false); int calYear = cal.get(GregorianCalendar.YEAR); int calMonth = cal.get(GregorianCalendar.MONTH) + 1; int calDay = cal.get(GregorianCalendar.DAY_OF_MONTH); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.getValue(); } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException( e ); } //end catch return val; } //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 maximum possible precision * * @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 yr = theCalendar.get(Calendar.YEAR); int mnth = theCalendar.get(Calendar.MONTH) + 1; int dy = theCalendar.get(Calendar.DATE); setYearMonthDayPrecision(yr, mnth, dy); }
/** * This method takes in integer values for the year and month and day * and performs validations, it then sets the value in the object * formatted as an HL7 Time Stamp value with year&month&day precision (YYYYMMDD). * */ public void setDatePrecision(int yr, int mnth, int dy) throws DataTypeException { try { //create date object if there isn't one if (dt == null) { dt = new CommonDT(); } //set the value of the date object to the input date value dt.setYearMonthDayPrecision(yr, mnth, dy); //clear the time value object tm = null; } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException(e); } //end catch } //end method
/** * Constructs a DT object with the given value. * The stored value will be in the following * format YYYY[MM[DD]]. */ public CommonDT(String val) throws DataTypeException { this.setValue(val); } //end constructor
/** * Returns the year as an integer. */ public int getYear() { int year = 0; if (dt != null) { year = dt.getYear(); } //end if return year; } //end method
/** * @see AbstractPrimitive#getValue */ public String getValue() { String result = super.getValue(); if (myDetail != null) { result = myDetail.getValue(); } return result; }
/** * @see CommonDT#setYearMonthDayPrecision(int, 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 setYearMonthDayPrecision(int yr, int mnth, int dy) throws DataTypeException { getDetail().setYearMonthDayPrecision(yr,mnth,dy); }
/** * @see CommonDT#setYearPrecision(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 setYearPrecision(int yr) throws DataTypeException { getDetail().setYearPrecision(yr); }
/** * @see CommonDT#setYearMonthPrecision(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 setYearMonthPrecision(int yr, int mnth) throws DataTypeException { getDetail().setYearMonthPrecision(yr,mnth); }
private CommonDT getDetail() throws DataTypeException { if (myDetail == null) { myDetail = new CommonDT(getValue()); } return myDetail; }
/** * Return the value as a calendar object * @since 1.1 */ public Calendar getValueAsCalendar() { Calendar retVal = Calendar.getInstance(); retVal.set(Calendar.DATE, getDay()); retVal.set(Calendar.MONTH, getMonth() - 1); retVal.set(Calendar.YEAR, getYear()); // Truncate retVal.set(Calendar.HOUR_OF_DAY, 0); retVal.set(Calendar.MINUTE, 0); retVal.set(Calendar.SECOND, 0); retVal.set(Calendar.MILLISECOND, 0); return retVal; }
/** * Returns a string value representing the input Gregorian Calendar object in * an Hl7 Date Format. */ public static String toHl7DTFormat(GregorianCalendar cal) throws DataTypeException { String val = ""; try { //set the input cal object so that it can report errors //on it's value cal.setLenient(false); int calYear = cal.get(GregorianCalendar.YEAR); int calMonth = cal.get(GregorianCalendar.MONTH) + 1; int calDay = cal.get(GregorianCalendar.DAY_OF_MONTH); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.getValue(); } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException( e ); } //end catch return val; } //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 maximum possible precision * * @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 yr = theCalendar.get(Calendar.YEAR); int mnth = theCalendar.get(Calendar.MONTH) + 1; int dy = theCalendar.get(Calendar.DATE); setYearMonthDayPrecision(yr, mnth, dy); }
/** * This method takes in integer values for the year and month and day * and performs validations, it then sets the value in the object * formatted as an HL7 Time Stamp value with year&month&day precision (YYYYMMDD). * */ public void setDatePrecision(int yr, int mnth, int dy) throws DataTypeException { try { //create date object if there isn't one if (dt == null) { dt = new CommonDT(); } //set the value of the date object to the input date value dt.setYearMonthDayPrecision(yr, mnth, dy); //clear the time value object tm = null; } //end try catch (DataTypeException e) { throw e; } //end catch catch (Exception e) { throw new DataTypeException(e); } //end catch } //end method