src/share/classes/java/time/zone/ZoneOffsetTransitionRule.java

Print this page




  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.zone;
  63 
  64 import static java.time.temporal.Adjusters.nextOrSame;
  65 import static java.time.temporal.Adjusters.previousOrSame;
  66 
  67 import java.io.DataInput;
  68 import java.io.DataOutput;
  69 import java.io.IOException;
  70 import java.io.Serializable;
  71 import java.time.DayOfWeek;
  72 import java.time.LocalDate;
  73 import java.time.LocalDateTime;
  74 import java.time.LocalTime;
  75 import java.time.Month;
  76 import java.time.ZoneOffset;
  77 import java.time.temporal.ISOChrono;
  78 import java.util.Objects;
  79 
  80 /**
  81  * A rule expressing how to create a transition.
  82  * <p>
  83  * This class allows rules for identifying future transitions to be expressed.
  84  * A rule might be written in many forms:
  85  * <p><ul>
  86  * <li>the 16th March
  87  * <li>the Sunday on or after the 16th March
  88  * <li>the Sunday on or before the 16th March
  89  * <li>the last Sunday in February
  90  * </ul><p>
  91  * These different rule types can be expressed and queried.
  92  *
  93  * <h3>Specification for implementors</h3>
  94  * This class is immutable and thread-safe.
  95  *
  96  * @since 1.8
  97  */


 413      * Gets the offset after the transition.
 414      *
 415      * @return the offset after, not null
 416      */
 417     public ZoneOffset getOffsetAfter() {
 418         return offsetAfter;
 419     }
 420 
 421     //-----------------------------------------------------------------------
 422     /**
 423      * Creates a transition instance for the specified year.
 424      * <p>
 425      * Calculations are performed using the ISO-8601 chronology.
 426      *
 427      * @param year  the year to create a transition for, not null
 428      * @return the transition instance, not null
 429      */
 430     public ZoneOffsetTransition createTransition(int year) {
 431         LocalDate date;
 432         if (dom < 0) {
 433             date = LocalDate.of(year, month, month.length(ISOChrono.INSTANCE.isLeapYear(year)) + 1 + dom);
 434             if (dow != null) {
 435                 date = date.with(previousOrSame(dow));
 436             }
 437         } else {
 438             date = LocalDate.of(year, month, dom);
 439             if (dow != null) {
 440                 date = date.with(nextOrSame(dow));
 441             }
 442         }
 443         if (timeEndOfDay) {
 444             date = date.plusDays(1);
 445         }
 446         LocalDateTime localDT = LocalDateTime.of(date, time);
 447         LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
 448         return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
 449     }
 450 
 451     //-----------------------------------------------------------------------
 452     /**
 453      * Checks if this object equals another.




  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.zone;
  63 
  64 import static java.time.temporal.Adjusters.nextOrSame;
  65 import static java.time.temporal.Adjusters.previousOrSame;
  66 
  67 import java.io.DataInput;
  68 import java.io.DataOutput;
  69 import java.io.IOException;
  70 import java.io.Serializable;
  71 import java.time.DayOfWeek;
  72 import java.time.LocalDate;
  73 import java.time.LocalDateTime;
  74 import java.time.LocalTime;
  75 import java.time.Month;
  76 import java.time.ZoneOffset;
  77 import java.time.chrono.IsoChronology;
  78 import java.util.Objects;
  79 
  80 /**
  81  * A rule expressing how to create a transition.
  82  * <p>
  83  * This class allows rules for identifying future transitions to be expressed.
  84  * A rule might be written in many forms:
  85  * <p><ul>
  86  * <li>the 16th March
  87  * <li>the Sunday on or after the 16th March
  88  * <li>the Sunday on or before the 16th March
  89  * <li>the last Sunday in February
  90  * </ul><p>
  91  * These different rule types can be expressed and queried.
  92  *
  93  * <h3>Specification for implementors</h3>
  94  * This class is immutable and thread-safe.
  95  *
  96  * @since 1.8
  97  */


 413      * Gets the offset after the transition.
 414      *
 415      * @return the offset after, not null
 416      */
 417     public ZoneOffset getOffsetAfter() {
 418         return offsetAfter;
 419     }
 420 
 421     //-----------------------------------------------------------------------
 422     /**
 423      * Creates a transition instance for the specified year.
 424      * <p>
 425      * Calculations are performed using the ISO-8601 chronology.
 426      *
 427      * @param year  the year to create a transition for, not null
 428      * @return the transition instance, not null
 429      */
 430     public ZoneOffsetTransition createTransition(int year) {
 431         LocalDate date;
 432         if (dom < 0) {
 433             date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom);
 434             if (dow != null) {
 435                 date = date.with(previousOrSame(dow));
 436             }
 437         } else {
 438             date = LocalDate.of(year, month, dom);
 439             if (dow != null) {
 440                 date = date.with(nextOrSame(dow));
 441             }
 442         }
 443         if (timeEndOfDay) {
 444             date = date.plusDays(1);
 445         }
 446         LocalDateTime localDT = LocalDateTime.of(date, time);
 447         LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
 448         return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
 449     }
 450 
 451     //-----------------------------------------------------------------------
 452     /**
 453      * Checks if this object equals another.