本文整理了Java中com.datastax.driver.core.LocalDate.add()
方法的一些代码示例,展示了LocalDate.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.add()
方法的具体详情如下:
包路径:com.datastax.driver.core.LocalDate
类名称:LocalDate
方法名:add
[英]Return a new LocalDate with the specified (signed) amount of time added to (or subtracted from) the given Calendar field, based on the calendar's rules.
Note that adding any amount to a field smaller than Calendar#DAY_OF_MONTH will remain without effect, as this class does not keep time components.
See Calendar javadocs for more information.
[中]根据日历的规则,返回一个新的LocalDate,在给定的日历字段中添加(或减去)指定的(已签名的)时间量。
请注意,将任何金额添加到小于日历#DAY_OF_MONTH的字段将保持无效,因为此类不保留时间组件。
有关更多信息,请参阅日历javadocs。
代码示例来源: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.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);
}
}
内容来源于网络,如有侵权,请联系作者删除!