当前位置: 首页>>代码示例>>Java>>正文


Java ZoneRules.isValidOffset方法代码示例

本文整理汇总了Java中java.time.zone.ZoneRules.isValidOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneRules.isValidOffset方法的具体用法?Java ZoneRules.isValidOffset怎么用?Java ZoneRules.isValidOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.zone.ZoneRules的用法示例。


在下文中一共展示了ZoneRules.isValidOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ofStrict

import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:ZonedDateTime.java

示例2: ofStrict

import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the combination of local date-time,
 * offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the local date-time according to the
 * rules of the specified zone. If the offset is invalid, an exception is thrown.
 * 
 * @param localDateTime the local date-time, not null
 * @param offset the zone offset, not null
 * @param zone the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {

  Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
  Jdk7Methods.Objects_requireNonNull(offset, "offset");
  Jdk7Methods.Objects_requireNonNull(zone, "zone");
  ZoneRules rules = zone.getRules();
  if (rules.isValidOffset(localDateTime, offset) == false) {
    // ZoneOffsetTransition trans = rules.getTransition(localDateTime);
    // if (trans != null && trans.isGap()) {
    // // error message says daylight savings for simplicity
    // // even though there are other kinds of gaps
    // throw new DateTimeException("LocalDateTime '" + localDateTime + "' does not exist in zone '" + zone
    // + "' due to a gap in the local time-line, typically caused by daylight savings");
    // }
    // throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
    // localDateTime
    // + "' in zone '" + zone + "'");
  }
  return new ZonedDateTime(localDateTime, offset, zone);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:33,代码来源:ZonedDateTime.java

示例3: ofStrict

import java.time.zone.ZoneRules; //导入方法依赖的package包/类
/**
 * Obtains an instance of {@code ZonedDateTime} strictly validating the
 * combination of local date-time, offset and zone ID.
 * <p>
 * This creates a zoned date-time ensuring that the offset is valid for the
 * local date-time according to the rules of the specified zone.
 * If the offset is invalid, an exception is thrown.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 * @throws DateTimeException if the combination of arguments is invalid
 */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // error message says daylight savings for simplicity
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime +
                    "' does not exist in zone '" + zone +
                    "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
                localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ZonedDateTime.java


注:本文中的java.time.zone.ZoneRules.isValidOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。