gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-14 12:01:31 29 4
gpt4 key购买 nike

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

ZoneRules介绍

[英]The rules defining how the zone offset varies for a single time-zone.

The rules model all the historic and future transitions for a time-zone. ZoneOffsetTransition is used for known transitions, typically historic. ZoneOffsetTransitionRule is used for future transitions that are based on the result of an algorithm.

The rules are loaded via ZoneRulesProvider using a ZoneId. The same rules may be shared internally between multiple zone IDs.

Serializing an instance of ZoneRules will store the entire set of rules. It does not store the zone ID as it is not part of the state of this object.

A rule implementation may or may not store full information about historic and future transitions, and the information stored is only as accurate as that supplied to the implementation by the rules provider. Applications should treat the data provided as representing the best information available to the implementation of this rule.

Specification for implementors

The supplied implementations of this class are immutable and thread-safe.
[中]定义单个时区的分区偏移量如何变化的规则。
这些规则为时区的所有历史和未来过渡建模。ZoneOffsetTransition用于已知的过渡,通常是历史过渡。ZoneOffsetTransitionRule用于基于算法结果的未来转换。
使用ZoneId通过ZoneRulesProvider加载规则。多个区域ID之间可以在内部共享相同的规则。
序列化ZoneRules实例将存储整个规则集。它不存储区域ID,因为它不是此对象状态的一部分。
规则实现可能存储也可能不存储有关历史和未来转换的完整信息,存储的信息仅与规则提供程序提供给实现的信息一样准确。应用程序应将提供的数据视为代表执行此规则所需的最佳信息。
####实施者规范
提供的此类实现是不可变的,并且是线程安全的。

代码示例

代码示例来源:origin: gengstrand/clojure-news-feed

@Override
 public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
  return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
 }
}

代码示例来源: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: stackoverflow.com

ZoneRules rules = zdt.getZone().getRules();
Boolean dstInEffect = rules.isDaylightSavings( zdt.toInstant() );

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

/**
 * Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible.
 * <p>
 * The returns a normalized {@code ZoneId} that can be used in place of this ID.
 * The result will have {@code ZoneRules} equivalent to those returned by this object,
 * however the ID returned by {@code getId()} may be different.
 * <p>
 * The normalization checks if the rules of this {@code ZoneId} have a fixed offset.
 * If they do, then the {@code ZoneOffset} equal to that offset is returned.
 * Otherwise {@code this} is returned.
 *
 * @return the time-zone unique ID, not null
 */
public ZoneId normalized() {
  try {
    ZoneRules rules = getRules();
    if (rules.isFixedOffset()) {
      return rules.getOffset(Instant.EPOCH);
    }
  } catch (ZoneRulesException ex) {
    // ignore invalid objects
  }
  return this;
}

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

List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
ZoneOffset offset;
if (validOffsets.size() == 1) {
  offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
  ZoneOffsetTransition trans = rules.getTransition(isoLDT);
  localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
  offset = trans.getOffsetAfter();

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

Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
  ZoneOffsetTransition trans = rules.getTransition(localDateTime);
  if (trans != null && trans.isGap()) {

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

private static void addTransitionRules(ZoneId zoneId, int rawTimeZoneOffsetInSeconds, VTimeZone result) {
  ZoneOffsetTransition zoneOffsetTransition = Collections.min(zoneId.getRules().getTransitions(),
      new Comparator<ZoneOffsetTransition>() {
        @Override
  for (ZoneOffsetTransitionRule transitionRule : zoneId.getRules().getTransitionRules()) {
    int transitionRuleMonthValue = transitionRule.getMonth().getValue();
    DayOfWeek transitionRuleDayOfWeek = transitionRule.getDayOfWeek();

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

private static void addTransitions(ZoneId zoneId, VTimeZone result, int rawTimeZoneOffsetInSeconds) throws ParseException {
  Map<ZoneOffsetKey, Set<ZoneOffsetTransition>> zoneTransitionsByOffsets = new HashMap<>();
  for(ZoneOffsetTransition zoneTransitionRule : zoneId.getRules().getTransitions()){
    ZoneOffsetKey offfsetKey = ZoneOffsetKey.of(zoneTransitionRule.getOffsetBefore(), zoneTransitionRule.getOffsetAfter());

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

/**
 * Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible.
 * <p>
 * The returns a normalized {@code ZoneId} that can be used in place of this ID.
 * The result will have {@code ZoneRules} equivalent to those returned by this object,
 * however the ID returned by {@code getId()} may be different.
 * <p>
 * The normalization checks if the rules of this {@code ZoneId} have a fixed offset.
 * If they do, then the {@code ZoneOffset} equal to that offset is returned.
 * Otherwise {@code this} is returned.
 *
 * @return the time-zone unique ID, not null
 */
public ZoneId normalized() {
  try {
    ZoneRules rules = getRules();
    if (rules.isFixedOffset()) {
      return rules.getOffset(Instant.EPOCH);
    }
  } catch (ZoneRulesException ex) {
    // ignore invalid objects
  }
  return this;
}

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

List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
ZoneOffset offset;
if (validOffsets.size() == 1) {
  offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
  ZoneOffsetTransition trans = rules.getTransition(isoLDT);
  localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
  offset = trans.getOffsetAfter();

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

Jdk8Methods.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
  ZoneOffsetTransition trans = rules.getTransition(localDateTime);
  if (trans != null && trans.isGap()) {

代码示例来源:origin: XeroAPI/Xero-Java

@Override
 public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
  return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
 }
}

代码示例来源: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: org.threeten/threetenbp

List<ZoneOffset> validOffsets = rules.getValidOffsets(localDateTime);
ZoneOffset offset;
if (validOffsets.size() == 1) {
  offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
  ZoneOffsetTransition trans = rules.getTransition(localDateTime);
  localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
  offset = trans.getOffsetAfter();

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

ZonedDateTime zdt = ...;
ZoneRules rules = zdt.getZone().getRules();
boolean isDst = rules.isDaylightSavings(zdt.toInstant());

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
  public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
    return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
  }
},

代码示例来源:origin: 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

List<ZoneOffset> validOffsets = rules.getValidOffsets(localDateTime);
ZoneOffset offset;
if (validOffsets.size() == 1) {
  offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
  ZoneOffsetTransition trans = rules.getTransition(localDateTime);
  localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
  offset = trans.getOffsetAfter();

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

ZonedDateTime now = ZonedDateTime.now( ZoneId.of( "America/Montreal" ) );
…
ZoneId z = now.getZone();
ZoneRules zoneRules = z.getRules();
Boolean isDst = zoneRules.isDaylightSavings( now.toInstant() );

代码示例来源:origin: mercadolibre/java-sdk

@Override
 public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
  return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
 }
}

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