gpt4 book ai didi

org.threeten.bp.zone.ZoneOffsetTransition类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:56:39 27 4
gpt4 key购买 nike

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

ZoneOffsetTransition介绍

[英]A transition between two offsets caused by a discontinuity in the local time-line.

A transition between two offsets is normally the result of a daylight savings cutover. The discontinuity is normally a gap in spring and an overlap in autumn. ZoneOffsetTransition models the transition between the two offsets.

Gaps occur where there are local date-times that simply do not not exist. An example would be when the offset changes from +03:00 to +04:00. This might be described as 'the clocks will move forward one hour tonight at 1am'.

Overlaps occur where there are local date-times that exist twice. An example would be when the offset changes from +04:00 to +03:00. This might be described as 'the clocks will move back one hour tonight at 2am'.

Specification for implementors

This class is immutable and thread-safe.
[中]由当地时间线的不连续性引起的两个偏移之间的过渡。
两个偏移之间的过渡通常是夏令时切换的结果。这种不连续性通常是春季的一个间隙,秋季的一个重叠。ZoneOffsetTransition为两个偏移之间的过渡建模。
当本地日期时间根本不存在时,就会出现间隔。例如,偏移从+03:00更改为+04:00。这可能被描述为“时钟将在今晚凌晨1点向前移动一小时”。
如果存在两次本地日期时间,则会发生重叠。例如,偏移从+04:00更改为+03:00。这可以被描述为“今晚凌晨2点钟会向后拨一小时”。
####实施者规范
这个类是不可变的,是线程安全的。

代码示例

代码示例来源:origin: org.threeten/threetenbp

/**
 * Finds the offset info for a local date-time and transition.
 *
 * @param dt  the date-time, not null
 * @param trans  the transition, not null
 * @return the offset info, not null
 */
private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) {
  LocalDateTime localTransition = trans.getDateTimeBefore();
  if (trans.isGap()) {
    if (dt.isBefore(localTransition)) {
      return trans.getOffsetBefore();
    }
    if (dt.isBefore(trans.getDateTimeAfter())) {
      return trans;
    } else {
      return trans.getOffsetAfter();
    }
  } else {
    if (dt.isBefore(localTransition) == false) {
      return trans.getOffsetAfter();
    }
    if (dt.isBefore(trans.getDateTimeAfter())) {
      return trans.getOffsetBefore();
    } else {
      return trans;
    }
  }
}

代码示例来源:origin: stackoverflow.com

public boolean isExtraHour(final ZonedDateTime time) {
  final ZoneOffsetTransition dayTransition = time.getZone().getRules()
      .getTransition(time.toLocalDateTime());

  return dayTransition != null && dayTransition.isOverlap() && dayTransition.getInstant()
      .equals(time.toInstant());
}

代码示例来源:origin: ThreeTen/threetenbp

