Java Code Examples for java.time.LocalTime#from()
The following examples show how to use
java.time.LocalTime#from() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkingDaysAdjusters.java From alf.io with GNU General Public License v3.0 | 6 votes |
private static Temporal adjust(Temporal in, Set<DayOfWeek> dayOfWeeks, List<HoursRange> hoursRanges) { DayOfWeek dayOfWeek = DayOfWeek.from(in); LocalTime localTime = LocalTime.from(in); boolean dayInRange = dayOfWeeks.contains(dayOfWeek); boolean hourInRange = hoursRanges.stream().anyMatch(hr -> hr.includes(localTime)); if(dayInRange && hourInRange) { return in; } Temporal result = in; if(!dayInRange) { do { result = result.plus(1, ChronoUnit.DAYS); } while(!dayOfWeeks.contains(DayOfWeek.from(result))); } if(!hourInRange) { OptionalInt distance = hoursRanges.stream() .mapToInt(hr -> hr.getDistanceInHours(localTime)) .sorted() .findFirst(); result = result.plus(distance.orElseThrow(IllegalStateException::new), ChronoUnit.HOURS); } return result; }
Example 2
Source File: FHIRPathUtil.java From FHIR with Apache License 2.0 | 6 votes |
public static TemporalAccessor getTemporalAccessor(Temporal temporal, Class<?> targetType) { if (temporal.getClass().equals(targetType)) { return temporal; } if (Year.class.equals(targetType)) { return Year.from(temporal); } else if (YearMonth.class.equals(targetType)) { return YearMonth.from(temporal); } else if (LocalDate.class.equals(targetType)) { return LocalDate.from(temporal); } else if (LocalDateTime.class.equals(targetType)) { return LocalDateTime.from(temporal); } else if (ZonedDateTime.class.equals(targetType)){ return ZonedDateTime.from(temporal); } else if (LocalTime.class.equals(targetType)) { return LocalTime.from(temporal); } throw new IllegalArgumentException(); }
Example 3
Source File: LocalTimeXmlAdapter.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public LocalTime unmarshal( String localTimeString ) throws Exception { if ( localTimeString == null ) { return null; } try { return LocalTime.from( formatter.parse( localTimeString ) ); } catch ( DateTimeException e ) { throw new IllegalStateException( "Failed to convert string (" + localTimeString + ") to type (" + LocalTime.class.getName() + ")." ); } }
Example 4
Source File: DefaultDateFunctions.java From jackcess with Apache License 2.0 | 5 votes |
static Value stringToDateValue(LocaleContext ctx, String valStr) { // see if we can coerce to date/time TemporalConfig.Type valTempType = ExpressionTokenizer.determineDateType( valStr, ctx); if(valTempType != null) { DateTimeFormatter parseDf = ctx.createDateFormatter( ctx.getTemporalConfig().getDateTimeFormat(valTempType)); try { TemporalAccessor parsedInfo = parseDf.parse(valStr); LocalDate ld = ColumnImpl.BASE_LD; if(valTempType.includesDate()) { // the year may not be explicitly specified if(parsedInfo.isSupported(ChronoField.YEAR)) { ld = LocalDate.from(parsedInfo); } else { ld = MonthDay.from(parsedInfo).atYear( Year.now(ctx.getZoneId()).getValue()); } } LocalTime lt = ColumnImpl.BASE_LT; if(valTempType.includesTime()) { lt = LocalTime.from(parsedInfo); } return ValueSupport.toValue(LocalDateTime.of(ld, lt)); } catch(DateTimeException de) { // note a valid date/time } } // not a valid date string, not a date/time return null; }
Example 5
Source File: CacheQueryEntityWithDateTimeApiFieldsTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Copy constructor. * * @param entity Entity to copy from. */ EntityWithDateTimeFields(EntityWithDateTimeFields entity) { id = entity.id; locTime = LocalTime.from(entity.locTime); locDate = LocalDate.from(entity.locDate); locDateTime = LocalDateTime.from(entity.locDateTime); }
Example 6
Source File: TCKLocalTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 7
Source File: TCKLocalTime.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 8
Source File: TCKLocalTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 9
Source File: TCKLocalTime.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 10
Source File: TCKLocalTime.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 11
Source File: HyperledgerHeader.java From fabric-api-archive with Apache License 2.0 | 4 votes |
/** * @return the time point of the block was created as observed in local time */ @Override public LocalTime getLocalCreateTime() { return LocalTime.from(Instant.ofEpochSecond(Integer.toUnsignedLong(createTime)).atZone(ZoneId.of("Z"))); }
Example 12
Source File: TCKLocalTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 13
Source File: TCKLocalTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 14
Source File: TCKLocalTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 15
Source File: TCKLocalTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 16
Source File: TCKLocalTime.java From j2objc with Apache License 2.0 | 4 votes |
@Test(expected=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 17
Source File: TCKLocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 18
Source File: TCKLocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }
Example 19
Source File: TCKLocalTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_from_TemporalAccessor_null() { LocalTime.from((TemporalAccessor) null); }
Example 20
Source File: TCKLocalTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_from_TemporalAccessor_invalid_noDerive() { LocalTime.from(LocalDate.of(2007, 7, 15)); }