jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java
changeset 30960 016d47557b45
parent 25859 3317bb8137f4
equal deleted inserted replaced
30959:14e1b420cdd6 30960:016d47557b45
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   165      * @param offsetBefore  the offset before the cutover, not null
   165      * @param offsetBefore  the offset before the cutover, not null
   166      * @param offsetAfter  the offset after the cutover, not null
   166      * @param offsetAfter  the offset after the cutover, not null
   167      * @return the rule, not null
   167      * @return the rule, not null
   168      * @throws IllegalArgumentException if the day of month indicator is invalid
   168      * @throws IllegalArgumentException if the day of month indicator is invalid
   169      * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
   169      * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
       
   170      * @throws IllegalArgumentException if {@code time.getNano()} returns non-zero value
   170      */
   171      */
   171     public static ZoneOffsetTransitionRule of(
   172     public static ZoneOffsetTransitionRule of(
   172             Month month,
   173             Month month,
   173             int dayOfMonthIndicator,
   174             int dayOfMonthIndicator,
   174             DayOfWeek dayOfWeek,
   175             DayOfWeek dayOfWeek,
   188             throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
   189             throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
   189         }
   190         }
   190         if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
   191         if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
   191             throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
   192             throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
   192         }
   193         }
       
   194         if (time.getNano() != 0) {
       
   195             throw new IllegalArgumentException("Time's nano-of-second must be zero");
       
   196         }
   193         return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter);
   197         return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter);
   194     }
   198     }
   195 
   199 
   196     /**
   200     /**
   197      * Creates an instance defining the yearly rule to create transitions between two offsets.
   201      * Creates an instance defining the yearly rule to create transitions between two offsets.
   218             boolean timeEndOfDay,
   222             boolean timeEndOfDay,
   219             TimeDefinition timeDefnition,
   223             TimeDefinition timeDefnition,
   220             ZoneOffset standardOffset,
   224             ZoneOffset standardOffset,
   221             ZoneOffset offsetBefore,
   225             ZoneOffset offsetBefore,
   222             ZoneOffset offsetAfter) {
   226             ZoneOffset offsetAfter) {
       
   227         assert time.getNano() == 0;
   223         this.month = month;
   228         this.month = month;
   224         this.dom = (byte) dayOfMonthIndicator;
   229         this.dom = (byte) dayOfMonthIndicator;
   225         this.dow = dayOfWeek;
   230         this.dow = dayOfWeek;
   226         this.time = time;
   231         this.time = time;
   227         this.timeEndOfDay = timeEndOfDay;
   232         this.timeEndOfDay = timeEndOfDay;