private Integer getFieldValue(int theField) { if (getValue() == null) { return null; } Calendar cal = getValueAsCalendar(); return cal.get(theField); }
/** * Returns <code>true</code> if this object represents a date that is today's date * * @throws NullPointerException * if {@link #getValue()} returns <code>null</code> */ public boolean isToday() { Validate.notNull(getValue(), getClass().getSimpleName() + " contains null value"); return DateUtils.isSameDay(new Date(), getValue()); }
/** * Returns the value of this object as a {@link GregorianCalendar} */ public GregorianCalendar getValueAsCalendar() { if (getValue() == null) { return null; } GregorianCalendar cal; if (getTimeZone() != null) { cal = new GregorianCalendar(getTimeZone()); } else { cal = new GregorianCalendar(); } cal.setTime(getValue()); return cal; }
private void setFieldValue(int theField, int theValue, String theFractionalSeconds, int theMinimum, int theMaximum) { validateValueInRange(theValue, theMinimum, theMaximum); Calendar cal; if (getValue() == null) { cal = new GregorianCalendar(0, 0, 0); } else { cal = getValueAsCalendar(); } if (theField != -1) { cal.set(theField, theValue); } if (theFractionalSeconds != null) { myFractionalSeconds = theFractionalSeconds; } else if (theField == Calendar.MILLISECOND) { myFractionalSeconds = StringUtils.leftPad(Integer.toString(theValue), 3, '0'); } super.setValue(cal.getTime()); }
/** * Returns a human readable version of this date/time using the system local format, converted to the local timezone * if neccesary. * * @see #toHumanDisplay() for a method which does not convert the time to the local timezone before rendering it. */ public String toHumanDisplayLocalTimezone() { switch (getPrecision()) { case YEAR: case MONTH: case DAY: return ourHumanDateFormat.format(getValue()); case MILLI: case SECOND: default: return ourHumanDateTimeFormat.format(getValue()); } }
private Integer getFieldValue(int theField) { if (getValue() == null) { return null; } Calendar cal = getValueAsCalendar(); return cal.get(theField); }
/** * Returns a human readable version of this date/time using the system local format. * <p> * <b>Note on time zones:</b> This method renders the value using the time zone that is contained within the value. * For example, if this date object contains the value "2012-01-05T12:00:00-08:00", * the human display will be rendered as "12:00:00" even if the application is being executed on a system in a * different time zone. If this behaviour is not what you want, use * {@link #toHumanDisplayLocalTimezone()} instead. * </p> */ public String toHumanDisplay() { TimeZone tz = getTimeZone(); Calendar value = tz != null ? Calendar.getInstance(tz) : Calendar.getInstance(); value.setTime(getValue()); switch (getPrecision()) { case YEAR: case MONTH: case DAY: return ourHumanDateFormat.format(value); case MILLI: case SECOND: default: return ourHumanDateTimeFormat.format(value); } }
private void setFieldValue(int theField, int theValue, String theFractionalSeconds, int theMinimum, int theMaximum) { validateValueInRange(theValue, theMinimum, theMaximum); Calendar cal; if (getValue() == null) { cal = new GregorianCalendar(0, 0, 0); } else { cal = getValueAsCalendar(); } if (theField != -1) { cal.set(theField, theValue); } if (theFractionalSeconds != null) { myFractionalSeconds = theFractionalSeconds; } else if (theField == Calendar.MILLISECOND) { myFractionalSeconds = StringUtils.leftPad(Integer.toString(theValue), 3, '0'); } super.setValue(cal.getTime()); }
/** * Create a new DateTimeDt using an existing value. <b>Use this constructor with caution</b>, * as it may create more precision than warranted (since for example it is possible to pass in * a DateTime with only a year, and this constructor will convert to an InstantDt with * milliseconds precision). */ public InstantDt(BaseDateTimeDt theDateTime) { // Do not call super(foo) here, we don't want to trigger a DataFormatException setValue(theDateTime.getValue()); setPrecision(DEFAULT_PRECISION); setTimeZone(theDateTime.getTimeZone()); }
/** * Returns <code>true</code> if this object represents a date that is today's date * * @throws NullPointerException * if {@link #getValue()} returns <code>null</code> */ public boolean isToday() { Validate.notNull(getValue(), getClass().getSimpleName() + " contains null value"); return DateUtils.isSameDay(new Date(), getValue()); }
/** * Returns the value of this object as a {@link GregorianCalendar} */ public GregorianCalendar getValueAsCalendar() { if (getValue() == null) { return null; } GregorianCalendar cal; if (getTimeZone() != null) { cal = new GregorianCalendar(getTimeZone()); } else { cal = new GregorianCalendar(); } cal.setTime(getValue()); return cal; }
/** * Returns a human readable version of this date/time using the system local format, converted to the local timezone * if neccesary. * * @see #toHumanDisplay() for a method which does not convert the time to the local timezone before rendering it. */ public String toHumanDisplayLocalTimezone() { switch (getPrecision()) { case YEAR: case MONTH: case DAY: return ourHumanDateFormat.format(getValue()); case MILLI: case SECOND: default: return ourHumanDateTimeFormat.format(getValue()); } }
/** * Returns a human readable version of this date/time using the system local format. * <p> * <b>Note on time zones:</b> This method renders the value using the time zone that is contained within the value. * For example, if this date object contains the value "2012-01-05T12:00:00-08:00", * the human display will be rendered as "12:00:00" even if the application is being executed on a system in a * different time zone. If this behaviour is not what you want, use * {@link #toHumanDisplayLocalTimezone()} instead. * </p> */ public String toHumanDisplay() { TimeZone tz = getTimeZone(); Calendar value = tz != null ? Calendar.getInstance(tz) : Calendar.getInstance(); value.setTime(getValue()); switch (getPrecision()) { case YEAR: case MONTH: case DAY: return ourHumanDateFormat.format(value); case MILLI: case SECOND: default: return ourHumanDateTimeFormat.format(value); } }
/** * Create a new DateTimeDt using an existing value. <b>Use this constructor with caution</b>, * as it may create more precision than warranted (since for example it is possible to pass in * a DateTime with only a year, and this constructor will convert to an InstantDt with * milliseconds precision). */ public InstantDt(BaseDateTimeDt theDateTime) { // Do not call super(foo) here, we don't want to trigger a DataFormatException setValue(theDateTime.getValue()); setPrecision(DEFAULT_PRECISION); setTimeZone(theDateTime.getTimeZone()); }