Java Code Examples for java.time.LocalDateTime#of()

The following examples show how to use java.time.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: TCKZoneRules.java    From dragonwell8_jdk with GNU General Public License v2.0 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 2
Source File: TCKZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 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: TCKInstant.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
 
Example 4
Source File: CronType.java    From baratine with GNU General Public License v2.0 6 votes vote down vote up
private long nextTime(int year, int month, int day, int hour, int minute)
{
  LocalDateTime dateTime = LocalDateTime.of(year, month, day, hour, minute);
  /*
  //QDate cal = allocateCalendar();

  cal.setLocalTime(0);

  cal.setYear(year);
  cal.setMonth(month);
  cal.setDayOfMonth(day);
  cal.setHour(hour);
  cal.setMinute(minute);

  long time = cal.getGMTTime();

  freeCalendar(cal);
  */

  return dateTime.toEpochSecond(ZoneOffset.UTC) * 1000;
}
 
Example 5
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() {
    TEST_LOCAL_2008_06_30_11_30_59_500 = LocalDateTime.of(2008, 6, 30, 11, 30, 59, 500);
    TEST_DATE_TIME = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    TEST_DATE_TIME_PARIS = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
    TEST_PARIS_OVERLAP_2008_10_26_02_30 = LocalDateTime.of(2008, 10, 26, 2, 30);
    TEST_PARIS_GAP_2008_03_30_02_30 = LocalDateTime.of(2008, 3, 30, 2, 30);
}
 
Example 6
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_minusMonths() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusMonths(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusMonths(1), ZONE_0100));
}
 
Example 7
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleDates")
public void test_get_dates(int y, int m, int d) {
    LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30);
    assertEquals(a.getYear(), y);
    assertEquals(a.getMonth(), Month.of(m));
    assertEquals(a.getDayOfMonth(), d);
}
 
Example 8
Source File: DateTimeMapFunctionsTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
public void testYearWeek() {
  LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30);
  startCol.append(dateTime);
  StringColumn yearWeek = startCol.yearWeek();
  TemporalField woy = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
  assertEquals(
      "2018-" + Strings.padStart(String.valueOf(dateTime.get(woy)), 2, '0'), yearWeek.get(0));
}
 
Example 9
Source File: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleDates")
public void test_get_dates(int y, int m, int d) {
    LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30);
    assertEquals(a.getYear(), y);
    assertEquals(a.getMonth(), Month.of(m));
    assertEquals(a.getDayOfMonth(), d);
}
 
Example 10
Source File: TCKIsoFields.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="quartersBetween")
Object[][] data_quartersBetween() {
    return new Object[][] {
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 1, 1), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 1, 2), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 2, 1), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 3, 1), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 3, 31), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 4, 1), 1},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 4, 2), 1},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 6, 30), 1},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 7, 1), 2},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 10, 1), 3},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 12, 31), 3},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2001, 1, 1), 4},
            {LocalDate.of(2000, 1, 1), LocalDate.of(2002, 1, 1), 8},

            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 12, 31), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 10, 2), 0},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 10, 1), -1},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 7, 2), -1},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 7, 1), -2},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 4, 2), -2},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 4, 1), -3},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 1, 2), -3},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 1, 1), -4},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 12, 31), -4},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 10, 2), -4},
            {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 10, 1), -5},

            {LocalDate.of(2000, 1, 1), LocalDateTime.of(2001, 4, 5, 0, 0), 5},
    };
}
 
Example 11
Source File: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_of_5intsMonth() {
    LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40);
    check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
}
 
Example 12
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_dayTooLow() {
    LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321);
}
 
Example 13
Source File: TCKZoneOffsetTransition.java    From jdk8u_jdk with GNU General Public License v2.0 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 14
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6ints_minuteTooHigh() {
    LocalDateTime.of(2007, 7, 15, 12, 60, 40);
}
 
Example 15
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_5ints_yearTooLow() {
    LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30);
}
 
Example 16
Source File: TCKZoneOffsetTransition.java    From jdk8u-jdk with GNU General Public License v2.0 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 17
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_4intsMonth_minuteTooLow() {
    LocalDateTime.of(2007, Month.JULY, 15, 12, -1);
}
 
Example 18
Source File: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_of_4intsMonth() {
    LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30);
    check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
}
 
Example 19
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_5ints_monthTooLow() {
    LocalDateTime.of(2007, 0, 15, 12, 30);
}
 
Example 20
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_of_5intsMonth_nullMonth() {
    LocalDateTime.of(2007, null, 15, 12, 30, 40);
}