Java Code Examples for org.threeten.bp.LocalDate#from()
The following examples show how to use
org.threeten.bp.LocalDate#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: IsoFields.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("unchecked") @Override public <R extends Temporal> R adjustInto(R temporal, long newValue) { if (isSupportedBy(temporal) == false) { throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear"); } int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR); // strict check LocalDate date = LocalDate.from(temporal); int dow = date.get(DAY_OF_WEEK); int week = getWeek(date); if (week == 53 && getWeekRange(newWby) == 52) { week = 52; } LocalDate resolved = LocalDate.of(newWby, 1, 4); // 4th is guaranteed to be in week one int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7); resolved = resolved.plusDays(days); return (R) temporal.with(resolved); }
Example 2
Source File: AppMapper.java From droidconat-2016 with Apache License 2.0 | 5 votes |
private Schedule mapToScheduleDays(@NonNull List<ScheduleSlot> scheduleSlots) { Schedule schedule = new Schedule(); LocalDate previousDay = null; List<ScheduleSlot> previousSlotList = null; LocalDate currentDay; for (ScheduleSlot currentSlot : scheduleSlots) { currentDay = LocalDate.from(currentSlot.getTime()); if (previousSlotList != null) { if (currentDay.equals(previousDay)) { previousSlotList.add(currentSlot); } else { schedule.add(new ScheduleDay(previousDay, previousSlotList)); previousSlotList = null; } } if (previousSlotList == null) { previousDay = currentDay; previousSlotList = new ArrayList<>(); previousSlotList.add(currentSlot); } } if (previousSlotList != null) { schedule.add(new ScheduleDay(previousDay, previousSlotList)); } return schedule; }
Example 3
Source File: JapaneseChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override // override with covariant return type public JapaneseDate date(TemporalAccessor temporal) { if (temporal instanceof JapaneseDate) { return (JapaneseDate) temporal; } return new JapaneseDate(LocalDate.from(temporal)); }
Example 4
Source File: MinguoChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override // override with covariant return type public MinguoDate date(TemporalAccessor temporal) { if (temporal instanceof MinguoDate) { return (MinguoDate) temporal; } return new MinguoDate(LocalDate.from(temporal)); }
Example 5
Source File: ThaiBuddhistChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override // override with covariant return type public ThaiBuddhistDate date(TemporalAccessor temporal) { if (temporal instanceof ThaiBuddhistDate) { return (ThaiBuddhistDate) temporal; } return new ThaiBuddhistDate(LocalDate.from(temporal)); }
Example 6
Source File: IsoChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Obtains an ISO local date from another date-time object. * <p> * This is equivalent to {@link LocalDate#from(TemporalAccessor)}. * * @param temporal the date-time object to convert, not null * @return the ISO local date, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate date(TemporalAccessor temporal) { return LocalDate.from(temporal); }