本文整理了Java中com.datastax.driver.core.LocalDate.fromDaysSinceEpoch()
方法的一些代码示例,展示了LocalDate.fromDaysSinceEpoch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.fromDaysSinceEpoch()
方法的具体详情如下:
包路径:com.datastax.driver.core.LocalDate
类名称:LocalDate
方法名:fromDaysSinceEpoch
[英]Builds a new instance from a number of days since January 1st, 1970 GMT.
[中]从1970年1月1日格林尼治标准时间以来的天数中构建新实例。
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
protected LocalDate deserialize(Integer value) {
return LocalDate.fromDaysSinceEpoch(value);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0) return null;
int unsigned = IntCodec.instance.deserializeNoBoxing(bytes, protocolVersion);
int signed = CodecUtils.fromUnsignedToSignedInt(unsigned);
return LocalDate.fromDaysSinceEpoch(signed);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
.put(DataType.text(), "text")
.put(DataType.timestamp(), new Date(872835240000L))
.put(DataType.date(), LocalDate.fromDaysSinceEpoch(16071))
.put(DataType.time(), 54012123450000L)
.put(DataType.timeuuid(), UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66"))
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
return new Date(872835240000L);
case DATE:
return LocalDate.fromDaysSinceEpoch(0);
case TIME:
return 54012123450000L;
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit")
public void should_build_from_days_since_epoch() {
assertThat(fromDaysSinceEpoch(0))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
.hasYearMonthDay(1970, 1, 1)
.hasToString("1970-01-01");
assertThat(fromDaysSinceEpoch(10))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(10))
.hasDaysSinceEpoch(10)
.hasYearMonthDay(1970, 1, 11)
.hasToString("1970-01-11");
assertThat(fromDaysSinceEpoch(-10))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(-10))
.hasDaysSinceEpoch(-10)
.hasYearMonthDay(1969, 12, 22)
.hasToString("1969-12-22");
assertThat(fromDaysSinceEpoch(Integer.MAX_VALUE))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(Integer.MAX_VALUE))
.hasDaysSinceEpoch(Integer.MAX_VALUE)
.hasYearMonthDay(5881580, 7, 11)
.hasToString("5881580-07-11");
assertThat(fromDaysSinceEpoch(Integer.MIN_VALUE))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(Integer.MIN_VALUE))
.hasDaysSinceEpoch(Integer.MIN_VALUE)
.hasYearMonthDay(-5877641, 6, 23)
.hasToString("-5877641-06-23");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
return new Date(1352288289L);
case DATE:
return LocalDate.fromDaysSinceEpoch(0);
case TIME:
return 54012123450000L;
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@DataProvider
public static Object[][] value() {
return new Object[][] {
{ByteBuffer.allocate(0), TypeCodec.blob()},
{Boolean.TRUE, TypeCodec.cboolean()},
{(short) 42, TypeCodec.smallInt()},
{(byte) 42, TypeCodec.tinyInt()},
{42, TypeCodec.cint()},
{42L, TypeCodec.bigint()},
{42D, TypeCodec.cdouble()},
{42F, TypeCodec.cfloat()},
{new BigInteger("1234"), TypeCodec.varint()},
{new BigDecimal("123.45"), TypeCodec.decimal()},
{"foo", TypeCodec.varchar()},
{new Date(42), TypeCodec.timestamp()},
{LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()},
{UUID.randomUUID(), TypeCodec.uuid()},
{mock(InetAddress.class), TypeCodec.inet()},
{Duration.from("1mo2d3h"), TypeCodec.duration()}
};
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Override
protected LocalDate deserialize(Integer value) {
return LocalDate.fromDaysSinceEpoch(value);
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0)
return null;
int unsigned = IntCodec.instance.deserializeNoBoxing(bytes, protocolVersion);
int signed = CodecUtils.fromUnsignedToSignedInt(unsigned);
return LocalDate.fromDaysSinceEpoch(signed);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@DataProvider
public static Object[][] cqlAndValue() {
return new Object[][] {
{DataType.blob(), ByteBuffer.allocate(0), TypeCodec.blob()},
{DataType.cboolean(), true, TypeCodec.cboolean()},
{DataType.smallint(), (short) 42, TypeCodec.smallInt()},
{DataType.tinyint(), (byte) 42, TypeCodec.tinyInt()},
{DataType.cint(), 42, TypeCodec.cint()},
{DataType.bigint(), 42L, TypeCodec.bigint()},
{DataType.counter(), 42L, TypeCodec.counter()},
{DataType.cdouble(), 42D, TypeCodec.cdouble()},
{DataType.cfloat(), 42F, TypeCodec.cfloat()},
{DataType.varint(), new BigInteger("1234"), TypeCodec.varint()},
{DataType.decimal(), new BigDecimal("123.45"), TypeCodec.decimal()},
{DataType.varchar(), "foo", TypeCodec.varchar()},
{DataType.ascii(), "foo", TypeCodec.ascii()},
{DataType.timestamp(), new Date(42), TypeCodec.timestamp()},
{DataType.date(), LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()},
{DataType.time(), 42L, TypeCodec.time()},
{DataType.uuid(), UUID.randomUUID(), TypeCodec.uuid()},
{DataType.timeuuid(), UUID.randomUUID(), TypeCodec.timeUUID()},
{DataType.inet(), mock(InetAddress.class), TypeCodec.inet()},
{DataType.duration(), Duration.from("1mo2d3h"), TypeCodec.duration()}
};
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
@Override
public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0)
return null;
int unsigned = IntCodec.instance.deserializeNoBoxing(bytes, protocolVersion);
int signed = CodecUtils.fromUnsignedToSignedInt(unsigned);
return LocalDate.fromDaysSinceEpoch(signed);
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
@Override
public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0)
return null;
int unsigned = IntCodec.instance.deserializeNoBoxing(bytes, protocolVersion);
int signed = CodecUtils.fromUnsignedToSignedInt(unsigned);
return LocalDate.fromDaysSinceEpoch(signed);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
new TestValue(LocalDate.fromDaysSinceEpoch(16071), "'2014-01-01'", "'2014-01-01'"),
new TestValue(LocalDate.fromDaysSinceEpoch(0), "'1970-01-01'", "'1970-01-01'"),
new TestValue(
LocalDate.fromDaysSinceEpoch((int) (2147483648L - (1L << 31))),
"'2147483648'",
"'1970-01-01'"),
new TestValue(
LocalDate.fromDaysSinceEpoch((int) (0 - (1L << 31))), "0", "'-5877641-06-23'"),
new TestValue(null, null, "NULL"),
new TestValue(null, "null", "NULL"),
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Test(groups = "unit")
public void should_build_from_days_since_epoch() {
assertThat(fromDaysSinceEpoch(0))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
.hasYearMonthDay(1970, 1, 1)
.hasToString("1970-01-01");
assertThat(fromDaysSinceEpoch(10))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(10))
.hasDaysSinceEpoch(10)
.hasYearMonthDay(1970, 1, 11)
.hasToString("1970-01-11");
assertThat(fromDaysSinceEpoch(-10))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(-10))
.hasDaysSinceEpoch(-10)
.hasYearMonthDay(1969, 12, 22)
.hasToString("1969-12-22");
assertThat(fromDaysSinceEpoch(Integer.MAX_VALUE))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(Integer.MAX_VALUE))
.hasDaysSinceEpoch(Integer.MAX_VALUE)
.hasYearMonthDay(5881580, 7, 11)
.hasToString("5881580-07-11");
assertThat(fromDaysSinceEpoch(Integer.MIN_VALUE))
.hasMillisSinceEpoch(TimeUnit.DAYS.toMillis(Integer.MIN_VALUE))
.hasDaysSinceEpoch(Integer.MIN_VALUE)
.hasYearMonthDay(-5877641, 6, 23)
.hasToString("-5877641-06-23");
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@DataProvider
public static Object[][] value() {
return new Object[][] {
{ByteBuffer.allocate(0), TypeCodec.blob()},
{Boolean.TRUE, TypeCodec.cboolean()},
{(short) 42, TypeCodec.smallInt()},
{(byte) 42, TypeCodec.tinyInt()},
{42, TypeCodec.cint()},
{42L, TypeCodec.bigint()},
{42D, TypeCodec.cdouble()},
{42F, TypeCodec.cfloat()},
{new BigInteger("1234"), TypeCodec.varint()},
{new BigDecimal("123.45"), TypeCodec.decimal()},
{"foo", TypeCodec.varchar()},
{new Date(42), TypeCodec.timestamp()},
{LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()},
{UUID.randomUUID(), TypeCodec.uuid()},
{mock(InetAddress.class), TypeCodec.inet()},
{Duration.from("1mo2d3h"), TypeCodec.duration()}
};
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@DataProvider
public static Object[][] cqlAndValue() {
return new Object[][] {
{DataType.blob(), ByteBuffer.allocate(0), TypeCodec.blob()},
{DataType.cboolean(), true, TypeCodec.cboolean()},
{DataType.smallint(), (short) 42, TypeCodec.smallInt()},
{DataType.tinyint(), (byte) 42, TypeCodec.tinyInt()},
{DataType.cint(), 42, TypeCodec.cint()},
{DataType.bigint(), 42L, TypeCodec.bigint()},
{DataType.counter(), 42L, TypeCodec.counter()},
{DataType.cdouble(), 42D, TypeCodec.cdouble()},
{DataType.cfloat(), 42F, TypeCodec.cfloat()},
{DataType.varint(), new BigInteger("1234"), TypeCodec.varint()},
{DataType.decimal(), new BigDecimal("123.45"), TypeCodec.decimal()},
{DataType.varchar(), "foo", TypeCodec.varchar()},
{DataType.ascii(), "foo", TypeCodec.ascii()},
{DataType.timestamp(), new Date(42), TypeCodec.timestamp()},
{DataType.date(), LocalDate.fromDaysSinceEpoch(42), TypeCodec.date()},
{DataType.time(), 42L, TypeCodec.time()},
{DataType.uuid(), UUID.randomUUID(), TypeCodec.uuid()},
{DataType.timeuuid(), UUID.randomUUID(), TypeCodec.timeUUID()},
{DataType.inet(), mock(InetAddress.class), TypeCodec.inet()},
{DataType.duration(), Duration.from("1mo2d3h"), TypeCodec.duration()}
};
}
内容来源于网络,如有侵权,请联系作者删除!