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

The following examples show how to use java.time.LocalDateTime#minusNanos() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 2
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 3
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 4
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 5
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 6
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 7
public IMessage getTestDate() throws ParseException{
	IMessage message = messageHelper.getMessageFactory().createMessage("testDate", "ITCH");
	String dateString = "20160627";
	String timeString = "10:10:11";
       TimeZone timeZone = TimeZone.getTimeZone("UTC");
    DateFormat df = new SimpleDateFormat("yyyyMMdd");
       df.setTimeZone(timeZone);
	DateFormat tf = new SimpleDateFormat("HH:mm:ss");
       tf.setTimeZone(timeZone);
	Date startDate=df.parse(dateString);
    Date startTime=tf.parse(timeString);
       Date days = new Date(100);
       LocalDateTime localDays = DateTimeUtility.toLocalDateTime(days);
       localDays = localDays.minusNanos(localDays.getNano());
       message.addField("Date", DateTimeUtility.toLocalDate(startDate));
       message.addField("Time", DateTimeUtility.toLocalTime(startTime));
       message.addField("Days", DateTimeUtility.toLocalDate(startDate));
       message.addField("STUB", DateTimeUtility.toLocalDateTime(days));
       
       DateTimeFormatter extTimeFormatter = DateTimeUtility.createFormatter("HH:mm:ss.SSS");
       LocalTime extTime = LocalTime.parse("10:10:11.123", extTimeFormatter);
       message.addField("ExtTime", extTime);
       
       DateTimeFormatter dateTimeFormatter = DateTimeUtility.createFormatter("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
       ZonedDateTime zonedDateTime = DateTimeUtility.toZonedDateTime(dateTimeFormatter.parse("2019-12-31T01:02:03.123456Z"));
       message.addField("Date_Time", DateTimeUtility.toLocalDateTime(zonedDateTime));
       // LocalDateTime localDays = DateTimeUtility.toLocalDateTime(100);
       // localDays = localDays.minusNanos(localDays.getNano());
       // message.addField("Date", DateTimeUtility.toLocalDateTime(startDate));
       // message.addField("Time", DateTimeUtility.toLocalDateTime(startTime));
       // message.addField("Days", localDays);
       // message.addField("STUB", DateTimeUtility.toLocalDateTime(100));
	return messageHelper.prepareMessageToEncode(message, null);
}
 
Example 8
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 9
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 10
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 11
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 12
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 13
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 14
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 15
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 16
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 17
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 18
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
Example 19
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusNanos(nanoseconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 20
Source Project: j2objc   File: TCKLocalDateTime.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_minusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.minusNanos(500000000);
        nanos -= 500000000;

        if (nanos < 0) {
            sec--;
            nanos += 1000000000;

            if (sec == -1) {
                min--;
                sec += 60;

                if (min == -1) {
                    hour--;
                    min += 60;

                    if (hour == -1) {
                        hour += 24;
                    }
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}