org.threeten.bp.Month Java Examples

The following examples show how to use org.threeten.bp.Month. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_Dublin_getStandardOffset() {
    ZoneRules test = europeDublin();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.getYear() < 1881) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutes(0, -25));
        } else if (zdt.getYear() >= 1881 && zdt.getYear() < 1917) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -25, -21));
        } else if (zdt.getYear() >= 1917 && zdt.getYear() < 1969) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO, zdt.toString());
        } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
            // from 1968-02-18 to 1971-10-31, permanent UTC+1
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
            assertEquals(test.getOffset(instant), OFFSET_PONE, zdt.toString());
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO, zdt.toString());
            assertEquals(test.getOffset(instant), zdt.getMonth() == Month.JANUARY ? OFFSET_ZERO : OFFSET_PONE, zdt.toString());
        }
        zdt = zdt.plusMonths(6);
    }
}
 
Example #2
Source File: TestDateTimeTextPrinting.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_appendTextMap() throws Exception {
    Map<Long, String> map = new HashMap<Long, String>();
    map.put(1L, "JNY");
    map.put(2L, "FBY");
    map.put(3L, "MCH");
    map.put(4L, "APL");
    map.put(5L, "MAY");
    map.put(6L, "JUN");
    map.put(7L, "JLY");
    map.put(8L, "AGT");
    map.put(9L, "SPT");
    map.put(10L, "OBR");
    map.put(11L, "NVR");
    map.put(12L, "DBR");
    builder.appendText(MONTH_OF_YEAR, map);
    DateTimeFormatter f = builder.toFormatter();
    LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
    for (Month month : Month.values()) {
        assertEquals(f.format(dt.with(month)), map.get((long) month.getValue()));
    }
}
 
Example #3
Source File: BasicActivityDecorated.java    From material-calendarview with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_basic);
  ButterKnife.bind(this);

  widget.setOnDateChangedListener(this);
  widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);

  final LocalDate instance = LocalDate.now();
  widget.setSelectedDate(instance);

  final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
  final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);

  widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();

  widget.addDecorators(
      new MySelectorDecorator(this),
      new HighlightWeekendsDecorator(),
      oneDayDecorator
  );

  new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor());
}
 
Example #4
Source File: DisableDaysActivity.java    From material-calendarview with MIT License 6 votes vote down vote up
@Override protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_basic);
  ButterKnife.bind(this);

  // Add a decorator to disable prime numbered days
  widget.addDecorator(new PrimeDayDisableDecorator());
  // Add a second decorator that explicitly enables days <= 10. This will work because
  // decorators are applied in order, and the system allows re-enabling
  widget.addDecorator(new EnableOneToTenDecorator());

  final LocalDate calendar = LocalDate.now();
  widget.setSelectedDate(calendar);

  final LocalDate min = LocalDate.of(calendar.getYear(), Month.JANUARY, 1);
  final LocalDate max = LocalDate.of(calendar.getYear() + 1, Month.OCTOBER, 31);

  widget.state().edit()
      .setMinimumDate(min)
      .setMaximumDate(max)
      .commit();
}
 
Example #5
Source File: SwappableBasicActivityDecorated.java    From material-calendarview with MIT License 6 votes vote down vote up
@Override protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_basic_modes);
  ButterKnife.bind(this);

  widget.setOnDateChangedListener(this);
  widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);

  final LocalDate instance = LocalDate.now();
  widget.setSelectedDate(instance);

  final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
  final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);

  widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();

  widget.addDecorators(
      new MySelectorDecorator(this),
      new HighlightWeekendsDecorator(),
      oneDayDecorator
  );
}
 
Example #6
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_getters_fixedDate() throws Exception {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.getMonth(), Month.MARCH);
    assertEquals(test.getDayOfMonthIndicator(), 20);
    assertEquals(test.getDayOfWeek(), null);
    assertEquals(test.getLocalTime(), TIME_0100);
    assertEquals(test.isMidnightEndOfDay(), false);
    assertEquals(test.getTimeDefinition(), TimeDefinition.WALL);
    assertEquals(test.getStandardOffset(), OFFSET_0200);
    assertEquals(test.getOffsetBefore(), OFFSET_0200);
    assertEquals(test.getOffsetAfter(), OFFSET_0300);
    assertSerializable(test);
}
 
