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

The following examples show how to use java.time.LocalDateTime#equals() . 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: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test.truncatedTo(ChronoUnit.SECONDS),
                 expected.truncatedTo(ChronoUnit.SECONDS));
}
 
Example 2
Source File: TCKLocalDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 3
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 4
Source File: SimpleIndicator.java    From FX-AlgorithmTrading with MIT License 5 votes vote down vote up
/**
 * 時刻データを追加します。同一更新時刻で1回だけ実行します
 * @param newDateTime
 */
public void addTimeData(LocalDateTime newDateTime) {
    // 念のため同一時刻の確認
    LocalDateTime lastTime = getLastDateTime();
    if (!newDateTime.equals(lastTime)) {
        dateTimeList.add(newDateTime);
    }
}
 
Example 5
Source File: LocalDateTimeTest.java    From jackcess with Apache License 2.0 5 votes vote down vote up
private static void doTestZoneId(final ZoneId zoneId) throws Exception
{
  final TimeZone tz = TimeZone.getTimeZone(zoneId);
  ColumnImpl col = new ColumnImpl(null, null, DataType.SHORT_DATE_TIME, 0, 0, 0) {
    @Override
    public TimeZone getTimeZone() { return tz; }
    @Override
    public ZoneId getZoneId() { return zoneId; }
    @Override
    public ColumnImpl.DateTimeFactory getDateTimeFactory() {
      return getDateTimeFactory(DateTimeType.LOCAL_DATE_TIME);
    }
  };

  SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
  df.setTimeZone(tz);

  long startDate = df.parse("2012.01.01").getTime();
  long endDate = df.parse("2013.01.01").getTime();

  Calendar curCal = Calendar.getInstance(tz);
  curCal.setTimeInMillis(startDate);

  DateTimeFormatter sdf = DateTimeFormatter.ofPattern("uuuu.MM.dd HH:mm:ss");

  while(curCal.getTimeInMillis() < endDate) {
    Date curDate = curCal.getTime();
    LocalDateTime curLdt = LocalDateTime.ofInstant(
        Instant.ofEpochMilli(curDate.getTime()), zoneId);
    LocalDateTime newLdt = ColumnImpl.ldtFromLocalDateDouble(
        col.toDateDouble(curDate));
    if(!curLdt.equals(newLdt)) {
      System.out.println("FOO " + curLdt + " " + newLdt);
      assertEquals(sdf.format(curLdt), sdf.format(newLdt));
    }
    curCal.add(Calendar.MINUTE, 30);
  }
}
 
Example 6
Source File: TCKLocalDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 7
Source File: TCKLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 8
Source File: TCKLocalDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 9
Source File: TCKLocalDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 10
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 11
Source File: MeteoDataInfo.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Interpolate data to a station point
 *
 * @param varName Variable name
 * @param x X coordinate of the station
 * @param y Y coordinate of the station
 * @param z Z coordinate of the station
 * @param t Time coordinate of the station
 * @return Interpolated value
 */
public double toStation(String varName, double x, double y, double z, LocalDateTime t) {
    List<LocalDateTime> times = this.getDataInfo().getTimes();
    int tnum = times.size();
    if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
        return this.getDataInfo().getMissingValue();
    }

    double ivalue = this.getDataInfo().getMissingValue();
    double v_t1, v_t2;
    for (int i = 0; i < tnum; i++) {
        if (t.equals(times.get(i))) {
            ivalue = this.toStation(varName, x, y, z, i);
            break;
        }
        if (t.isBefore(times.get(i))) {
            v_t1 = this.toStation(varName, x, y, z, i - 1);
            v_t2 = this.toStation(varName, x, y, z, i);
            int h = (int)Duration.between(times.get(i - 1), t).toHours();
            int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours();
            ivalue = (v_t2 - v_t1) * h / th + v_t1;
            break;
        }
    }

    return ivalue;
}
 
Example 12
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 13
Source File: TCKLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 14
Source File: TCKLocalDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 15
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 16
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 17
Source File: MeteoDataInfo.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Interpolate data to a station point
 *
 * @param varNames Variable names
 * @param x X coordinate of the station
 * @param y Y coordinate of the station
 * @param z Z coordinate of the station
 * @param t Time coordinate of the station
 * @return Interpolated values
 */
public List<Double> toStation(List<String> varNames, double x, double y, double z, LocalDateTime t) {
    List<LocalDateTime> times = this.getDataInfo().getTimes();
    int tnum = times.size();
    if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
        return null;
    }

    List<Double> ivalues = new ArrayList<>();
    double v_t1, v_t2;
    List<Double> v_t1s, v_t2s;
    for (int i = 0; i < tnum; i++) {
        if (t.equals(times.get(i))) {
            ivalues = this.toStation(varNames, x, y, z, i);
            break;
        }
        if (t.isBefore(times.get(i))) {
            v_t1s = this.toStation(varNames, x, y, z, i - 1);
            v_t2s = this.toStation(varNames, x, y, z, i);
            int h = (int)Duration.between(times.get(i - 1), t).toHours();
            int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours();
            for (int j = 0; j < v_t1s.size(); j++) {
                v_t1 = v_t1s.get(j);
                v_t2 = v_t2s.get(j);
                ivalues.add((v_t2 - v_t1) * h / th + v_t1);
            }
            break;
        }
    }

    return ivalues;
}
 
Example 18
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
    LocalDateTime test = LocalDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalDateTime.now(Clock.system(zone));
        test = LocalDateTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 19
Source File: Main.java    From Java-11-Cookbook-Second-Edition with MIT License 4 votes vote down vote up
private static void compare(LocalDateTime time1, LocalDateTime time2){
    if ( !time1.equals(time2) ) {
        throw new AssertionError(String.format("DateTime 1 %s is not equal to DateTime 2 %s", 
            time1, time2));
    }
}
 
Example 20
Source File: LocalDateTimeComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equalToReference(LocalDateTime candidate) {
	return candidate.equals(reference);
}