當前位置: 首頁>>代碼示例>>Java>>正文


Java Temporal類代碼示例

本文整理匯總了Java中java.time.temporal.Temporal的典型用法代碼示例。如果您正苦於以下問題:Java Temporal類的具體用法?Java Temporal怎麽用?Java Temporal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Temporal類屬於java.time.temporal包,在下文中一共展示了Temporal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: renderTemporal

import java.time.temporal.Temporal; //導入依賴的package包/類
/**
 * Renders a Temporal value type Field
 * @param property Property to render
 * @return Field instance
 */
@SuppressWarnings("unchecked")
protected Field<T> renderTemporal(Property<T> property) {

	TemporalInputBuilder builder = null;

	if (LocalDate.class.isAssignableFrom(property.getType())) {
		builder = input.localDate(false);
	} else if (LocalDateTime.class.isAssignableFrom(property.getType())) {
		builder = input.localDateTime(false);
	} else {
		throw new UnsupportedTemporalTypeException(
				"Temporal type " + property.getType().getName() + " is not supported by default field renderer");
	}

	final TemporalInputBuilder<Temporal, ?> b = builder;

	// set locale from LocalizationContext, if any
	LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap((c) -> c.getLocale())
			.ifPresent((l) -> b.locale(l));

	return postProcessField(b.asField(), property);
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:28,代碼來源:DefaultFieldPropertyRenderer.java

示例2: addTo

import java.time.temporal.Temporal; //導入依賴的package包/類
@Override
public Temporal addTo(Temporal temporal) {
    validateChrono(temporal);
    if (months == 0) {
        if (years != 0) {
            temporal = temporal.plus(years, YEARS);
        }
    } else {
        long monthRange = monthRange();
        if (monthRange > 0) {
            temporal = temporal.plus(years * monthRange + months, MONTHS);
        } else {
            if (years != 0) {
                temporal = temporal.plus(years, YEARS);
            }
            temporal = temporal.plus(months, MONTHS);
        }
    }
    if (days != 0) {
        temporal = temporal.plus(days, DAYS);
    }
    return temporal;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:ChronoPeriodImpl.java

示例3: ensureValid

import java.time.temporal.Temporal; //導入依賴的package包/類
/**
 * Casts the {@code Temporal} to {@code ChronoLocalDateTime} ensuring it bas the specified chronology.
 *
 * @param chrono  the chronology to check for, not null
 * @param temporal   a date-time to cast, not null
 * @return the date-time checked and cast to {@code ChronoLocalDateTime}, not null
 * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDateTimeImpl
 *  or the chronology is not equal this Chronology
 */
static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal) {
    @SuppressWarnings("unchecked")
    ChronoLocalDateTimeImpl<R> other = (ChronoLocalDateTimeImpl<R>) temporal;
    if (chrono.equals(other.getChronology()) == false) {
        throw new ClassCastException("Chronology mismatch, required: " + chrono.getId()
                + ", actual: " + other.getChronology().getId());
    }
    return other;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ChronoLocalDateTimeImpl.java

示例4: test_with_adjustment

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test
public void test_with_adjustment() {
    final OffsetDateTime sample = OffsetDateTime.of(LocalDate.of(2012, 3, 4), LocalTime.of(23, 5), OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {
        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_2008_6_30_11_30_59_000000500.with(adjuster), sample);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:TCKOffsetDateTime.java

示例5: test_with_adjustment

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test
public void test_with_adjustment() {
    final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {
        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:TCKOffsetTime.java

示例6: until

import java.time.temporal.Temporal; //導入依賴的package包/類
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
    CopticDate end = getChronology().date(endExclusive);
    if (unit instanceof ChronoUnit) {
        return LocalDate.from(this).until(end, unit);  // TODO: this is wrong
    }
    return unit.between(this, end);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:CopticDate.java

示例7: get

import java.time.temporal.Temporal; //導入依賴的package包/類
@Override
default int get(TemporalField field) {
    if (field instanceof ChronoField) {
        switch ((ChronoField) field) {
            case INSTANT_SECONDS:
                throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
            case OFFSET_SECONDS:
                return getOffset().getTotalSeconds();
        }
        return toLocalDateTime().get(field);
    }
    return Temporal.super.get(field);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ChronoZonedDateTime.java

示例8: test_adjustDate

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test
public void test_adjustDate() {
    LocalDate base = LocalDate.of(2007, 2, 12);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = Year.of(i).adjustInto(base);
        assertEquals(result, LocalDate.of(i, 2, 12));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKYear.java

示例9: test_formatStyle

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test(dataProvider = "formatStyle")
public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
    formatter = formatter.withLocale(Locale.US);
    assertEquals(formatter.format(temporal), formattedStr);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TCKFormatStyle.java

示例10: test_with_TemporalAdjuster

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test
public void test_with_TemporalAdjuster() {
    Year base = Year.of(-10);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = base.with(Year.of(i));
        assertEquals(result, Year.of(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKYear.java

示例11: test_with_adjustment

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test
public void test_with_adjustment() {
    final LocalTime sample = LocalTime.of(23, 5);
    TemporalAdjuster adjuster = new TemporalAdjuster() {
        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_12_30_40_987654321.with(adjuster), sample);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:TCKLocalTime.java

示例12: test_subtractFrom

import java.time.temporal.Temporal; //導入依賴的package包/類
@Test(dataProvider="calendars")
public void test_subtractFrom(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.subtractFrom(date);
    assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TCKChronoPeriod.java

示例13: until

import java.time.temporal.Temporal; //導入依賴的package包/類
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
    Objects.requireNonNull(endExclusive, "endExclusive");
    @SuppressWarnings("unchecked")
    ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
    if (unit instanceof ChronoUnit) {
        if (unit.isTimeBased()) {
            long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
            switch ((ChronoUnit) unit) {
                case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break;
                case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
                case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
                case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break;
                case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break;
                case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break;
                case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break;
            }
            return Math.addExact(amount, time.until(end.toLocalTime(), unit));
        }
        ChronoLocalDate endDate = end.toLocalDate();
        if (end.toLocalTime().isBefore(time)) {
            endDate = endDate.minus(1, ChronoUnit.DAYS);
        }
        return date.until(endDate, unit);
    }
    Objects.requireNonNull(unit, "unit");
    return unit.between(this, end);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:ChronoLocalDateTimeImpl.java

示例14: invokeSpecial0

import java.time.temporal.Temporal; //導入依賴的package包/類
@Override
protected <T> T invokeSpecial0(@NotNull SNode node, @NotNull SMethod<T> method, @Nullable Object[] parameters) {
  int methodIndex = BH_METHODS.indexOf(method);
  if (methodIndex < 0) {
    throw new BHMethodNotFoundException(this, method);
  }
  switch (methodIndex) {
    case 0:
      return (T) ((Temporal) GeefTemporeleWaarde_id5kuxuwXEUJM(node));
    case 1:
      return (T) ((String) GeefWaardeString_idFzw$g_H4hz(node));
    default:
      throw new BHMethodNotFoundException(this, method);
  }
}
 
開發者ID:diederikd,項目名稱:DeBrug,代碼行數:16,代碼來源:DatumTijdWaarde__BehaviorDescriptor.java

示例15: ensureValid

import java.time.temporal.Temporal; //導入依賴的package包/類
/**
 * Casts the {@code Temporal} to {@code ChronoZonedDateTimeImpl} ensuring it bas the specified chronology.
 *
 * @param chrono  the chronology to check for, not null
 * @param temporal  a date-time to cast, not null
 * @return the date-time checked and cast to {@code ChronoZonedDateTimeImpl}, not null
 * @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl
 *  or the chronology is not equal this Chronology
 */
static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal) {
    @SuppressWarnings("unchecked")
    ChronoZonedDateTimeImpl<R> other = (ChronoZonedDateTimeImpl<R>) temporal;
    if (chrono.equals(other.getChronology()) == false) {
        throw new ClassCastException("Chronology mismatch, required: " + chrono.getId()
                + ", actual: " + other.getChronology().getId());
    }
    return other;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ChronoZonedDateTimeImpl.java


注:本文中的java.time.temporal.Temporal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。