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


Java ZoneOffsetTransitionRule.TimeDefinition方法代码示例

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


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

示例1: test_of

import java.time.zone.ZoneOffsetTransitionRule; //导入方法依赖的package包/类
public void test_of(){
    //used for standard offset
    ZoneOffset stdOffset1 = ZoneOffset.UTC;
    ZoneOffset stdOffset2 = ZoneOffset.ofHours(1);
    LocalDateTime time_of_stdOffsetTransition1 = LocalDateTime.of(2013, 1, 5, 1, 0);
    ZoneOffsetTransition  stdOffsetTransition1 = ZoneOffsetTransition.of(time_of_stdOffsetTransition1, stdOffset1, stdOffset2);
    List<ZoneOffsetTransition> stdOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
    stdOffsetTransition_list.add(stdOffsetTransition1);

    //used for wall offset
    ZoneOffset wallOffset1 = ZoneOffset.ofHours(2);
    ZoneOffset wallOffset2 = ZoneOffset.ofHours(4);
    ZoneOffset wallOffset3 = ZoneOffset.ofHours(7);

    LocalDateTime time_of_wallOffsetTransition1 = LocalDateTime.of(2013, 2, 5, 1, 0);
    LocalDateTime time_of_wallOffsetTransition2 = LocalDateTime.of(2013, 3, 5, 1, 0);
    LocalDateTime time_of_wallOffsetTransition3 = LocalDateTime.of(2013, 10, 5, 1, 0);

    ZoneOffsetTransition  wallOffsetTransition1 = ZoneOffsetTransition.of(time_of_wallOffsetTransition1, wallOffset1, wallOffset2);
    ZoneOffsetTransition  wallOffsetTransition2 = ZoneOffsetTransition.of(time_of_wallOffsetTransition2, wallOffset2, wallOffset3);
    ZoneOffsetTransition  wallOffsetTransition3 = ZoneOffsetTransition.of(time_of_wallOffsetTransition3, wallOffset3, wallOffset1);

    List<ZoneOffsetTransition> wallOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
    wallOffsetTransition_list.add(wallOffsetTransition1);
    wallOffsetTransition_list.add(wallOffsetTransition2);
    wallOffsetTransition_list.add(wallOffsetTransition3);

    //used for ZoneOffsetTransitionRule
    ZoneOffset ruleOffset = ZoneOffset.ofHours(3);
    ZoneOffsetTransitionRule.TimeDefinition timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.valueOf("WALL");
    ZoneOffsetTransitionRule rule1 = ZoneOffsetTransitionRule.of(Month.FEBRUARY,
                                                                 2,
                                                                 DayOfWeek.MONDAY,
                                                                 LocalTime.of(1, 0),
                                                                 false,
                                                                 timeDefinition,
                                                                 ZoneOffset.UTC,
                                                                 ZoneOffset.UTC,
                                                                 ruleOffset
                                                                 );
     List<ZoneOffsetTransitionRule> rule_list = new ArrayList<ZoneOffsetTransitionRule>();
     rule_list.add(rule1);

     //Begin verification
     ZoneRules zoneRule = ZoneRules.of(stdOffset1,
                                       wallOffset1,
                                       stdOffsetTransition_list,
                                       wallOffsetTransition_list,
                                       rule_list
                                       );

     OffsetDateTime before_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).minusSeconds(1);
     OffsetDateTime after_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).plusSeconds(1);;
     assertEquals(zoneRule.getStandardOffset(before_time_of_stdOffsetTransition1.toInstant()), stdOffset1);
     assertEquals(zoneRule.getStandardOffset(after_time_of_stdOffsetTransition1.toInstant()), stdOffset2);

     OffsetDateTime  before_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).minusSeconds(1);
     OffsetDateTime  after_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).plusSeconds(1);
     assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition1);
     assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition2);

     OffsetDateTime  before_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).minusSeconds(1);
     OffsetDateTime  after_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).plusSeconds(1);
     assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition2);
     assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition3);

     OffsetDateTime  before_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).minusSeconds(1);
     OffsetDateTime  after_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).plusSeconds(1);
     assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition3.toInstant()), wallOffsetTransition3);
     assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition3.toInstant()), rule1.createTransition(2014));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:72,代码来源:TCKZoneRules.java


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