/** * Obtains a {@code MutableDateTime} set to the current system millisecond time * using <code>ISOChronology</code> in the default time zone. * * @return the current date-time, not null * @since 2.0 */ public static MutableDateTime now() { return new MutableDateTime(); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
private void fillEmptyTimestamps(Map<Long, Map<String, Number>> results) { final long minTimestamp = Collections.min(results.keySet()); final long maxTimestamp = Collections.max(results.keySet()); final MutableDateTime currentTime = new MutableDateTime(minTimestamp, DateTimeZone.UTC); while (currentTime.getMillis() < maxTimestamp) { final Map<String, Number> entry = results.get(currentTime.getMillis()); // advance timestamp by the interval currentTime.add(interval.getPeriod()); if (entry == null) { // synthesize a 0 value for this timestamp results.put(currentTime.getMillis(), EMPTY_RESULT); } } }
/** * Add a number of years to the date. * * @param years the years to add * @throws IllegalArgumentException if the value is invalid */ public void addYears(final int years) { if (years != 0) { setMillis(getChronology().years().add(getMillis(), years)); } }
/** * Add a number of weeks to the date. * * @param weeks the weeks to add * @throws IllegalArgumentException if the value is invalid */ public void addWeeks(final int weeks) { if (weeks != 0) { setMillis(getChronology().weeks().add(getMillis(), weeks)); } }
/** * Set the millis of the day to the specified value. * <p> * Setting this will replace the values of milli-of-second, second-of-minute, minute-of-hour and hour-of-day. * * @param millisOfDay the millis of day * @throws IllegalArgumentException if the value is invalid */ public void setMillisOfDay(final int millisOfDay) { setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay)); }
private void updateDateTime(Date date, Integer hours, Integer minutes) { if(date!=null) { MutableDateTime datetime = new MutableDateTime(date); try { TimeZone zone = getClientTimeZone(); if (zone != null) { datetime.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { datetime.set(DateTimeFieldType.hourOfDay(), hours % 24); datetime.setMinuteOfHour(minutes != null ? minutes : 0); } // the date will be in the server's timezone setDate(datetime.toDate()); //setModelObject(datetime.toDate()); } catch (RuntimeException e) { error(e.getMessage()); invalid(); } } }
zone = DateTimeZone.getDefault(); if (lowerLimit != null) { MutableDateTime mdt = lowerLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); lowerLimit = mdt.toDateTime(); if (upperLimit != null) { MutableDateTime mdt = upperLimit.toMutableDateTime(); mdt.setZoneRetainFields(zone); upperLimit = mdt.toDateTime(); (getBase().withZone(zone), lowerLimit, upperLimit);
/** * Set the time from another instant. * The date part of this object will be unaffected. * * @param instant an instant to copy the time from, date part ignored * @throws IllegalArgumentException if the object is invalid */ public void setTime(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); Chronology instantChrono = DateTimeUtils.getInstantChronology(instant); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(DateTimeZone.UTC, instantMillis); } setTime(instantMillis); }
if (iOffsetParsed && bucket.getOffsetInteger() != null) { int parsedOffset = bucket.getOffsetInteger(); DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset); chrono = chrono.withZone(parsedZone); } else if (bucket.getZone() != null) { chrono = chrono.withZone(bucket.getZone()); MutableDateTime dt = new MutableDateTime(millis, chrono); if (iZone != null) { dt.setZone(iZone);
private void updateDateTime() { final Date date = getDate(); if (date != null) { final MutableDateTime dateTime = new MutableDateTime(date); try { final TimeZone zone = getClientTimeZone(); if (zone != null) { dateTime.setZone(DateTimeZone.forTimeZone(zone)); } setHourAndMinutes(dateTime); // the date will be in the server's timezone setDate(dateTime.toDate()); setModelObject(dateTime.toDate()); } catch (final RuntimeException e) { error(e.getMessage()); invalid(); } } }
/** * Set the month of the year to the specified value. * * @param monthOfYear the month of the year * @throws IllegalArgumentException if the value is invalid */ public void setMonthOfYear(final int monthOfYear) { setMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear)); }
/** * Set the hour of the day to the specified value. * * @param hourOfDay the hour of day * @throws IllegalArgumentException if the value is invalid */ public void setHourOfDay(final int hourOfDay) { setMillis(getChronology().hourOfDay().set(getMillis(), hourOfDay)); }
/** * Set the minute of the hour to the specified value. * * @param minuteOfHour the minute of hour * @throws IllegalArgumentException if the value is invalid */ public void setMinuteOfHour(final int minuteOfHour) { setMillis(getChronology().minuteOfHour().set(getMillis(), minuteOfHour)); }
/** * Add a number of months to the date. * * @param months the months to add * @throws IllegalArgumentException if the value is invalid */ public void addMonths(final int months) { if (months != 0) { setMillis(getChronology().months().add(getMillis(), months)); } }
/** * Set the year to the specified value. * * @param year the year * @throws IllegalArgumentException if the value is invalid */ public void setYear(final int year) { setMillis(getChronology().year().set(getMillis(), year)); }
/** * Get this object as a MutableDateTime using the same chronology but a different zone. * * @param zone time zone to apply, or default if null * @return a MutableDateTime using the same millis */ public MutableDateTime toMutableDateTime(DateTimeZone zone) { Chronology chrono = DateTimeUtils.getChronology(getChronology()); chrono = chrono.withZone(zone); return new MutableDateTime(getMillis(), chrono); }
/** * Set the millis of the second to the specified value. * * @param millisOfSecond the millis of second * @throws IllegalArgumentException if the value is invalid */ public void setMillisOfSecond(final int millisOfSecond) { setMillis(getChronology().millisOfSecond().set(getMillis(), millisOfSecond)); }
/** * Set the week of weekyear to the specified value. * * @param weekOfWeekyear the week of the weekyear * @throws IllegalArgumentException if the value is invalid */ public void setWeekOfWeekyear(final int weekOfWeekyear) { setMillis(getChronology().weekOfWeekyear().set(getMillis(), weekOfWeekyear)); }
/** * Add a number of days to the date. * * @param days the days to add * @throws IllegalArgumentException if the value is invalid */ public void addDays(final int days) { if (days != 0) { setMillis(getChronology().days().add(getMillis(), days)); } }