net.time4j.tz.ZonalTransition类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中net.time4j.tz.ZonalTransition类的一些代码示例,展示了ZonalTransition类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonalTransition类的具体详情如下:
包路径:net.time4j.tz.ZonalTransition
类名称:ZonalTransition

ZonalTransition介绍

[英]Represents the change of a shift of the local time relative to POSIX-time in any timezone.

This class contains informations about the global timestamp of the transition and the shifts/offsets before and after the transitions. A change of a zonal shift can either be caused by special historical events and political actions (change of standard time) or by establishing daylight saving-rules (change from winter time to summer time and reverse - DST). Therefore the total shift getTotalOffset() is always the sum of the parts getStandardOffset() and getDaylightSavingOffset().

Shifts are described on the local timeline in seconds. Following relationship holds between local time and POSIX-time:

getTotalOffset() = [Local Wall Time] - [POSIX Time]

A zonal transition induces a gap on the local timeline if the new shift is greater than the old shift. And an overlap occurs if the new shift is smaller than the old shift. A local time is not defined within gaps and ambivalent in overlapping regions.
[中]表示本地时间相对于任何时区中POSIX时间的偏移量的变化。
此类包含有关转换的全局时间戳以及转换前后的移位/偏移的信息。地带性变化既可以由特殊的历史事件和政治行动(标准时间的变化)引起,也可以通过建立夏时制规则(从冬季时间到夏季时间的变化和反向DST)引起。因此,总移位getTotalOffset()始终是getStandardOffset()和getDaylightSavingOffset()部分的总和。
班次在本地时间线上以秒为单位进行描述。当地时间和POSIX时间之间存在以下关系:
getTotalOffset()=[Local Wall Time]-[POSIX Time]
如果新的转变大于旧的转变,地带性转变会在当地时间线上产生一个缺口。如果新班次比旧班次小,就会发生重叠。当地时间不是在间隔内定义的,而是在重叠区域内定义的。

代码示例

代码示例来源:origin: net.time4j/time4j-olson

static void dump(
  ZonalTransition transition,
  Appendable buffer
) throws IOException {
  Moment ut = Moment.of(transition.getPosixTime(), TimeScale.POSIX);
  buffer.append(">>> Transition at: ").append(ut.toString());
  buffer.append(" from ").append(format(transition.getPreviousOffset()));
  buffer.append(" to ").append(format(transition.getTotalOffset()));
  buffer.append(", DST=");
  buffer.append(format(transition.getDaylightSavingOffset()));
  buffer.append(NEW_LINE);
}

代码示例来源:origin: net.time4j/time4j-core

@Override
public int getDSTSavings() {
  TransitionHistory history = this.tz.getHistory();
  if (history != null) {
    List<ZonalTransition> transitions = history.getStdTransitions();
    int dst = 0;
    for (int i = transitions.size() - 1; i >= 0; i--) {
      ZonalTransition t = transitions.get(i);
      if (t.isDaylightSaving()) {
        dst = t.getDaylightSavingOffset() * 1000;
        break;
      }
    }
    return dst;
  }
  return 0;
}

代码示例来源:origin: net.time4j/time4j-olson

ZonalTransition getConflictTransition(
  GregorianDate localDate,
  long localSecs
) {
  long preModel = this.initial.getPosixTime();
  int max =
    Math.max(
      this.initial.getPreviousOffset(),
      this.initial.getTotalOffset());
  if (localSecs <= preModel + max) {
    return null;
  }
  for (ZonalTransition t : this.getTransitions(localDate)) {
    long tt = t.getPosixTime();
    if (t.isGap()) {
      if (localSecs < tt + t.getPreviousOffset()) {
        return null; // offset = t.getPreviousOffset()
      } else if (localSecs < tt + t.getTotalOffset()) {
        return t;
      }
    } else if (t.isOverlap()) {
      if (localSecs < tt + t.getTotalOffset()) {
        return null; // offset = t.getPreviousOffset()
      } else if (localSecs < tt + t.getPreviousOffset()) {
        return t;
      }
    }
  }
  return null; // offset = lastTotalOffset
}

代码示例来源:origin: net.time4j/time4j-olson

private static int searchLocal(
  long localSecs,
  ZonalTransition[] transitions
) {
  int low = 0;
  int high = transitions.length - 1;
  while (low <= high) {
    int middle = (low + high) / 2;
    ZonalTransition zt = transitions[middle];
    int offset = Math.max(zt.getTotalOffset(), zt.getPreviousOffset());
    if (zt.getPosixTime() + offset <= localSecs) {
      low = middle + 1;
    } else {
      high = middle - 1;
    }
  }
  return low;
}

代码示例来源:origin: net.time4j/time4j-core

/**
 * @serialData  Checks the consistency.
 * @param       in      object input stream
 * @throws      IOException in any case of inconsistencies
 * @throws      ClassNotFoundException if class-loading fails
 */
private void readObject(ObjectInputStream in)
  throws IOException, ClassNotFoundException {
  in.defaultReadObject();
  try {
    checkRange(this.previous);
    checkRange(this.total);
    checkDST(this.dst);
  } catch (IllegalArgumentException iae) {
    throw new InvalidObjectException(iae.getMessage());
  }
}

代码示例来源:origin: net.time4j/time4j-olson

