com.datastax.driver.core.LocalDate.fromYearMonthDay()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中com.datastax.driver.core.LocalDate.fromYearMonthDay()方法的一些代码示例,展示了LocalDate.fromYearMonthDay()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.fromYearMonthDay()方法的具体详情如下:
包路径:com.datastax.driver.core.LocalDate
类名称:LocalDate
方法名:fromYearMonthDay

LocalDate.fromYearMonthDay介绍

[英]Builds a new instance from a year/month/day specification.

This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but instead throw an IllegalArgumentException.
[中]根据年/月/日规范构建新实例。
该方法并不宽松,即“2014-12-32”不会被视为“2015-01-01”,而是抛出一个非法辩论例外。

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_add_and_subtract_months() {
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, 2)).hasYearMonthDay(1970, 3, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, 24)).hasYearMonthDay(1972, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, -5)).hasYearMonthDay(1969, 8, 1);
 assertThat(fromYearMonthDay(1, 1, 1).add(Calendar.MONTH, -1)).hasYearMonthDay(0, 12, 1);
 assertThat(fromYearMonthDay(0, 1, 1).add(Calendar.MONTH, -1)).hasYearMonthDay(-1, 12, 1);
 assertThat(fromYearMonthDay(-1, 12, 1).add(Calendar.MONTH, 1)).hasYearMonthDay(0, 1, 1);
 assertThat(fromYearMonthDay(0, 12, 1).add(Calendar.MONTH, 1)).hasYearMonthDay(1, 1, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_add_and_subtract_years() {
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, 1)).hasYearMonthDay(1971, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1)).hasYearMonthDay(1969, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1970)).hasYearMonthDay(0, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1971)).hasYearMonthDay(-1, 1, 1);
 assertThat(fromYearMonthDay(0, 5, 12).add(Calendar.YEAR, 1)).hasYearMonthDay(1, 5, 12);
 assertThat(fromYearMonthDay(-1, 5, 12).add(Calendar.YEAR, 1)).hasYearMonthDay(0, 5, 12);
 assertThat(fromYearMonthDay(-1, 5, 12).add(Calendar.YEAR, 2)).hasYearMonthDay(1, 5, 12);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
 public void should_add_and_subtract_days() {
  assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.DAY_OF_MONTH, 12))
    .hasYearMonthDay(1970, 1, 13);
  assertThat(fromYearMonthDay(1970, 3, 28).add(Calendar.DAY_OF_MONTH, -40))
    .hasYearMonthDay(1970, 2, 16);
  assertThat(fromYearMonthDay(1, 1, 1).add(Calendar.DAY_OF_MONTH, -2)).hasYearMonthDay(0, 12, 30);
  assertThat(fromYearMonthDay(0, 1, 1).add(Calendar.DAY_OF_MONTH, -2))
    .hasYearMonthDay(-1, 12, 30);
  assertThat(fromYearMonthDay(-1, 12, 31).add(Calendar.DAY_OF_MONTH, 4)).hasYearMonthDay(0, 1, 4);
  assertThat(fromYearMonthDay(0, 12, 25).add(Calendar.DAY_OF_MONTH, 14)).hasYearMonthDay(1, 1, 8);
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_build_from_year_month_day() {
 assertThat(fromYearMonthDay(1970, 1, 1))
   .hasMillisSinceEpoch(0)
   .hasDaysSinceEpoch(0)
 assertThat(fromYearMonthDay(1, 1, 1))
   .hasDaysSinceEpoch(-719162)
   .hasYearMonthDay(1, 1, 1)
   .hasToString("1-01-01");
 assertThat(fromYearMonthDay(0, 1, 1))
   .hasDaysSinceEpoch(-719162 - 366)
   .hasYearMonthDay(0, 1, 1)
   .hasToString("0-01-01");
 assertThat(fromYearMonthDay(-1, 1, 1))
   .hasDaysSinceEpoch(-719162 - 366 - 365)
   .hasYearMonthDay(-1, 1, 1)
  fromYearMonthDay(1970, 0, 1);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {
  fromYearMonthDay(1970, 13, 1);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {
  fromYearMonthDay(1970, 1, 0);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public LocalDate convert(Date in, Context context) throws Exception {
    if (in == null) return null;
    Calendar cal = Calendar.getInstance();
    cal.setTime(in);
    return LocalDate.fromYearMonthDay(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH));
  }
});

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public LocalDate convert(Year in, Context context) throws Exception {
    if (in == null) return null;
    return LocalDate.fromYearMonthDay(in.getValue(), 1, 1);
  }
});

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@DataProvider
public static Object[][] dataTypeSamples51() {
 return new Object[][] {
  {"Date()", LocalDate.fromYearMonthDay(2016, 5, 12)},
  {"Date()", "1999-07-29"},
  {"Time()", "18:30:41.554"},
  {"Time()", "18:30:41.554010034"}
 };
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public LocalDate convert(YearMonth in, Context context) throws Exception {
    if (in == null) return null;
    return LocalDate.fromYearMonthDay(in.getYear(), in.getMonthValue(), 1);
  }
});

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
  public com.datastax.driver.core.LocalDate convert(LocalDate source) {
    return com.datastax.driver.core.LocalDate.fromYearMonthDay(source.getYear(), source.getMonthValue(),
        source.getDayOfMonth());
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public LocalDate convert(java.time.LocalDate in, Context context) throws Exception {
    if (in == null) return null;
    return LocalDate.fromYearMonthDay(in.getYear(), in.getMonthValue(), in.getDayOfMonth());
  }
});

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
  public com.datastax.driver.core.LocalDate convert(LocalDate source) {
    return com.datastax.driver.core.LocalDate.fromYearMonthDay(source.getYear(), source.getMonthValue(),
        source.getDayOfMonth());
  }
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
  public com.datastax.driver.core.LocalDate convert(LocalDate source) {
    return com.datastax.driver.core.LocalDate.fromYearMonthDay(source.getYear(), source.getMonthOfYear(),
        source.getDayOfMonth());
  }
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_use_proleptic_parser() throws ParseException {
 DateRange parsed = DateRange.parse("[0000 TO 0000-01-02]");
 assertThat(parsed.getLowerBound().getTimestamp().getTime())
   // Use LocalDate as reference since it is also proleptic
   .isEqualTo(LocalDate.fromYearMonthDay(0, 1, 1).getMillisSinceEpoch());
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_add_and_subtract_years() {
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, 1)).hasYearMonthDay(1971, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1)).hasYearMonthDay(1969, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1970)).hasYearMonthDay(0, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.YEAR, -1971)).hasYearMonthDay(-1, 1, 1);
 assertThat(fromYearMonthDay(0, 5, 12).add(Calendar.YEAR, 1)).hasYearMonthDay(1, 5, 12);
 assertThat(fromYearMonthDay(-1, 5, 12).add(Calendar.YEAR, 1)).hasYearMonthDay(0, 5, 12);
 assertThat(fromYearMonthDay(-1, 5, 12).add(Calendar.YEAR, 2)).hasYearMonthDay(1, 5, 12);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_add_and_subtract_months() {
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, 2)).hasYearMonthDay(1970, 3, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, 24)).hasYearMonthDay(1972, 1, 1);
 assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.MONTH, -5)).hasYearMonthDay(1969, 8, 1);
 assertThat(fromYearMonthDay(1, 1, 1).add(Calendar.MONTH, -1)).hasYearMonthDay(0, 12, 1);
 assertThat(fromYearMonthDay(0, 1, 1).add(Calendar.MONTH, -1)).hasYearMonthDay(-1, 12, 1);
 assertThat(fromYearMonthDay(-1, 12, 1).add(Calendar.MONTH, 1)).hasYearMonthDay(0, 1, 1);
 assertThat(fromYearMonthDay(0, 12, 1).add(Calendar.MONTH, 1)).hasYearMonthDay(1, 1, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
 public void should_add_and_subtract_days() {
  assertThat(fromYearMonthDay(1970, 1, 1).add(Calendar.DAY_OF_MONTH, 12))
    .hasYearMonthDay(1970, 1, 13);
  assertThat(fromYearMonthDay(1970, 3, 28).add(Calendar.DAY_OF_MONTH, -40))
    .hasYearMonthDay(1970, 2, 16);
  assertThat(fromYearMonthDay(1, 1, 1).add(Calendar.DAY_OF_MONTH, -2)).hasYearMonthDay(0, 12, 30);
  assertThat(fromYearMonthDay(0, 1, 1).add(Calendar.DAY_OF_MONTH, -2))
    .hasYearMonthDay(-1, 12, 30);
  assertThat(fromYearMonthDay(-1, 12, 31).add(Calendar.DAY_OF_MONTH, 4)).hasYearMonthDay(0, 1, 4);
  assertThat(fromYearMonthDay(0, 12, 25).add(Calendar.DAY_OF_MONTH, 14)).hasYearMonthDay(1, 1, 8);
 }
}