Example #7
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_getters_floatingWeekBackwards() throws Exception {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.getMonth(), Month.MARCH);
    assertEquals(test.getDayOfMonthIndicator(), -1);
    assertEquals(test.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(test.getLocalTime(), TIME_0100);
    assertEquals(test.isMidnightEndOfDay(), false);
    assertEquals(test.getTimeDefinition(), TimeDefinition.WALL);
    assertEquals(test.getStandardOffset(), OFFSET_0200);
    assertEquals(test.getOffsetBefore(), OFFSET_0200);
    assertEquals(test.getOffsetAfter(), OFFSET_0300);
    assertSerializable(test);
}
 
Example #8
Source File: ZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Reads the state from the stream.
 *
 * @param in  the input stream, not null
 * @return the created object, not null
 * @throws IOException if an error occurs
 */
static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException {
    int data = in.readInt();
    Month month = Month.of(data >>> 28);
    int dom = ((data & (63 << 22)) >>> 22) - 32;
    int dowByte = (data & (7 << 19)) >>> 19;
    DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte);
    int timeByte = (data & (31 << 14)) >>> 14;
    TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
    int stdByte = (data & (255 << 4)) >>> 4;
    int beforeByte = (data & (3 << 2)) >>> 2;
    int afterByte = (data & 3);
    int timeOfDaysSecs = (timeByte == 31 ? in.readInt() : timeByte * 3600);
    ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
    ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
    ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
    // only bit of validation that we need to copy from public of() method
    if (dom < -28 || dom > 31 || dom == 0) {
        throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
    }
    LocalTime time = LocalTime.ofSecondOfDay(Jdk8Methods.floorMod(timeOfDaysSecs, SECS_PER_DAY));
    int adjustDays = Jdk8Methods.floorDiv(timeOfDaysSecs, SECS_PER_DAY);
    return new ZoneOffsetTransitionRule(month, dom, dow, time, adjustDays, defn, std, before, after);
}
 
Example #9
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_getters_floatingWeek() throws Exception {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.getMonth(), Month.MARCH);
    assertEquals(test.getDayOfMonthIndicator(), 20);
    assertEquals(test.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(test.getLocalTime(), TIME_0100);
    assertEquals(test.isMidnightEndOfDay(), false);
    assertEquals(test.getTimeDefinition(), TimeDefinition.WALL);
    assertEquals(test.getStandardOffset(), OFFSET_0200);
    assertEquals(test.getOffsetBefore(), OFFSET_0200);
    assertEquals(test.getOffsetAfter(), OFFSET_0300);
    assertSerializable(test);
}
 
Example #10
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_London_getTransitionRules() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    assertEquals(rules.size(), 2);

    ZoneOffsetTransitionRule in = rules.get(0);
    assertEquals(in.getMonth(), Month.MARCH);
    assertEquals(in.getDayOfMonthIndicator(), 25);  // optimized from -1
    assertEquals(in.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(in.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(in.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(in.getStandardOffset(), OFFSET_ZERO);
    assertEquals(in.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(in.getOffsetAfter(), OFFSET_PONE);

    ZoneOffsetTransitionRule out = rules.get(1);
    assertEquals(out.getMonth(), Month.OCTOBER);
    assertEquals(out.getDayOfMonthIndicator(), 25);  // optimized from -1
    assertEquals(out.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(out.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(out.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(out.getStandardOffset(), OFFSET_ZERO);
    assertEquals(out.getOffsetBefore(), OFFSET_PONE);
    assertEquals(out.getOffsetAfter(), OFFSET_ZERO);
}
 
Example #11
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_previous() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
                } else {
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 8);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 24);
                }
            }
        }
    }
}
 
Example #12
Source File: TestTzdbZoneRulesCompiler.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_parseMonthDayTime_sepSatAfter82500() throws Exception {
    TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2018f", new ArrayList<File>(), null, false);
    TZDBRule mdt = parseMonthDayTime(test, "Sep Sat>=8 25:00");
    assertEquals(mdt.month, Month.SEPTEMBER);
    assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY);
    assertEquals(mdt.dayOfMonth, 8);
    assertEquals(mdt.adjustForwards, true);
    assertEquals(mdt.time, LocalTime.of(1, 0));
    assertEquals(mdt.adjustDays, 1);
    assertEquals(mdt.timeDefinition, TimeDefinition.WALL);
}
 
