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

The following examples show how to use java.time.LocalDateTime#equals() . These examples are extracted from open source projects. 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
/**
 * 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 2
Source Project: j2objc   File: TCKLocalDateTime.java    License: 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 3
/**
 * 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 4
@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 5
@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 6
@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
@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
@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
@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 10
@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
@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 12
@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
@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
@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 Project: jackcess   File: LocalDateTimeTest.java    License: 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 16
Source Project: FX-AlgorithmTrading   File: SimpleIndicator.java    License: 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 17
@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 18
@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 Project: flink   File: LocalDateTimeComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean equalToReference(LocalDateTime candidate) {
	return candidate.equals(reference);
}
 
Example 20
Source Project: Java-11-Cookbook-Second-Edition   File: Main.java    License: 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));
    }
}