org.joda.time.LocalDate.now()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(181)

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

LocalDate.now介绍

[英]Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.
[中]使用默认时区中的ISOChronology获取设置为当前系统毫秒时间的LocalDate。

代码示例

代码示例来源:origin: dlew/joda-time-android

/**
 * See {@link android.text.format.DateUtils#isToday} for full docs.
 *
 * @return true if the supplied when is today else false
 */
public static boolean isToday(ReadableInstant time) {
  return LocalDate.now().compareTo(new LocalDate(time)) == 0;
}

代码示例来源:origin: dlew/joda-time-android

private void sampleLocalDate() {
  List<String> text = new ArrayList<String>();
  LocalDate now = LocalDate.now();
  text.add("Now: " + now);
  text.add("Now + 2 days: " + now.plusDays(2));
  text.add("Now + 3 months: " + now.plusMonths(3));
  addSample("LocalDate", text);
}

代码示例来源:origin: dlew/joda-time-android

private void sampleIsToday() {
  List<String> text = new ArrayList<String>();
  LocalDate today = LocalDate.now();
  text.add("Today: " + DateUtils.isToday(today));
  text.add("Tomorrow: " + DateUtils.isToday(today.plusDays(1)));
  text.add("Yesterday: " + DateUtils.isToday(today.minusDays(1)));
  addSample("DateUtils.isToday()", text);
}

代码示例来源:origin: dlew/joda-time-android

/**
 * See {@link android.text.format.DateUtils#isToday} for full docs.
 *
 * @return true if the supplied when is today else false
 */
public static boolean isToday(ReadablePartial time) {
  if (!time.isSupported(DateTimeFieldType.dayOfMonth())
    || !time.isSupported(DateTimeFieldType.monthOfYear())
    || !time.isSupported(DateTimeFieldType.year())) {
    throw new IllegalArgumentException("isToday() must be passed a ReadablePartial that supports day of " +
      "month, month of year and year.");
  }
  LocalDate localDate = time instanceof LocalDate ? (LocalDate) time : new LocalDate(time);
  return LocalDate.now().compareTo(localDate) == 0;
}

代码示例来源:origin: apache/avro

@Test
public void testWithValues() throws IOException {
  LogicalTypesWithDefaults instanceOfGeneratedClass = LogicalTypesWithDefaults.newBuilder()
      .setNullableDate(LocalDate.now())
      .setNonNullDate(LocalDate.now())
      .build();
  verifySerDeAndStandardMethods(instanceOfGeneratedClass);
}

代码示例来源:origin: apache/avro

@Test(expected = MissingSchemaException.class)
 public void testSpecificByteArrayIncompatibleWithoutLogicalTypes() throws IOException {
  TestRecordWithLogicalTypes withLogicalTypes = new TestRecordWithLogicalTypes(
    true,
    34,
    35L,
    3.14F,
    3019.34,
    null,
    LocalDate.now(),
    LocalTime.now(),
    DateTime.now().withZone(DateTimeZone.UTC),
    new BigDecimal("123.45")
  );

  ByteBuffer b = withLogicalTypes.toByteBuffer();
  TestRecordWithoutLogicalTypes.fromByteBuffer(b);
 }
}

代码示例来源:origin: apache/avro

@Test
public void testNullableLogicalTypeInArray() {
 final NullableLogicalTypesArray logicalTypesArray =
  NullableLogicalTypesArray.newBuilder().setArrayOfLogicalType(Collections.singletonList(LocalDate.now())).build();
 verifySerDeAndStandardMethods(logicalTypesArray);
}

代码示例来源:origin: apache/avro

@Test
public void testSpecificToFromByteBufferWithLogicalTypes() throws IOException {
 TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(
   true,
   34,
   35L,
   3.14F,
   3019.34,
   null,
   LocalDate.now(),
   LocalTime.now(),
   DateTime.now().withZone(DateTimeZone.UTC),
   new BigDecimal("123.45")
 );
 ByteBuffer b = record.toByteBuffer();
 TestRecordWithLogicalTypes copy = TestRecordWithLogicalTypes.fromByteBuffer(b);
 assertEquals(record, copy);
}

代码示例来源:origin: apache/avro

@Test
public void testRecordWithLogicalTypes() throws IOException {
 TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(
   true,
   34,
   35L,
   3.14F,
   3019.34,
   null,
   LocalDate.now(),
   LocalTime.now(),
   DateTime.now().withZone(DateTimeZone.UTC),
   new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN)
 );
 File data = write(TestRecordWithLogicalTypes.getClassSchema(), record);
 List<TestRecordWithLogicalTypes> actual = read(
   TestRecordWithLogicalTypes.getClassSchema(), data);
 Assert.assertEquals("Should match written record", record, actual.get(0));
}
@Test

代码示例来源:origin: apache/avro

@Test
public void testDefaultValueOfNullableField() throws IOException {
  LogicalTypesWithDefaults instanceOfGeneratedClass = LogicalTypesWithDefaults.newBuilder()
      .setNonNullDate(LocalDate.now())
      .build();
  verifySerDeAndStandardMethods(instanceOfGeneratedClass);
}

代码示例来源:origin: apache/avro

@Test
public void testDate() throws IOException {
  NullableLogicalTypes instanceOfGeneratedClass = NullableLogicalTypes.newBuilder()
      .setNullableDate(LocalDate.now())
      .build();
  verifySerDeAndStandardMethods(instanceOfGeneratedClass);
}

代码示例来源:origin: apache/avro

@Test
public void testNullableLogicalTypeInRecordInArray() {
 final NestedLogicalTypesArray nestedLogicalTypesArray =
  NestedLogicalTypesArray.newBuilder().setArrayOfRecords(Collections.singletonList(
   RecordInArray.newBuilder().setNullableDateField(LocalDate.now()).build())).build();
 verifySerDeAndStandardMethods(nestedLogicalTypesArray);
}

