本文整理了Java中java.time.Period.of()
方法的一些代码示例,展示了Period.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Period.of()
方法的具体详情如下:
包路径:java.time.Period
类名称:Period
方法名:of
[英]Obtains a Period representing a number of years, months and days.
This creates an instance based on years, months and days.
[中]获取表示年、月和日数的期间。
这将基于年、月和日创建一个实例。
代码示例来源:origin: wildfly/wildfly
@Override
public Period readObject(ObjectInput input) throws IOException, ClassNotFoundException {
int years = input.readInt();
int months = input.readInt();
int days = input.readInt();
return Period.of(years, months, days);
}
代码示例来源:origin: OpenGamma/Strata
public void test_of_tooBig() {
assertThrowsIllegalArg(() -> Frequency.of(Period.ofMonths(12001)));
assertThrowsIllegalArg(() -> Frequency.of(Period.ofMonths(Integer.MAX_VALUE)));
assertThrowsIllegalArg(() -> Frequency.of(Period.ofYears(1001)));
assertThrowsIllegalArg(() -> Frequency.of(Period.ofYears(Integer.MAX_VALUE)));
assertThrowsIllegalArg(() -> Frequency.ofMonths(12001), "Months must not exceed 12,000");
assertThrowsIllegalArg(() -> Frequency.ofMonths(Integer.MAX_VALUE));
assertThrowsIllegalArg(() -> Frequency.ofYears(1001), "Years must not exceed 1,000");
assertThrowsIllegalArg(() -> Frequency.ofYears(Integer.MAX_VALUE));
assertThrowsIllegalArg(() -> Frequency.of(Period.of(10000, 0, 1)));
}
代码示例来源:origin: neo4j/neo4j
private Period nextPeriodRaw()
{
return Period.of( generator.nextInt(), generator.nextInt( 12 ), generator.nextInt( 28 ) );
}
代码示例来源:origin: jdbi/jdbi
@Override
public Optional<ColumnMapper<?>> build(Type type, ConfigRegistry config) {
if (type != Period.class) {
return Optional.empty();
}
return Optional.of((r, i, c) -> {
final Object obj = r.getObject(i);
if (obj == null) {
return null;
}
if (!(obj instanceof PGInterval)) {
throw new IllegalArgumentException(String.format("got non-pginterval %s", obj));
}
final PGInterval interval = (PGInterval) obj;
if (interval.getHours() != 0 || interval.getMinutes() != 0 || interval.getSeconds() != 0) {
throw new IllegalArgumentException(
String.format("pginterval \"%s\" is too granular to be represented as period",
interval.getValue()));
}
return Period.of(interval.getYears(), interval.getMonths(), interval.getDays());
});
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testReadsViaFluentAPI() {
List<Period> periods = handle.createQuery("select foo from intervals where id = 1 or id = 2 order by id")
.mapTo(Period.class)
.list();
assertThat(periods).isEqualTo(ImmutableList.of(
Period.of(1, 9, 40),
Period.of(0, 0, 7)
));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testNegativePeriod() {
handle.execute("insert into intervals(id, foo) values(?, interval '-3 years -1 month 2 days')", 7);
final Period p = handle.createQuery("select foo from intervals where id=?")
.bind(0, 7)
.mapTo(Period.class)
.findOnly();
assertThat(p).isEqualTo(Period.of(-3, -1, 2));
}
}
代码示例来源:origin: neo4j/neo4j
private List<InputEntity> randomNodeData()
{
List<InputEntity> nodes = new ArrayList<>();
for ( int i = 0; i < 300; i++ )
{
InputEntity node = new InputEntity();
node.id( UUID.randomUUID().toString(), Group.GLOBAL );
node.property( "name", "Node " + i );
node.property( "pointA", "\" { x : -4.2, y : " + i + ", crs: WGS-84 } \"" );
node.property( "pointB", "\" { x : -8, y : " + i + " } \"" );
node.property( "date", LocalDate.of( 2018, i % 12 + 1, i % 28 + 1 ) );
node.property( "time", OffsetTime.of( 1, i % 60, 0, 0, ZoneOffset.ofHours( 9 ) ) );
node.property( "dateTime",
ZonedDateTime.of( 2011, 9, 11, 8, i % 60, 0, 0, ZoneId.of( "Europe/Stockholm" ) ) );
node.property( "dateTime2",
LocalDateTime.of( 2011, 9, 11, 8, i % 60, 0, 0 ) ); // No zone specified
node.property( "localTime", LocalTime.of( 1, i % 60, 0 ) );
node.property( "localDateTime", LocalDateTime.of( 2011, 9, 11, 8, i % 60 ) );
node.property( "duration", Period.of( 2, -3, i % 30 ) );
node.labels( randomLabels( random.random() ) );
nodes.add( node );
}
return nodes;
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testTrivialPeriod() {
handle.execute("insert into intervals(id, foo) values(?, ?)", 4, Period.of(0, 0, 0));
Period p = handle.createQuery("select foo from intervals where id=?")
.bind(0, 4)
.mapTo(Period.class)
.findOnly();
assertThat(p.isZero());
}
代码示例来源:origin: apache/tinkerpop
@Override
protected Period readValue(final ByteBuf buffer, final GraphBinaryReader context) throws SerializationException {
return Period.of(buffer.readInt(), buffer.readInt(), buffer.readInt());
}
代码示例来源:origin: apache/tinkerpop
@Override
public <I extends InputShim> Period read(final KryoShim<I, ?> kryo, final I input, final Class<Period> clazz) {
return Period.of(input.readInt(), input.readInt(), input.readInt());
}
}
代码示例来源:origin: benas/random-beans
@Override
public Period getRandomValue() {
Year randomYear = yearRandomizer.getRandomValue();
Month randomMonth = monthRandomizer.getRandomValue();
int randomDay = dayRandomizer.getRandomValue();
return Period.of(randomYear.getValue(), randomMonth.getValue(), randomDay);
}
}
代码示例来源:origin: pholser/junit-quickcheck
private Period fromBigInteger(BigInteger period) {
BigInteger[] monthsAndDays = period.divideAndRemainder(THIRTY_ONE);
BigInteger[] yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE);
return Period.of(
yearsAndMonths[0].intValueExact(),
yearsAndMonths[1].intValueExact(),
monthsAndDays[1].intValueExact());
}
}
代码示例来源:origin: neo4j/neo4j
assertLowest( DurationValue.duration( Period.of( Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE ) ) );
代码示例来源:origin: apache/tinkerpop
addExtendedEntry(OffsetDateTime.parse("2007-12-03T10:15:30+01:00"), "OffsetDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(OffsetTime.parse("10:15:30+01:00"), "OffsetTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Period.of(1, 6, 15), "Period", "The following example is a `Period` of one year, six months and fifteen days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
代码示例来源:origin: com.esotericsoftware/kryo
public Period read (Kryo kryo, Input in, Class<Period> type) {
int years = in.readInt(true);
int months = in.readInt(true);
int days = in.readInt(true);
return Period.of(years, months, days);
}
}
代码示例来源:origin: com.esotericsoftware/kryo-shaded
public Period read (Kryo kryo, Input in, Class<Period> type) {
int years = in.readInt(true);
int months = in.readInt(true);
int days = in.readInt(true);
return Period.of(years, months, days);
}
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-core
@Override
public <I extends InputShim> Period read(final KryoShim<I, ?> kryo, final I input, final Class<Period> clazz) {
return Period.of(input.readInt(), input.readInt(), input.readInt());
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_of_additionConventionNone() {
PeriodAdjustment test = PeriodAdjustment.of(Period.of(1, 2, 3), PAC_NONE, BDA_NONE);
assertEquals(test.getPeriod(), Period.of(1, 2, 3));
assertEquals(test.getAdditionConvention(), PAC_NONE);
assertEquals(test.getAdjustment(), BDA_NONE);
assertEquals(test.toString(), "P1Y2M3D");
}
代码示例来源:origin: OpenGamma/Strata
public void test_of_additionConventionNone() {
TenorAdjustment test = TenorAdjustment.of(Tenor.of(Period.of(1, 2, 3)), PAC_NONE, BDA_NONE);
assertEquals(test.getTenor(), Tenor.of(Period.of(1, 2, 3)));
assertEquals(test.getAdditionConvention(), PAC_NONE);
assertEquals(test.getAdjustment(), BDA_NONE);
assertEquals(test.toString(), "1Y2M3D");
}
代码示例来源:origin: OpenGamma/Strata
public void test_eventsPerYear_bad() {
assertThrowsIllegalArg(() -> Frequency.ofDays(3).eventsPerYear());
assertThrowsIllegalArg(() -> Frequency.ofWeeks(3).eventsPerYear());
assertThrowsIllegalArg(() -> Frequency.ofWeeks(104).eventsPerYear());
assertThrowsIllegalArg(() -> Frequency.ofMonths(5).eventsPerYear());
assertThrowsIllegalArg(() -> Frequency.ofMonths(24).eventsPerYear());
assertThrowsIllegalArg(() -> Frequency.of(Period.of(2, 2, 2)).eventsPerYear());
}
内容来源于网络,如有侵权,请联系作者删除!