コード例 #1
0
 private Date adjustYear(Date ldate, long millis, int zoneOffset) {
   int i;
   for (i = eras.length - 1; i >= 0; --i) {
     Era era = eras[i];
     long since = era.getSince(null);
     if (era.isLocalTime()) {
       since -= zoneOffset;
     }
     if (millis >= since) {
       ldate.setLocalEra(era);
       int y = ldate.getNormalizedYear() - era.getSinceDate().getYear() + 1;
       ldate.setLocalYear(y);
       break;
     }
   }
   if (i < 0) {
     ldate.setLocalEra(null);
     ldate.setLocalYear(ldate.getNormalizedYear());
   }
   ldate.setNormalized(true);
   return ldate;
 }
コード例 #2
0
  public boolean normalize(CalendarDate date) {
    if (date.isNormalized()) {
      return true;
    }

    normalizeYear(date);
    Date ldate = (Date) date;

    // Normalize it as a Gregorian date and get its millisecond value
    super.normalize(ldate);

    boolean hasMillis = false;
    long millis = 0;
    int year = ldate.getNormalizedYear();
    int i;
    Era era = null;
    for (i = eras.length - 1; i >= 0; --i) {
      era = eras[i];
      if (era.isLocalTime()) {
        CalendarDate sinceDate = era.getSinceDate();
        int sinceYear = sinceDate.getYear();
        if (year > sinceYear) {
          break;
        }
        if (year == sinceYear) {
          int month = ldate.getMonth();
          int sinceMonth = sinceDate.getMonth();
          if (month > sinceMonth) {
            break;
          }
          if (month == sinceMonth) {
            int day = ldate.getDayOfMonth();
            int sinceDay = sinceDate.getDayOfMonth();
            if (day > sinceDay) {
              break;
            }
            if (day == sinceDay) {
              long timeOfDay = ldate.getTimeOfDay();
              long sinceTimeOfDay = sinceDate.getTimeOfDay();
              if (timeOfDay >= sinceTimeOfDay) {
                break;
              }
              --i;
              break;
            }
          }
        }
      } else {
        if (!hasMillis) {
          millis = super.getTime(date);
          hasMillis = true;
        }

        long since = era.getSince(date.getZone());
        if (millis >= since) {
          break;
        }
      }
    }
    if (i >= 0) {
      ldate.setLocalEra(era);
      int y = ldate.getNormalizedYear() - era.getSinceDate().getYear() + 1;
      ldate.setLocalYear(y);
    } else {
      // Set Gregorian year with no era
      ldate.setEra(null);
      ldate.setLocalYear(year);
      ldate.setNormalizedYear(year);
    }
    ldate.setNormalized(true);
    return true;
  }