代码示例来源:origin: apache/avro

@Test
 public void testNullableLogicalTypeInRecordInMap() {
  final NestedLogicalTypesMap nestedLogicalTypesMap =
   NestedLogicalTypesMap.newBuilder().setMapOfRecords(Collections.singletonMap("key",
    RecordInMap.newBuilder().setNullableDateField(LocalDate.now()).build())).build();
  verifySerDeAndStandardMethods(nestedLogicalTypesMap);
 }
}

代码示例来源:origin: apache/avro

@Test
public void testDefaultValueOfNonNullField() throws IOException {
  LogicalTypesWithDefaults instanceOfGeneratedClass = LogicalTypesWithDefaults.newBuilder()
      .setNullableDate(LocalDate.now())
      .build();
  Assert.assertEquals(DEFAULT_VALUE, instanceOfGeneratedClass.getNonNullDate());
  verifySerDeAndStandardMethods(instanceOfGeneratedClass);
}

代码示例来源:origin: apache/avro

@Test
public void testNullableLogicalTypeInNestedRecord() {
 final NestedLogicalTypesRecord nestedLogicalTypesRecord =
  NestedLogicalTypesRecord.newBuilder()
   .setNestedRecord(NestedRecord.newBuilder()
    .setNullableDateField(LocalDate.now()).build()).build();
 verifySerDeAndStandardMethods(nestedLogicalTypesRecord);
}

代码示例来源:origin: apache/avro

@Test
public void testNullableLogicalTypeInRecordInUnion() {
 final NestedLogicalTypesUnion nestedLogicalTypesUnion =
  NestedLogicalTypesUnion.newBuilder().setUnionOfRecords(
   RecordInUnion.newBuilder().setNullableDateField(LocalDate.now()).build()).build();
 verifySerDeAndStandardMethods(nestedLogicalTypesUnion);
}

代码示例来源:origin: apache/avro

@Test
public void testRecordWithoutLogicalTypes() throws IOException {
 // the significance of the record without logical types is that it has the
 // same schema (besides record name) as the one with logical types,
 // including the type annotations. this verifies that the type annotations
 // are only applied if the record was compiled to use those types. this
 // ensures compatibility with already-compiled code.
 TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(
   true,
   34,
   35L,
   3.14F,
   3019.34,
   null,
   new DateConversion().toInt(LocalDate.now(), null, null),
   new TimeConversion().toInt(LocalTime.now(), null, null),
   new TimestampConversion().toLong(
     DateTime.now().withZone(DateTimeZone.UTC), null, null),
   new Conversions.DecimalConversion().toBytes(
     new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN), null,
     LogicalTypes.decimal(9, 2))
 );
 File data = write(TestRecordWithoutLogicalTypes.getClassSchema(), record);
 List<TestRecordWithoutLogicalTypes> actual = read(
   TestRecordWithoutLogicalTypes.getClassSchema(), data);
 Assert.assertEquals("Should match written record", record, actual.get(0));
}

代码示例来源:origin: apache/avro

@Test(expected = MissingSchemaException.class)
public void testSpecificByteArrayIncompatibleWithLogicalTypes() throws IOException {
 TestRecordWithoutLogicalTypes withoutLogicalTypes = new TestRecordWithoutLogicalTypes(
   true,
   34,
   35L,
   3.14F,
   3019.34,
   null,
   new TimeConversions.DateConversion().toInt(LocalDate.now(), null, null),
   new TimeConversions.TimeConversion().toInt(LocalTime.now(), null, null),
   new TimeConversions.TimestampConversion().toLong(
     DateTime.now().withZone(DateTimeZone.UTC), null, null),
   new Conversions.DecimalConversion().toBytes(
     new BigDecimal("123.45"), null, LogicalTypes.decimal(9, 2))
 );
 ByteBuffer b = withoutLogicalTypes.toByteBuffer();
 TestRecordWithLogicalTypes.fromByteBuffer(b);
}

代码示例来源:origin: apache/avro

@Test
public void testSpecificToFromByteBufferWithoutLogicalTypes() throws IOException {
 TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(
   true,
   34,
   35L,
   3.14F,
   3019.34,
   null,
   new TimeConversions.DateConversion().toInt(LocalDate.now(), null, null),
   new TimeConversions.TimeConversion().toInt(LocalTime.now(), null, null),
   new TimeConversions.TimestampConversion().toLong(
     DateTime.now().withZone(DateTimeZone.UTC), null, null),
   new Conversions.DecimalConversion().toBytes(
     new BigDecimal("123.45"), null, LogicalTypes.decimal(9, 2))
 );
 ByteBuffer b = record.toByteBuffer();
 TestRecordWithoutLogicalTypes copy = TestRecordWithoutLogicalTypes.fromByteBuffer(b);
 assertEquals(record, copy);
}

代码示例来源:origin: dlew/joda-time-android

@Test
public void testGetRelativeTimeSpanStringWithPreposition() {
  Context ctx = InstrumentationRegistry.getContext();
  LocalDate today = LocalDate.now();
  LocalDate tomorrow = today.plusDays(1);
  LocalDate nextYear = today.plusYears(1);
  assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, today, false));
  assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, today, true));
  assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, false));
  assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, true));
  assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, false));
  assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, true));
  DateTime todayDt = DateTime.now();
  DateTime tomorrowDt = todayDt.plusDays(1);
  DateTime nextYearDt = todayDt.plusYears(1);
  assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, false));
  assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, true));
  assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, false));
  assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, true));
  assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, false));
  assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, true));
}

相关文章