Java Code Examples for org.threeten.bp.LocalDateTime#of()

The following examples show how to use org.threeten.bp.LocalDateTime#of() . 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: ZoneOffsetTransitionRule.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a transition instance for the specified year.
 * <p>
 * Calculations are performed using the ISO-8601 chronology.
 *
 * @param year  the year to create a transition for, not null
 * @return the transition instance, not null
 */
public ZoneOffsetTransition createTransition(int year) {
    LocalDate date;
    if (dom < 0) {
        date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom);
        if (dow != null) {
            date = date.with(previousOrSame(dow));
        }
    } else {
        date = LocalDate.of(year, month, dom);
        if (dow != null) {
            date = date.with(nextOrSame(dow));
        }
    }
    LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time);
    LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 2
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_Paris_getOffsetInfo_gap() {
    ZoneRules test = europeParis();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PONE, GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), OFFSET_PONE);
    assertEquals(trans.getOffsetAfter(), OFFSET_PTWO);
    assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.isValidOffset(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), false);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T02:00+01:00 to +02:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PONE));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example 3
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_gap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 9, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-5), GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getInstant(), createInstant(2008, 3, 9, 2, 0, ZoneOffset.ofHours(-5)));
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-09T02:00-05:00 to -04:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-5)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example 4
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_Paris_getOffsetInfo_overlap() {
    ZoneRules test = europeParis();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PTWO, OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), OFFSET_PTWO);
    assertEquals(trans.getOffsetAfter(), OFFSET_PONE);
    assertEquals(trans.getInstant(), createInstant(2008, 10, 26, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.isValidOffset(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(3)), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T03:00+02:00 to +01:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PTWO));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example 5
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_equals() {
    LocalDateTime ldtA = LocalDateTime.of(2010, 3, 31, 1, 0);
    ZoneOffsetTransition a1 = ZoneOffsetTransition.of(ldtA, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransition a2 = ZoneOffsetTransition.of(ldtA, OFFSET_0200, OFFSET_0300);
    LocalDateTime ldtB = LocalDateTime.of(2010, 10, 31, 1, 0);
    ZoneOffsetTransition b = ZoneOffsetTransition.of(ldtB, OFFSET_0300, OFFSET_0200);

    assertEquals(a1.equals(a1), true);
    assertEquals(a1.equals(a2), true);
    assertEquals(a1.equals(b), false);
    assertEquals(a2.equals(a1), true);
    assertEquals(a2.equals(a2), true);
    assertEquals(a2.equals(b), false);
    assertEquals(b.equals(a1), false);
    assertEquals(b.equals(a2), false);
    assertEquals(b.equals(b), true);

    assertEquals(a1.equals(""), false);
    assertEquals(a1.equals(null), false);
}
 
Example 6
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example 7
Source File: TestDateTimeTextPrinting.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_print_appendText2arg_french_long() throws Exception {
    DateTimeFormatter f = builder.appendText(MONTH_OF_YEAR, TextStyle.FULL).toFormatter(Locale.FRENCH);
    LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
    String text = f.format(dt);
    assertEquals(text, "janvier");
}
 
Example 8
Source File: TestDateTimeTextPrinting.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider="printText")
public void test_appendText1arg_print(TemporalField field, TextStyle style, int value, String expected) throws Exception {
    if (style == TextStyle.FULL) {
        DateTimeFormatter f = builder.appendText(field).toFormatter(Locale.ENGLISH);
        LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
        dt = dt.with(field, value);
        String text = f.format(dt);
        assertEquals(text, expected);
    }
}
 
Example 9
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_isValidOffset_overlap() {
    LocalDateTime ldt = LocalDateTime.of(2010, 10, 31, 1, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, OFFSET_0300, OFFSET_0200);
    assertEquals(test.isValidOffset(OFFSET_0100), false);
    assertEquals(test.isValidOffset(OFFSET_0200), true);
    assertEquals(test.isValidOffset(OFFSET_0230), false);
    assertEquals(test.isValidOffset(OFFSET_0300), true);
    assertEquals(test.isValidOffset(OFFSET_0400), false);
}
 