Example #13
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_equals_localTimeDifferent() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);
}
 
Example #14
Source File: TestTzdbZoneRulesCompiler.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_parseMonthDayTime_maySatBefore50220u() throws Exception {
    TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false);
    TZDBRule mdt = parseMonthDayTime(test, "May Sat<=5 24:00g");
    assertEquals(mdt.month, Month.MAY);
    assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY);
    assertEquals(mdt.dayOfMonth, 5);
    assertEquals(mdt.adjustForwards, false);
    assertEquals(mdt.time, LocalTime.of(0, 0));
    assertEquals(mdt.adjustDays, 1);
    assertEquals(mdt.timeDefinition, TimeDefinition.UTC);
}
 
Example #15
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_hashCode_floatingWeek_gap_notEndOfDay() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(a.hashCode(), b.hashCode());
}
 
Example #16
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_toString_floatingWeek_gap_notEndOfDay() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or after MARCH 20 at 01:00 WALL, standard offset +02:00]");
}
 
Example #17
Source File: TestTzdbZoneRulesCompiler.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_parseMonthDayTime_maySatBefore15Dash() throws Exception {
    TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false);
    TZDBRule mdt = parseMonthDayTime(test, "May Sat<=15 -");
    assertEquals(mdt.month, Month.MAY);
    assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY);
    assertEquals(mdt.dayOfMonth, 15);
    assertEquals(mdt.adjustForwards, false);
    assertEquals(mdt.time, LocalTime.of(0, 0));
    assertEquals(mdt.adjustDays, 0);
    assertEquals(mdt.timeDefinition, TimeDefinition.WALL);
}
 
Example #18
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_hashCode_fixedDate() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(a.hashCode(), b.hashCode());
}
 
Example #19
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_equals_offsetBeforeDifferent() {
    ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0300, OFFSET_0300);
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
    assertEquals(b.equals(b), true);
}
 
Example #20
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_toString_floatingWeekBackwards_last() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day of MARCH at 01:00 WALL, standard offset +02:00]");
}
 
Example #21
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfNextYear_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
            assertEquals(test.getYear(), 2009);
            assertEquals(test.getMonth(), JANUARY);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #22
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_toString_floatingWeekBackwards_secondLast() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, -2, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day minus 1 of MARCH at 01:00 WALL, standard offset +02:00]");
}
 
Example #23
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfMonth_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #24
Source File: TestTzdbZoneRulesCompiler.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_parseLeapSecondRule_just_before_midnight() throws Exception {
    TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false);
    LeapSecondRule lsr = parseLeapSecondRule(test, "Leap\t2009 May\t1   23:59:59 - S");
    assertEquals(lsr.leapDate, LocalDate.of(2009, Month.MAY, 1));
    assertEquals(lsr.secondAdjustment, -1);
}
 
Example #25
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfYear_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), Month.JANUARY);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #26
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_createTransition_floatingWeekBackwards_secondLast() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, -2, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransition trans = new ZoneOffsetTransition(
            LocalDateTime.of(2000, Month.MARCH, 26, 1, 0), OFFSET_0200, OFFSET_0300);
    assertEquals(test.createTransition(2000), trans);
}
 
Example #27
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_firstDayOfNextMonth_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
            assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008);
            assertEquals(test.getMonth(), month.plus(1));
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
 
Example #28
Source File: TestZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_createTransition_fixedDate() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD,
            OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransition trans = new ZoneOffsetTransition(
            LocalDateTime.of(2000, Month.MARCH, 20, 1, 0), OFFSET_0200, OFFSET_0300);
    assertEquals(test.createTransition(2000), trans);
}
 
Example #29
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_leap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(true); i++) {
            LocalDate date = date(2008, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(true));
        }
    }
}
 
Example #30
Source File: TestTemporalAdjusters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_nonLeap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(false));
        }
    }
}