代码示例来源:origin: zhicwu/cassandra-jdbc-driver

@Override
protected void setParameter(int paramIndex, Object paramValue) throws SQLException {
  String typeName = parameterMetaData.getParameterTypeName(paramIndex);
  Class javaClass = getDataTypeMappings().javaTypeFor(typeName);
  boolean replaceNullValue = this.cqlStmt.getConfiguration().replaceNullValue();
  if (javaClass != null) {
    paramValue = getDataTypeConverters().convert(paramValue, javaClass, replaceNullValue);
    // time is mapped by the driver to a primitive long, representing the number of nanoseconds since midnight
    if (CassandraDataType.TIME.getTypeName().equals(typeName) && paramValue instanceof Time) {
      Time time = (Time) paramValue;
      paramValue = new LocalTime(time).getMillisOfDay() * 1000000L;
    } else if (CassandraDataType.DATE.getTypeName().equals(typeName)
        && paramValue instanceof Date) {
      LocalDate localDate = LocalDate.fromDateFields((Date) paramValue);
      paramValue = com.datastax.driver.core.LocalDate.fromYearMonthDay(
          localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
    } else if (CassandraDataType.BLOB.getTypeName().equals(typeName)
        && paramValue instanceof byte[]) {
      paramValue = ByteBuffer.wrap((byte[]) paramValue);
    }
    parameters.put(paramIndex, paramValue);
  } else {
    super.setParameter(paramIndex, paramValue);
  }
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_build_from_year_month_day() {
 assertThat(fromYearMonthDay(1970, 1, 1))
   .hasMillisSinceEpoch(0)
   .hasDaysSinceEpoch(0)
 assertThat(fromYearMonthDay(1, 1, 1))
   .hasDaysSinceEpoch(-719162)
   .hasYearMonthDay(1, 1, 1)
   .hasToString("1-01-01");
 assertThat(fromYearMonthDay(0, 1, 1))
   .hasDaysSinceEpoch(-719162 - 366)
   .hasYearMonthDay(0, 1, 1)
   .hasToString("0-01-01");
 assertThat(fromYearMonthDay(-1, 1, 1))
   .hasDaysSinceEpoch(-719162 - 366 - 365)
   .hasYearMonthDay(-1, 1, 1)
  fromYearMonthDay(1970, 0, 1);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {
  fromYearMonthDay(1970, 13, 1);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {
  fromYearMonthDay(1970, 1, 0);
  Assertions.fail("Expected an IllegalArgumentException");
 } catch (IllegalArgumentException e) {

相关文章