Пример #1
0
 public static String formatFileName(String taskName, Instant firstLogTime, String agentId) {
   return String.format(
           ENGLISH,
           "%s@%08x%08x.%s",
           taskName,
           firstLogTime.getEpochSecond(),
           firstLogTime.getNano(),
           agentId)
       + LOG_GZ_FILE_SUFFIX;
 }
Пример #2
0
  /**
   * Gets the previous transition before the specified instant.
   *
   * <p>This returns details of the previous transition after the specified instant. For example, if
   * the instant represents a point where "summer" daylight saving time applies, then the method
   * will return the transition from the previous "winter" time.
   *
   * @param instant the instant to get the previous transition after, not null, but null may be
   *     ignored if the rules have a single offset for all instants
   * @return the previous transition after the specified instant, null if this is before the first
   *     transition
   */
  public ZoneOffsetTransition previousTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
      return null;
    }
    long epochSec = instant.getEpochSecond();
    if (instant.getNano() > 0 && epochSec < Long.MAX_VALUE) {
      epochSec += 1; // allow rest of method to only use seconds
    }

    // check if using last rules
    long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1];
    if (lastRules.length > 0 && epochSec > lastHistoric) {
      // search year the instant is in
      ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1];
      int year = findYear(epochSec, lastHistoricOffset);
      ZoneOffsetTransition[] transArray = findTransitionArray(year);
      for (int i = transArray.length - 1; i >= 0; i--) {
        if (epochSec > transArray[i].toEpochSecond()) {
          return transArray[i];
        }
      }
      // use last from preceding year
      int lastHistoricYear = findYear(lastHistoric, lastHistoricOffset);
      if (--year > lastHistoricYear) {
        transArray = findTransitionArray(year);
        return transArray[transArray.length - 1];
      }
      // drop through
    }

    // using historic rules
    int index = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
      index = -index - 1;
    }
    if (index <= 0) {
      return null;
    }
    return new ZoneOffsetTransition(
        savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]);
  }