ZoneOffset before = wallOffsets[i];
ZoneOffset after = wallOffsets[i + 1];
ZoneOffsetTransition trans = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after);
if (trans.isGap()) {
  localTransitionList.add(trans.getDateTimeBefore());
  localTransitionList.add(trans.getDateTimeAfter());
} else {
  localTransitionList.add(trans.getDateTimeAfter());
  localTransitionList.add(trans.getDateTimeBefore());

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Gets the valid offsets during this transition.
 * <p>
 * A gap will return an empty list, while an overlap will return both offsets.
 *
 * @return the list of valid offsets
 */
List<ZoneOffset> getValidOffsets() {
  if (isGap()) {
    return Collections.emptyList();
  }
  return Arrays.asList(getOffsetBefore(), getOffsetAfter());
}

代码示例来源:origin: stackoverflow.com

LocalDateTime ldt = LocalDateTime.of(2015, 3, 29, 2, 30, 0, 0);
ZoneRules rules = ZoneId.of("Europe/Berlin").getRules();
ZoneOffsetTransition conflict = rules.getTransition(ldt);
if (conflict != null && conflict.isGap()) {
  ldt = conflict.getDateTimeAfter();
}
System.out.println(ldt); // 2015-03-29T03:00

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Gets the duration of the transition in seconds.
 *
 * @return the duration in seconds
 */
private int getDurationSeconds() {
  return getOffsetAfter().getTotalSeconds() - getOffsetBefore().getTotalSeconds();
}

代码示例来源:origin: org.threeten/threetenbp

this.standardOffsets[0] = baseStandardOffset;
for (int i = 0; i < standardOffsetTransitionList.size(); i++) {
  this.standardTransitions[i] = standardOffsetTransitionList.get(i).toEpochSecond();
  this.standardOffsets[i + 1] = standardOffsetTransitionList.get(i).getOffsetAfter();
localTransitionOffsetList.add(baseWallOffset);
for (ZoneOffsetTransition trans : transitionList) {
  if (trans.isGap()) {
    localTransitionList.add(trans.getDateTimeBefore());
    localTransitionList.add(trans.getDateTimeAfter());
  } else {
    localTransitionList.add(trans.getDateTimeAfter());
    localTransitionList.add(trans.getDateTimeBefore());
  localTransitionOffsetList.add(trans.getOffsetAfter());
  this.savingsInstantTransitions[i] = transitionList.get(i).getInstant().getEpochSecond();

代码示例来源:origin: org.threeten/threetenbp

for (TZRule rule : window.ruleList) {
    ZoneOffsetTransition trans = rule.toTransition(loopStandardOffset, loopSavings);
    if (trans.toEpochSecond() > loopWindowStart.toEpochSecond(loopWindowOffset)) {
    new ZoneOffsetTransition(
      LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset),
      loopStandardOffset, window.standardOffset)));
if (loopWindowOffset.equals(effectiveWallOffset) == false) {
  ZoneOffsetTransition trans = deduplicate(
    new ZoneOffsetTransition(loopWindowStart, loopWindowOffset, effectiveWallOffset));
  transitionList.add(trans);
  if (trans.toEpochSecond() < loopWindowStart.toEpochSecond(loopWindowOffset) == false &&
      trans.toEpochSecond() < window.createDateTimeEpochSecond(loopSavings) &&
      trans.getOffsetBefore().equals(trans.getOffsetAfter()) == false) {
    transitionList.add(trans);
    loopSavings = rule.savingAmountSecs;

代码示例来源:origin: org.threeten/threetenbp

@Override
public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap() {
  ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
  if (trans != null && trans.isOverlap()) {
    ZoneOffset earlierOffset = trans.getOffsetBefore();
    if (earlierOffset.equals(offset) == false) {
      return new ChronoZonedDateTimeImpl<D>(dateTime, earlierOffset, zone);
    }
  }
  return this;
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public ZoneOffset getOffset(Instant instant) {
  long epochSec = instant.getEpochSecond();
  // check if using last rules
  if (lastRules.length > 0 &&
      epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
    int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
    ZoneOffsetTransition[] transArray = findTransitionArray(year);
    ZoneOffsetTransition trans = null;
    for (int i = 0; i < transArray.length; i++) {
      trans = transArray[i];
      if (epochSec < trans.toEpochSecond()) {
        return trans.getOffsetBefore();
      }
    }
    return trans.getOffsetAfter();
  }
  // using historic rules
  int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
  if (index < 0) {
    // switch negative insert position to start of matched range
    index = -index - 2;
  }
  return wallOffsets[index + 1];
}

代码示例来源:origin: net.oneandone.ical4j/ical4j

ZoneOffsetKey offfsetKey = ZoneOffsetKey.of(zoneTransitionRule.getOffsetBefore(), zoneTransitionRule.getOffsetAfter());
LocalDateTime start = Collections.min(e.getValue()).getDateTimeBefore();
  RDate rDate = new RDate(new ParameterList(), String.format(DATE_TIME_TPL, transition.getDateTimeBefore()));
  observance.getProperties().add(rDate);

代码示例来源:origin: org.threeten/threetenbp

} else if (validOffsets.size() == 0) {
  ZoneOffsetTransition trans = rules.getTransition(isoLDT);
  localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
  offset = trans.getOffsetAfter();
} else {
  if (preferredOffset != null && validOffsets.contains(preferredOffset)) {

代码示例来源:origin: stackoverflow.com

LocalDateTime ldt = LocalDate.of(2015, 3, 29).atTime(LocalTime.of(1, 40)); 
ZoneOffsetTransition conflict = ZoneId.of("Europe/London").getRules().getTransition(ldt);
boolean gap = (conflict != null) && conflict.isGap(); // true

代码示例来源:origin: ThreeTen/threetenbp

for (ZoneOffsetTransition trans : transArray) {
  info = findOffsetInfo(dt, trans);
  if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
    return info;
if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
  return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
} else {
  return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);

代码示例来源:origin: ThreeTen/threetenbp

@Override
public ChronoZonedDateTime<D> withLaterOffsetAtOverlap() {
  ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
  if (trans != null) {
    ZoneOffset offset = trans.getOffsetAfter();
    if (offset.equals(getOffset()) == false) {
      return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone);
    }
  }
  return this;
}

代码示例来源:origin: ThreeTen/threetenbp

ZoneOffsetTransition[] transArray = findTransitionArray(year);
  for (ZoneOffsetTransition trans : transArray) {
    if (epochSec < trans.toEpochSecond()) {
      return trans;
  index += 1;  // exact match, so need to add one to get the next
return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);

代码示例来源:origin: stackoverflow.com

ZoneId zoneId = ZoneId.of("Australia/Sydney");
ZoneRules rules = zoneId.getRules();

ZoneOffsetTransition nextTransition = rules.nextTransition(Instant.now());
System.out.println("Next transition at: " +
    nextTransition.getInstant().atZone(zoneId));

ZoneOffsetTransition nextNextTransition =
    rules.nextTransition(nextTransition.getInstant());
System.out.println("Next transition after that at: " +
    nextNextTransition.getInstant().atZone(zoneId));

代码示例来源:origin: org.threeten/threetenbp

@Override
public List<ZoneOffsetTransition> getTransitions() {
  List<ZoneOffsetTransition> list = new ArrayList<ZoneOffsetTransition>();
  for (int i = 0; i < savingsInstantTransitions.length; i++) {
    list.add(new ZoneOffsetTransition(savingsInstantTransitions[i], wallOffsets[i], wallOffsets[i + 1]));
  }
  return Collections.unmodifiableList(list);
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public ZoneOffset getOffset(LocalDateTime localDateTime) {
  Object info = getOffsetInfo(localDateTime);
  if (info instanceof ZoneOffsetTransition) {
    return ((ZoneOffsetTransition) info).getOffsetBefore();
  }
  return (ZoneOffset) info;
}

代码示例来源:origin: net.oneandone.ical4j/ical4j

@Override
  public int compare(ZoneOffsetTransition z1, ZoneOffsetTransition z2) {
    return z1.getDateTimeBefore().compareTo(z2.getDateTimeBefore());
  }
});

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com