コード例 #1
0
  /**
   * If this LimitChronology has the same time zone as the one given, then this is returned.
   * Otherwise, a new instance is returned, with the limits adjusted to the new time zone.
   */
  public Chronology withZone(DateTimeZone zone) {
    if (zone == null) {
      zone = DateTimeZone.getDefault();
    }
    if (zone == getZone()) {
      return this;
    }

    if (zone == DateTimeZone.UTC && iWithUTC != null) {
      return iWithUTC;
    }

    DateTime lowerLimit = iLowerLimit;
    if (lowerLimit != null) {
      MutableDateTime mdt = lowerLimit.toMutableDateTime();
      mdt.setZoneRetainFields(zone);
      lowerLimit = mdt.toDateTime();
    }

    DateTime upperLimit = iUpperLimit;
    if (upperLimit != null) {
      MutableDateTime mdt = upperLimit.toMutableDateTime();
      mdt.setZoneRetainFields(zone);
      upperLimit = mdt.toDateTime();
    }

    LimitChronology chrono = getInstance(getBase().withZone(zone), lowerLimit, upperLimit);

    if (zone == DateTimeZone.UTC) {
      iWithUTC = chrono;
    }

    return chrono;
  }
コード例 #2
0
 /**
  * Gets the Chronology in a specific time zone.
  *
  * @param zone the zone to get the chronology in, null is default
  * @return the chronology
  */
 public Chronology withZone(DateTimeZone zone) {
   if (zone == null) {
     zone = DateTimeZone.getDefault();
   }
   if (zone == getZone()) {
     return this;
   }
   return getInstance(zone);
 }
コード例 #3
0
 public Chronology withZone(DateTimeZone zone) {
   if (zone == null) {
     zone = DateTimeZone.getDefault();
   }
   if (zone == DateTimeZone.UTC) {
     return withUTC();
   }
   if (zone == getZone()) {
     return this;
   }
   return StrictChronology.getInstance(getBase().withZone(zone));
 }
コード例 #4
0
  /**
   * Gets an instance of the EthiopicChronology in the given time zone.
   *
   * @param zone the time zone to get the chronology in, null is default
   * @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4
   * @return a chronology in the specified time zone
   */
  public static EthiopicChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) {
    if (zone == null) {
      zone = DateTimeZone.getDefault();
    }
    EthiopicChronology chrono;
    EthiopicChronology[] chronos = cCache.get(zone);
    if (chronos == null) {
      chronos = new EthiopicChronology[7];
      EthiopicChronology[] oldChronos = cCache.putIfAbsent(zone, chronos);
      if (oldChronos != null) {
        chronos = oldChronos;
      }
    }
    try {
      chrono = chronos[minDaysInFirstWeek - 1];
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new IllegalArgumentException("Invalid min days in first week: " + minDaysInFirstWeek);
    }

    if (chrono == null) {
      synchronized (chronos) {
        chrono = chronos[minDaysInFirstWeek - 1];
        if (chrono == null) {
          if (zone == DateTimeZone.UTC) {
            // First create without a lower limit.
            chrono = new EthiopicChronology(null, null, minDaysInFirstWeek);
            // Impose lower limit and make another EthiopicChronology.
            DateTime lowerLimit = new DateTime(1, 1, 1, 0, 0, 0, 0, chrono);
            chrono =
                new EthiopicChronology(
                    LimitChronology.getInstance(chrono, lowerLimit, null),
                    null,
                    minDaysInFirstWeek);
          } else {
            chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek);
            chrono =
                new EthiopicChronology(
                    ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek);
          }
          chronos[minDaysInFirstWeek - 1] = chrono;
        }
      }
    }
    return chrono;
  }
コード例 #5
0
 /**
  * Gets an instance of the EthiopicChronology in the default time zone.
  *
  * @return a chronology in the default time zone
  */
 public static EthiopicChronology getInstance() {
   return getInstance(DateTimeZone.getDefault(), 4);
 }