ZonalTransition zt = initial;
if (initial.getPosixTime() == Long.MIN_VALUE) {
  if (initial.isDaylightSaving()) {
    throw new IllegalArgumentException(
      "Initial transition must not have any dst-offset: "
  zt = new ZonalTransition(
    Moment.axis().getMinimum().getPosixTime(),
    initial.getStandardOffset(),
    initial.getStandardOffset(),
    getNextTransition(initial.getPosixTime(), initial, sortedRules);
  if (initial.getTotalOffset() != first.getPreviousOffset()) {
    throw new IllegalArgumentException(
      "Inconsistent model: " + initial + " / " + rules);

代码示例来源:origin: net.time4j/time4j-olson

) throws IOException {
  int rawOffset = transition.getStandardOffset();
  boolean newStdOffset = (rawOffset != stdOffset);
  byte first = 0;
  int dstOffset = transition.getDaylightSavingOffset();
  if (transition.isDaylightSaving() && (dstOffset == 0)) {
    dstOffset = Integer.MAX_VALUE;
  long modTime = transition.getPosixTime() + stdOffset + 7200;
  int timeIndex = NO_COMPRESSION;
    out.writeLong(transition.getPosixTime());
  } else {
    int dayIndex = (int) ((modTime - POSIX_TIME_1825) / 86400);

代码示例来源:origin: net.time4j/time4j-core

private PlainTimestamp atStartOfDay(TransitionHistory history) {
  if (history == null) {
    throw new UnsupportedOperationException(
      "Timezone repository does not expose its transition history: "
      + Timezone.getProviderInfo());
  }
  ZonalTransition conflict = history.getConflictTransition(this, PlainTime.MIN);
  if ((conflict != null) && conflict.isGap()) {
    long localSeconds =
      conflict.getPosixTime() + conflict.getTotalOffset();
    PlainDate date =
      PlainDate.of(
        MathUtils.floorDivide(localSeconds, 86400),
        EpochDays.UNIX);
    int secondsOfDay = MathUtils.floorModulo(localSeconds, 86400);
    int second = secondsOfDay % 60;
    int minutesOfDay = secondsOfDay / 60;
    int minute = minutesOfDay % 60;
    int hour = minutesOfDay / 60;
    PlainTime time = PlainTime.of(hour, minute, second);
    return PlainTimestamp.of(date, time);
  }
  return this.at(PlainTime.MIN);
}

代码示例来源:origin: net.time4j/time4j-olson

) {
  long preModel = initial.getPosixTime();
  int n = rules.size();
  int i = 0;
  int stdOffset = initial.getStandardOffset();
    ) {
      transitions.add(
        new ZonalTransition(
          tt,
          stdOffset + previous.getSavings(),

代码示例来源:origin: net.time4j/time4j-core

private Moment atFirstMoment(Timezone tz) {
  TransitionHistory history = tz.getHistory();
  if (history == null) {
    throw new UnsupportedOperationException(
      "Timezone repository does not expose its transition history: "
      + Timezone.getProviderInfo());
  }
  ZonalTransition conflict = history.getConflictTransition(this, PlainTime.MIN);
  if ((conflict != null) && conflict.isGap()) {
    return Moment.of(conflict.getPosixTime(), TimeScale.POSIX);
  }
  return this.at(PlainTime.MIN).in(tz);
}

代码示例来源:origin: net.time4j/time4j-olson

@Override
public ZonalTransition getStartTransition(UnixTime ut) {
  long preModel = this.initial.getPosixTime();
  int stdOffset = this.initial.getStandardOffset();
  int n = this.rules.size();
  DaylightSavingRule rule = this.rules.get(0);
    long tt = zt.getPosixTime();
          zt = transitions.get(i - 1);
        if (zt.getPosixTime() > preModel) {
          current = zt;

代码示例来源:origin: net.time4j/time4j-olson

ZonalOffset.ofTotalSeconds(t.get(0).getPreviousOffset());
long t1 = last.getPosixTime() + 1;
long t2 = getFutureMoment(1);

代码示例来源:origin: net.time4j/time4j-olson

int stdOffset = this.initial.getStandardOffset();
    new ZonalTransition(
      getTransitionTime(rule, year, shift),
      stdOffset + previous.getSavings(),

代码示例来源:origin: net.time4j/time4j-olson

private static int search(
  long posixTime,
  ZonalTransition[] transitions
) {
  int low = 0;
  int high = transitions.length - 1;
  while (low <= high) {
    int middle = (low + high) / 2;
    if (transitions[middle].getPosixTime() <= posixTime) {
      low = middle + 1;
    } else {
      high = middle - 1;
    }
  }
  return low;
}

代码示例来源:origin: net.time4j/time4j-olson

@Override
public ZonalOffset getInitialOffset() {
  return ZonalOffset.ofTotalSeconds(
    this.transitions[0].getPreviousOffset());
}

代码示例来源:origin: net.time4j/time4j-olson

@Override
public ZonalOffset getInitialOffset() {
  return ZonalOffset.ofTotalSeconds(this.initial.getTotalOffset());
}

代码示例来源:origin: net.time4j/time4j-core

@Override
public boolean isDaylightSaving(UnixTime ut) {
  ZonalTransition t = this.history.getStartTransition(ut);
  return ((t != null) && t.isDaylightSaving());
}

代码示例来源:origin: net.time4j/time4j-core

return (this.total - this.getDaylightSavingOffset());

代码示例来源:origin: net.time4j/time4j-core

@Override
public boolean isInvalid(
  GregorianDate localDate,
  WallTime localTime
) {
  ZonalTransition t = this.history.getConflictTransition(localDate, localTime);
  return ((t != null) && t.isGap());
}

代码示例来源:origin: net.time4j/time4j-core

@Override
public ZonalOffset getStandardOffset(UnixTime ut) {
  ZonalTransition t = this.history.getStartTransition(ut);
  return (
    (t == null)
    ? this.history.getInitialOffset()
    : ZonalOffset.ofTotalSeconds(t.getStandardOffset())
  );
}

相关文章