List of usage examples for org.joda.time LocalDate fromDateFields
@SuppressWarnings("deprecation") public static LocalDate fromDateFields(Date date)
java.util.Date
using exactly the same field values. From source file:com.qcadoo.mes.assignmentToShift.hooks.AssignmentToShiftHooks.java
License:Open Source License
private Optional<LocalDate> resolveNextStartDate(final Entity assignmentToShift) { final LocalDate startDate = LocalDate .fromDateFields(assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE)); final Shift shift = shiftsFactory.buildFrom(assignmentToShift.getBelongsToField(SHIFT)); final Set<LocalDate> occupiedDates = findNextStartDatesMatching(assignmentToShift.getDataDefinition(), shift, startDate);/*from w w w. j av a 2s .co m*/ Iterable<Integer> daysRange = ContiguousSet.create(Range.closed(1, DAYS_IN_YEAR), DiscreteDomain.integers()); return FluentIterable.from(daysRange).transform(new Function<Integer, LocalDate>() { @Override public LocalDate apply(final Integer numOfDay) { return startDate.plusDays(numOfDay); } }).firstMatch(new Predicate<LocalDate>() { @Override public boolean apply(final LocalDate localDate) { return !occupiedDates.contains(localDate) && shift.worksAt(localDate); } }); }
From source file:com.qcadoo.mes.productionPerShift.util.NonWorkingShiftsNotifier.java
License:Open Source License
private Iterable<ShiftAndDate> extractShiftsAndDates(final Entity progressForDay) { Optional<Date> maybeActualDate = Optional .fromNullable(progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY)); for (Date actualDate : maybeActualDate.asSet()) { final LocalDate actualLocalDate = LocalDate.fromDateFields(actualDate); final int realizationDayNumber = progressForDay.getIntegerField(ProgressForDayFields.DAY); return FluentIterable.from(progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS)) .transformAndConcat(new Function<Entity, Iterable<ShiftAndDate>>() { @Override//from w ww . j a va 2 s.c o m public Iterable<ShiftAndDate> apply(final Entity dailyProgress) { return toShiftAndDates(dailyProgress, realizationDayNumber, actualLocalDate); } }).toList(); } return Collections.emptyList(); }
From source file:com.studium.joda.converters.JodaLocalDateConverter.java
License:Apache License
public LocalDate convertToEntityAttribute(Date date) { return date == null ? null : LocalDate.fromDateFields(date); }
From source file:com.tojsq.view.master.VpnViewBean.java
public void search() { final List<Vpn> vpnList = vpnService.selectByQQ(this.getQq()); if (vpnList.size() > 0) { final Vpn vpn = vpnList.get(0); int days = Days.daysBetween(LocalDate.now(), LocalDate.fromDateFields(vpn.getEndDate())).getDays(); if (days < 0) { this.setResult(String.format("????:%s", LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd"))); } else {//from www . ja va 2 s . com this.setResult(String.format(":%s,%d", LocalDate.fromDateFields(vpn.getEndDate()).toString("yyyy-MM-dd"), days)); } } else { this.setResult("?????QQ???~"); } }
From source file:com.tomtom.speedtools.mongodb.mappers.LocalDateMapper.java
License:Apache License
@Nullable @Override/*w ww. j av a 2 s .co m*/ public LocalDate fromDb(@Nullable final Object dbValue) throws MapperException { if (dbValue == null) { return null; } if (dbValue instanceof Date) { return LocalDate.fromDateFields((Date) dbValue); } throw new MapperException( "DateTime value expected, " + "got a value of type: " + dbValue.getClass().getCanonicalName()); }
From source file:dao.RegistroDao.java
public List<Registro> getListBetween(Date dt1, Date dt2) { List<Registro> result = new ArrayList<Registro>(); try {/*from w ww . java 2s .co m*/ LocalDate dtTmp = LocalDate.fromDateFields(dt1); while (dt2.compareTo(dtTmp.dayOfMonth().withMinimumValue().toDate()) >= 0) { List<Registro> listTmp = getListByMonth(dtTmp.toDate()); if (listTmp != null) { result.addAll(listTmp); //ordena a lista Collections.sort(result, regComparator); } dtTmp = dtTmp.plusMonths(1); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:energy.usef.core.model.PlanboardMessage.java
License:Apache License
public LocalDate getPeriod() { if (period == null) { return null; } return LocalDate.fromDateFields(period); }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
License:Open Source License
void setupNewCalendar() { caldroidFragment = new CaldroidSampleCustomFragment(); Bundle args = new Bundle(); DateTime now = DateTime.now();// w w w. j a va 2 s . co m args.putInt(CaldroidFragment.MONTH, now.getMonthOfYear()); args.putInt(CaldroidFragment.YEAR, now.getYear()); args.putBoolean(CaldroidFragment.SHOW_NAVIGATION_ARROWS, false); args.putBoolean(CaldroidFragment.SIX_WEEKS_IN_CALENDAR, false); args.putInt(CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY); args.putInt(CaldroidFragment.THEME_RESOURCE, R.style.CaldroidDefaultNoGrid); caldroidFragment.setArguments(args); FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.calendar, caldroidFragment); t.commit(); final CaldroidListener listener = new CaldroidListener() { @Override public void onSelectDate(Date date, View view) { LocalDate d = LocalDate.fromDateFields(date); onDaySelected(d); if (bestDay != null && bestDay.first != null && bestDay.first.equals(d)) { //Toast.makeText(CalendarActivity.this, "Best day!", Toast.LENGTH_SHORT).show(); AlertDialog.Builder builder = new AlertDialog.Builder(CalendarActivity.this); builder.setTitle(R.string.best_date_recommendation_title).setPositiveButton( getString(R.string.driving_warning_gotit), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alertDialog = builder.create(); alertDialog.setMessage(bestDayText); alertDialog.show(); } } @Override public void onChangeMonth(int month, int year) { DateTime date = DateTime.now().withYear(year).withMonthOfYear(month); subtitle.setText(date.toString("MMMM YYYY").toUpperCase()); } @Override public void onLongClickDate(Date date, View view) { } @Override public void onCaldroidViewCreated() { caldroidFragment.getView().findViewById(R.id.calendar_title_view).setVisibility(View.GONE); caldroidFragment.getMonthTitleTextView().setVisibility(View.GONE); } }; caldroidFragment.setCaldroidListener(listener); this.bestDay = pickupUtils.getBestDay(); this.bestDayText = getBestDayText(); if (this.bestDay != null && this.bestDay.first != null) { //Toast.makeText(CalendarActivity.this, "Best day: " + bestDay.first.toString("dd/MM/YY"), Toast.LENGTH_SHORT).show(); caldroidFragment.setBackgroundDrawableForDate( new ColorDrawable(getResources().getColor(R.color.android_green_light)), this.bestDay.first.toDate()); } caldroidFragment.refreshView(); }
From source file:fr.inria.atlanmod.decision.ui.DecisionEngine.java
License:Open Source License
private boolean deadlineMet(Rule rule, ProxyTask task) { Deadline deadline = rule.getDeadline(); if (deadline instanceof Timer) { Timer timer = (Timer) deadline; Date creationDate = task.getCreationDate(); Days days = Days.daysBetween(LocalDate.fromDateFields(creationDate), LocalDate.fromDateFields(new Date())); int deadlineDays = timer.getTimeStamp(); if (days.getDays() < deadlineDays) return false; else//from ww w . j a v a 2s .c o m return true; } else if (deadline instanceof WaitForVote) { WaitForVote waitForVote = (WaitForVote) deadline; List<Role> rolesToWaitFor = waitForVote.getRoles(); List<User> allUsers = collaborations.getUsers(); List<User> usersToVote = new ArrayList<User>(); for (User user : allUsers) { for (Role role : user.getRoles()) { boolean found = false; for (Role roletToWaitFor : rolesToWaitFor) { if (role.getName().equals(roletToWaitFor.getName())) { usersToVote.add(user); found = true; break; } } if (found) break; } } List<User> usersVoted = new ArrayList<User>(); for (Vote vote : task.getCollaboration().getVotes()) { usersVoted.add(vote.getVotedBy()); } // I'm not very proud of this, but I was having a hard afternoon // and I didn't come up with other solution :( int totalUsersToVote = usersToVote.size(); for (User userVoted : usersVoted) { for (User userToVote : usersToVote) { if (userVoted.getName().equals(userToVote.getName())) { totalUsersToVote--; } } } if (totalUsersToVote == 0) return true; else return false; } else if (deadline instanceof OCLCondition) { OCLCondition oclCondition = (OCLCondition) deadline; // TODO consider OCL expressions } return true; }
From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static LocalDate toLocalDate(final java.sql.Date d) { // TODO - confirm this conversion always works, esp. across timezones final LocalDate ld = (d == null ? null : LocalDate.fromDateFields(d)); return ld;//from w ww . ja v a 2 s . c o m }