/** * Converts this object to an Interval representing the whole day. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); return toDateMidnight(zone).toInterval(); }
/** * Get this object as a DateTime, returning <code>this</code> if possible. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); if (getZone() == zone) { return this; } return super.toDateTime(zone); }
/** * Converts this object to an Interval representing the whole day. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); return toDateMidnight(zone).toInterval(); }
/** * Get this object as a DateTime, returning <code>this</code> if possible. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); if (getZone() == zone) { return this; } return super.toDateTime(zone); }
/** * Returns a copy of this date with a different time zone, preserving the day * The returned object will have a local time of midnight in the new zone on * the same day as the original instant. * * @param newZone the new time zone, null means default * @return a copy of this instant with a different time zone */ public DateMidnight withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateMidnight(millis, getChronology().withZone(newZone)); }
/** * Returns a copy of this date with a different time zone, preserving the day * The returned object will have a local time of midnight in the new zone on * the same day as the original instant. * * @param newZone the new time zone, null means default * @return a copy of this instant with a different time zone */ public DateMidnight withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateMidnight(millis, getChronology().withZone(newZone)); }
/** * Converts this LocalDate to a full datetime at midnight using the * specified time zone. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This method uses the chronology from this instance plus the time zone * specified. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to use, null means default zone * @return this date as a datetime at midnight * @deprecated Use {@link #toDateTimeAtStartOfDay(DateTimeZone)} which won't throw an exception */ @Deprecated public DateTime toDateTimeAtMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateTime(getYear(), getMonthOfYear(), getDayOfMonth(), 0, 0, 0, 0, chrono); }
/** * Converts this LocalDate to a full datetime using the specified time zone * setting the date fields from this instance and the time fields from * the current time. * <p> * This method uses the chronology from this instance plus the time zone * specified. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to use, null means default zone * @return this date as a datetime with the time as the current time */ public DateTime toDateTimeAtCurrentTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); long instantMillis = DateTimeUtils.currentTimeMillis(); long resolved = chrono.set(this, instantMillis); return new DateTime(resolved, chrono); }
/** * Converts this LocalDate to a full datetime using the specified time zone * setting the date fields from this instance and the time fields from * the current time. * <p> * This method uses the chronology from this instance plus the time zone * specified. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to use, null means default zone * @return this date as a datetime with the time as the current time */ public DateTime toDateTimeAtCurrentTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); long instantMillis = DateTimeUtils.currentTimeMillis(); long resolved = chrono.set(this, instantMillis); return new DateTime(resolved, chrono); }
/** * 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); }
/** * Converts this object to an Interval representing the whole day. * <p> * The interval may have more or less than 24 hours if this is a daylight * savings cutover date. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toDateTimeAtStartOfDay(zone); DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this object to an Interval representing the whole day. * <p> * The interval may have more or less than 24 hours if this is a daylight * savings cutover date. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toDateTimeAtStartOfDay(zone); DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * 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); }
/** * Sets the time zone of the datetime, changing the chronology and field values. * <p> * Changing the zone using this method retains the millisecond instant. * The millisecond instant is adjusted in the new zone to compensate. * * chronology. Setting the time zone does not affect the millisecond value * of this instant. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZoneRetainFields */ public void setZone(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); Chronology chrono = getChronology(); if (chrono.getZone() != newZone) { setChronology(chrono.withZone(newZone)); // set via this class not super } }
/** * Sets the time zone of the datetime, changing the chronology and field values. * <p> * Changing the zone using this method retains the millisecond instant. * The millisecond instant is adjusted in the new zone to compensate. * * chronology. Setting the time zone does not affect the millisecond value * of this instant. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZoneRetainFields */ public void setZone(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); Chronology chrono = getChronology(); if (chrono.getZone() != newZone) { setChronology(chrono.withZone(newZone)); // set via this class not super } }
/** * Converts this LocalDate to a DateMidnight. * <p> * As from v1.5, you are recommended to avoid DateMidnight and use * {@link #toDateTimeAtStartOfDay()} instead because of the exception * detailed below. * <p> * This method will throw an exception if the time zone switches * to Daylight Savings Time at midnight and this LocalDate represents * that switchover date. The problem is that there is no such time as * midnight on the required date, and as such an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the DateMidnight in, null means default zone * @return the DateMidnight instance * @deprecated DateMidnight is deprecated */ @Deprecated public DateMidnight toDateMidnight(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = getChronology().withZone(zone); return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono); }
/** * Converts this object to an Interval representing the whole month. * <p> * The interval will use the chronology of the year-month in the specified zone. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return an interval over the month, never null */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toLocalDate(1).toDateTimeAtStartOfDay(zone); DateTime end = plusMonths(1).toLocalDate(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this object to an Interval representing the whole month. * <p> * The interval will use the chronology of the year-month in the specified zone. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return an interval over the month, never null */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toLocalDate(1).toDateTimeAtStartOfDay(zone); DateTime end = plusMonths(1).toLocalDate(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this object to a DateTime using the specified zone. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }
/** * Converts this object to a DateTime using the specified zone. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); Chronology chrono = iChronology.withZone(zone); return new DateTime( getYear(), getMonthOfYear(), getDayOfMonth(), getHourOfDay(), getMinuteOfHour(), getSecondOfMinute(), getMillisOfSecond(), chrono); }