/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using <code>ISOChronology</code> in the default time zone. * The constructed object will have a local time of midnight. * * @return the current date, not null * @since 2.0 */ public static DateMidnight now() { return new DateMidnight(); }
/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using <code>ISOChronology</code> in the default time zone. * The constructed object will have a local time of midnight. * * @return the current date, not null * @since 2.0 */ public static DateMidnight now() { return new DateMidnight(); }
/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using <code>ISOChronology</code> in the specified time zone. * The constructed object will have a local time of midnight. * * @param zone the time zone, not null * @return the current date, not null * @since 2.0 */ public static DateMidnight now(DateTimeZone zone) { if (zone == null) { throw new NullPointerException("Zone must not be null"); } return new DateMidnight(zone); }
/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using the specified chronology. * The constructed object will have a local time of midnight. * * @param chronology the chronology, not null * @return the current date, not null * @since 2.0 */ public static DateMidnight now(Chronology chronology) { if (chronology == null) { throw new NullPointerException("Chronology must not be null"); } return new DateMidnight(chronology); }
/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using <code>ISOChronology</code> in the specified time zone. * The constructed object will have a local time of midnight. * * @param zone the time zone, not null * @return the current date, not null * @since 2.0 */ public static DateMidnight now(DateTimeZone zone) { if (zone == null) { throw new NullPointerException("Zone must not be null"); } return new DateMidnight(zone); }
/** * Obtains a {@code DateMidnight} set to the current system millisecond time * using the specified chronology. * The constructed object will have a local time of midnight. * * @param chronology the chronology, not null * @return the current date, not null * @since 2.0 */ public static DateMidnight now(Chronology chronology) { if (chronology == null) { throw new NullPointerException("Chronology must not be null"); } return new DateMidnight(chronology); }
/** * Converts this object to a <code>DateMidnight</code> using the * same millis and chronology. * * @return a DateMidnight using the same millis and chronology * @deprecated DateMidnight is deprecated */ @Deprecated public DateMidnight toDateMidnight() { return new DateMidnight(getMillis(), getChronology()); }
/** * Converts this object to a <code>DateMidnight</code> using the * same millis and chronology. * * @return a DateMidnight using the same millis and chronology * @deprecated DateMidnight is deprecated */ @Deprecated public DateMidnight toDateMidnight() { return new DateMidnight(getMillis(), getChronology()); }
// first midnight in this month DateMidnight first = new DateMidnight().withDayOfMonth(1); // last midnight in this month DateMidnight last = first.plusMonths(1).minusDays(1);
/** * Returns a copy of this date with a different chronology, potentially * changing the day in unexpected ways. * <p> * This method creates a new DateMidnight using the midnight millisecond value * and the new chronology. If the same or similar chronology is specified, but * with a different time zone, the day may change. This occurs because the new * DateMidnight rounds down the millisecond value to get to midnight, and the * time zone change may result in a rounding down to a different day. * <p> * For example, changing time zone from London (+00:00) to Paris (+01:00) will * retain the same day, but changing from Paris to London will change the day. * (When its midnight in London its the same day in Paris, but when its midnight * in Paris its still the previous day in London) * <p> * To avoid these unusual effects, use {@link #withZoneRetainFields(DateTimeZone)} * to change time zones. * * @param newChronology the new chronology * @return a copy of this instant with a different chronology */ public DateMidnight withChronology(Chronology newChronology) { return (newChronology == getChronology() ? this : new DateMidnight(getMillis(), newChronology)); }
/** * Returns a copy of this date with a different chronology, potentially * changing the day in unexpected ways. * <p> * This method creates a new DateMidnight using the midnight millisecond value * and the new chronology. If the same or similar chronology is specified, but * with a different time zone, the day may change. This occurs because the new * DateMidnight rounds down the millisecond value to get to midnight, and the * time zone change may result in a rounding down to a different day. * <p> * For example, changing time zone from London (+00:00) to Paris (+01:00) will * retain the same day, but changing from Paris to London will change the day. * (When its midnight in London its the same day in Paris, but when its midnight * in Paris its still the previous day in London) * <p> * To avoid these unusual effects, use {@link #withZoneRetainFields(DateTimeZone)} * to change time zones. * * @param newChronology the new chronology * @return a copy of this instant with a different chronology */ public DateMidnight withChronology(Chronology newChronology) { return (newChronology == getChronology() ? this : new DateMidnight(getMillis(), newChronology)); }
/** * Returns a copy of this date with a different millisecond instant. * The returned object will have a local time of midnight. * <p> * Only the millis will change, the chronology and time zone are kept. * The returned object will be either be a new instance or <code>this</code>. * * @param newMillis the new millis, from 1970-01-01T00:00:00Z * @return a copy of this instant with different millis */ public DateMidnight withMillis(long newMillis) { Chronology chrono = getChronology(); newMillis = checkInstant(newMillis, chrono); return (newMillis == getMillis() ? this : new DateMidnight(newMillis, chrono)); }
/** * Returns a copy of this date with a different millisecond instant. * The returned object will have a local time of midnight. * <p> * Only the millis will change, the chronology and time zone are kept. * The returned object will be either be a new instance or <code>this</code>. * * @param newMillis the new millis, from 1970-01-01T00:00:00Z * @return a copy of this instant with different millis */ public DateMidnight withMillis(long newMillis) { Chronology chrono = getChronology(); newMillis = checkInstant(newMillis, chrono); return (newMillis == getMillis() ? this : new DateMidnight(newMillis, chrono)); }
/** * Converts this object to a DateMidnight. * * @param zone the zone to get the DateMidnight in, null means default * @return the DateMidnight instance */ public DateMidnight toDateMidnight(DateTimeZone zone) { Chronology chrono = getChronology().withZone(zone); return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono); }
/** * Converts this object to a DateMidnight. * * @param zone the zone to get the DateMidnight in, null means default * @return the DateMidnight instance */ public DateMidnight toDateMidnight(DateTimeZone zone) { Chronology chrono = getChronology().withZone(zone); return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono); }
/** * 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 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); }
/** * 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)); }
@Override public DateMidnight deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // We'll accept either long (timestamp) or array: if (jp.isExpectedStartArrayToken()) { jp.nextToken(); // VALUE_NUMBER_INT int year = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int month = jp.getIntValue(); jp.nextToken(); // VALUE_NUMBER_INT int day = jp.getIntValue(); if (jp.nextToken() != JsonToken.END_ARRAY) { throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after DateMidnight ints"); } return new DateMidnight(year, month, day); } switch (jp.getCurrentToken()) { case VALUE_NUMBER_INT: return new DateMidnight(jp.getLongValue()); case VALUE_STRING: DateTime local = parseLocal(jp); if (local == null) { return null; } return local.toDateMidnight(); } throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "expected JSON Array, Number or String"); } }