1 /* 2 * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * * Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * * Neither the name of JSR-310 nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.threeten.bp; 33 34 import static org.threeten.bp.DayOfWeek.MONDAY; 35 import static org.threeten.bp.DayOfWeek.TUESDAY; 36 import static org.threeten.bp.Month.AUGUST; 37 import static org.threeten.bp.Month.FEBRUARY; 38 import static org.threeten.bp.Month.MARCH; 39 import static org.threeten.bp.temporal.ChronoField.DAY_OF_MONTH; 40 import static org.threeten.bp.temporal.ChronoUnit.DAYS; 41 import static org.threeten.bp.temporal.ChronoUnit.HOURS; 42 import static org.threeten.bp.temporal.ChronoUnit.MINUTES; 43 import static org.threeten.bp.temporal.TemporalAdjusters.dayOfWeekInMonth; 44 import static org.threeten.bp.temporal.TemporalAdjusters.firstInMonth; 45 import static org.threeten.bp.temporal.TemporalAdjusters.lastDayOfMonth; 46 import static org.threeten.bp.temporal.TemporalAdjusters.next; 47 import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame; 48 49 import org.threeten.bp.zone.ZoneOffsetTransition; 50 51 /** 52 * Test the fluency of the whole API. 53 */ 54 public class FluentAPIChecker { 55 56 @SuppressWarnings("unused") main(String[] args)57 public static void main(String[] args) { 58 Clock clock = Clock.systemDefaultZone(); 59 60 LocalTime tod = LocalTime.now(clock); 61 tod.plusHours(6).plusMinutes(2); 62 tod.plus(6, HOURS).plus(2, MINUTES); 63 64 LocalDate date = null; 65 date = LocalDate.now(clock).plusDays(3); 66 date = LocalDate.now(clock).plus(3, DAYS); 67 date = LocalDate.now(Clock.systemDefaultZone()).plus(3, DAYS); 68 69 date = LocalDate.of(2007, 3, 20); 70 date = LocalDate.of(2007, MARCH, 20); 71 date = Year.of(2007).atMonth(3).atDay(20); 72 date = Year.of(2007).atMonth(MARCH).atDay(20); 73 74 date = date.with(lastDayOfMonth()); 75 date = date.with(next(MONDAY)); 76 date = date.with(nextOrSame(MONDAY)); 77 date = date.with(dayOfWeekInMonth(2, TUESDAY)); 78 date = date.with(firstInMonth(MONDAY)); 79 date = date.with(Year.of(2009)); 80 date = date.with(Month.of(6)); 81 date = date.with(AUGUST); 82 83 // DateTimeFields fri13 = DateTimeFields.of( 84 // DAY_OF_WEEK, FRIDAY.getValue(), DAY_OF_MONTH, 13); 85 // if (fri13.matches(date)) { 86 // System.out.println("Spooky"); 87 // } 88 89 Period d2 = Period.ofDays(3); 90 System.out.println(d2); 91 92 tod.withHour(12).withMinute(30); 93 94 MonthDay md = MonthDay.of(FEBRUARY, 4); 95 md = md.with(MARCH); 96 97 DAY_OF_MONTH.range().getMaximum(); 98 date.getMonth().maxLength(); 99 date.range(DAY_OF_MONTH).getMaximum(); 100 FEBRUARY.maxLength(); 101 102 DayOfWeek dow = MONDAY; 103 dow = dow.plus(1); 104 // 105 // int dayIndex = day.value(); 106 // int dayIndex = day.value(Territory.US); 107 // int dayIndex = day.valueIndexedFrom(SUNDAY); 108 //// SundayBasedDayOfWeek.MONDAY != DayOfWeek.MONDAY; 109 // Territory.US.dayOfWeekComparator(); 110 111 ZoneOffset offset = ZoneOffset.ofHours(1); 112 ZoneId paris = ZoneId.of("Europe/Paris"); 113 114 for (ZoneOffsetTransition trans : paris.getRules().getTransitions()) { 115 System.out.println("Paris transition: " + trans); 116 } 117 System.out.println("Summer time Paris starts: " + paris.getRules().getTransitionRules().get(0)); 118 System.out.println("Summer time Paris ends: " + paris.getRules().getTransitionRules().get(1)); 119 120 LocalDateTime ldt = date.atTime(tod); 121 ZonedDateTime zdt1 = date.atStartOfDay(paris); 122 ZonedDateTime zdt2 = date.atTime(12, 0).atZone(paris); 123 124 { 125 Year year = Year.of(2002); 126 YearMonth sixNationsMonth = year.atMonth(FEBRUARY); 127 LocalDate englandWales = sixNationsMonth.atDay(12); 128 LocalDate engWal = Year.of(2009).atMonth(FEBRUARY).atDay(12); 129 } 130 131 Clock tickingClock = Clock.tickSeconds(paris); 132 for (int i = 0; i < 20; i++) { 133 System.out.println(LocalTime.now(tickingClock)); 134 try { 135 Thread.sleep(500); 136 } catch (InterruptedException ex) { 137 } 138 } 139 } 140 141 } 142