Example 10
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_floatingWeek_overlap_endOfDay() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
            Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL,
            OFFSET_0200, OFFSET_0300, OFFSET_0200);
    ZoneOffsetTransition trans = new ZoneOffsetTransition(
            LocalDateTime.of(2000, Month.MARCH, 27, 0, 0), OFFSET_0300, OFFSET_0200);
    assertEquals(test.createTransition(2000), trans);
}
 
Example 11
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 12
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_getters_gap() throws Exception {
    LocalDateTime before = LocalDateTime.of(2010, 3, 31, 1, 0);
    LocalDateTime after = LocalDateTime.of(2010, 3, 31, 2, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(before, OFFSET_0200, OFFSET_0300);
    assertEquals(test.isGap(), true);
    assertEquals(test.isOverlap(), false);
    assertEquals(test.getDateTimeBefore(), before);
    assertEquals(test.getDateTimeAfter(), after);
    assertEquals(test.getInstant(), before.toInstant(OFFSET_0200));
    assertEquals(test.getOffsetBefore(), OFFSET_0200);
    assertEquals(test.getOffsetAfter(), OFFSET_0300);
    assertEquals(test.getDuration(), Duration.of(1, HOURS));
    assertSerializable(test);
}
 
Example 13
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_getters_overlap() throws Exception {
    LocalDateTime before = LocalDateTime.of(2010, 10, 31, 1, 0);
    LocalDateTime after = LocalDateTime.of(2010, 10, 31, 0, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(before, OFFSET_0300, OFFSET_0200);
    assertEquals(test.isGap(), false);
    assertEquals(test.isOverlap(), true);
    assertEquals(test.getDateTimeBefore(), before);
    assertEquals(test.getDateTimeAfter(), after);
    assertEquals(test.getInstant(), before.toInstant(OFFSET_0300));
    assertEquals(test.getOffsetBefore(), OFFSET_0300);
    assertEquals(test.getOffsetAfter(), OFFSET_0200);
    assertEquals(test.getDuration(), Duration.of(-1, HOURS));
    assertSerializable(test);
}
 
Example 14
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_toString_overlap() {
    LocalDateTime ldt = LocalDateTime.of(2010, 10, 31, 1, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, OFFSET_0300, OFFSET_0200);
    assertEquals(test.toString(), "Transition[Overlap at 2010-10-31T01:00+03:00 to +02:00]");
}
 
Example 15
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_serialization_unusual2() throws Exception {
    LocalDateTime ldt = LocalDateTime.of(Year.MIN_VALUE, 1, 1, 12, 1, 3);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("+10:02:34"));
    assertSerializable(test);
}
 
Example 16
Source File: TestStandardZoneRules.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private LocalDateTime createLDT(int year, int month, int day) {
    return LocalDateTime.of(year, month, day, 0, 0);
}
 
Example 17
Source File: TestZoneRulesBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static LocalDateTime dateTime(int year, int month, int day, int h, int m) {
    return LocalDateTime.of(year, month, day, h, m);
}
 
Example 18
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_toString_gap() {
    LocalDateTime ldt = LocalDateTime.of(2010, 3, 31, 1, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, OFFSET_0200, OFFSET_0300);
    assertEquals(test.toString(), "Transition[Gap at 2010-03-31T01:00+02:00 to +03:00]");
}
 
Example 19
Source File: TestZoneRulesBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static LocalDateTime dateTime(int year, Month month, int day, int h, int m) {
    return LocalDateTime.of(year, month, day, h, m);
}
 
Example 20
Source File: TestZoneOffsetTransition.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void test_serialization_unusual1() throws Exception {
    LocalDateTime ldt = LocalDateTime.of(Year.MAX_VALUE, 12, 31, 1, 31, 53);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(ldt, ZoneOffset.of("+02:04:56"), ZoneOffset.of("-10:02:34"));
    assertSerializable(test);
}