Search in sources :

Example 31 with Period

use of java.time.Period in project flink by apache.

the class ExpressionConverterTest method testIntervalYearMonth.

@Test
public void testIntervalYearMonth() {
    Period value = Period.of(999, 3, 1);
    RexNode rex = converter.visit(valueLiteral(value));
    assertThat(((RexLiteral) rex).getValueAs(BigDecimal.class), equalTo(BigDecimal.valueOf(value.toTotalMonths())));
    // TODO planner ignores the precision
    assertThat(rex.getType().getSqlTypeName(), equalTo(SqlTypeName.INTERVAL_YEAR_MONTH));
    assertThat(rex.getType().getPrecision(), // year precision, should actually be 3
    equalTo(2));
}
Also used : Period(java.time.Period) BigDecimal(java.math.BigDecimal) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 32 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class PeriodStyleTests method printIso8601ShouldPrint.

@Test
void printIso8601ShouldPrint() {
    Period period = Period.parse("-P-6M+3D");
    assertThat(PeriodStyle.ISO8601.print(period)).isEqualTo("P6M-3D");
}
Also used : Period(java.time.Period) Test(org.junit.jupiter.api.Test)

Example 33 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class PeriodStyleTests method printIso8601ShouldIgnoreUnit.

@Test
void printIso8601ShouldIgnoreUnit() {
    Period period = Period.parse("-P3Y");
    assertThat(PeriodStyle.ISO8601.print(period, ChronoUnit.DAYS)).isEqualTo("P-3Y");
}
Also used : Period(java.time.Period) Test(org.junit.jupiter.api.Test)

Example 34 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class PeriodStyleTests method printSimpleWhenZeroWithUnitShouldPrintInUnit.

@Test
void printSimpleWhenZeroWithUnitShouldPrintInUnit() {
    Period period = Period.ofYears(0);
    assertThat(PeriodStyle.SIMPLE.print(period, ChronoUnit.YEARS)).isEqualTo("0y");
}
Also used : Period(java.time.Period) Test(org.junit.jupiter.api.Test)

Example 35 with Period

use of java.time.Period in project spring-boot by spring-projects.

the class PeriodStyleTests method printSimpleWhenNonZeroShouldIgnoreUnit.

@Test
void printSimpleWhenNonZeroShouldIgnoreUnit() {
    Period period = Period.of(1, 2, 3);
    assertThat(PeriodStyle.SIMPLE.print(period, ChronoUnit.YEARS)).isEqualTo("1y2m3d");
}
Also used : Period(java.time.Period) Test(org.junit.jupiter.api.Test)

Aggregations

Period (java.time.Period)108 Test (org.junit.Test)38 Test (org.testng.annotations.Test)27 LocalDate (java.time.LocalDate)20 Duration (java.time.Duration)9 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 LocalDateTime (java.time.LocalDateTime)7 ZonedDateTime (java.time.ZonedDateTime)7 Date (java.util.Date)6 LocalTime (java.time.LocalTime)5 ZoneId (java.time.ZoneId)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 List (java.util.List)5 Test (org.junit.jupiter.api.Test)5 Instant (java.time.Instant)4 DateTimeParseException (java.time.format.DateTimeParseException)4 Temporal (java.time.temporal.Temporal)4 TemporalAmount (java.time.temporal.TemporalAmount)4 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4