List of usage examples for org.joda.time DateTime toDateMidnight
@Deprecated
public DateMidnight toDateMidnight()
DateMidnight
using the same millis and chronology. From source file:net.lshift.diffa.config.WindowRefiner.java
License:Apache License
private WindowRefiner(String periodExpression, String offsetExpression, DateTime now) { this.periodExpression = periodExpression; this.offsetExpression = offsetExpression; DateTime end;//from w ww.java2 s . c o m if (offsetExpression == null || offsetExpression.equals("")) { end = now; } else { DateTime startOfDay = now.toDateMidnight().toDateTime(); end = startOfDay.plus(periodFormatter.parsePeriod(offsetExpression).toDurationFrom(startOfDay)); } DateTime start = end.minus(periodFormatter.parsePeriod(periodExpression)); this.windowInterval = new Interval(start, end); }
From source file:net.naonedbus.helper.DateTimeFormatHelper.java
License:Open Source License
/** * Formater 2 dates en vitant de rpter 2 fois le mme jour * // w ww . jav a 2s. c o m * @param debut * @param fin * @return Les dates formates. */ public String formatDuree(final DateTime debut, final DateTime fin) { final StringBuilder builder = new StringBuilder(); builder.append(formatDateTime(debut)); if (fin != null) { builder.append(ARROW); if (debut.toDateMidnight().equals(fin.toDateMidnight())) { // Mme jour builder.append( DateUtils.formatDateTime(this.mContext, fin.getMillis(), DateUtils.FORMAT_SHOW_TIME)); } else { builder.append(formatDateTime(fin)); } } return builder.toString(); }
From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentForFirstTimeStudents.java
License:Open Source License
@Override protected Money calculatePenaltyAmount(final Event event, final DateTime when, final BigDecimal discountPercentage) { if (when.toDateMidnight().compareTo(getWhenStartToApplyPenalty(event, when)) >= 0) { return new Money(calculateMonthPenalty(event, discountPercentage) .multiply(new BigDecimal(getNumberOfMonthsToChargePenalty(event, when)))); } else {//from w w w . ja va 2 s .c o m return Money.ZERO; } }
From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentForFirstTimeStudents.java
License:Open Source License
private int getNumberOfMonthsToChargePenalty(final Event event, final DateTime when) { final int numberOfMonths = (new Period(getWhenStartToApplyPenalty(event, when), when.toDateMidnight()) .getMonths() + 1);//from ww w .j a va 2 s . com return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty(); }
From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentWithMonthlyPenalty.java
License:Open Source License
@Override protected Money calculatePenaltyAmount(Event event, DateTime when, BigDecimal discountPercentage) { if (when.toDateMidnight().compareTo(getWhenStartToApplyPenalty().toDateMidnight()) >= 0) { return new Money(calculateMonthPenalty(event, discountPercentage) .multiply(new BigDecimal(getNumberOfMonthsToChargePenalty(when)))); } else {//from w ww . j av a2s.co m return Money.ZERO; } }
From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentWithMonthlyPenalty.java
License:Open Source License
protected int getNumberOfMonthsToChargePenalty(DateTime when) { final int numberOfMonths = (new Period(getWhenStartToApplyPenalty().withDayOfMonth(1).toDateMidnight(), when.toDateMidnight()).getMonths() + 1); return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publicRelationsOffice.AlumniInformationAction.java
License:Open Source License
public ActionForward showAlumniStatistics(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { Map<Long, Integer> registrationsByDay = new TreeMap<Long, Integer>(); int totalAlumniCount = Bennu.getInstance().getAlumnisSet().size(); int newAlumniCount = 0; int registeredAlumniCount = 0; for (Alumni alumni : Bennu.getInstance().getAlumnisSet()) { if (alumni.hasStartedPublicRegistry()) { newAlumniCount++;//from ww w . j a v a2 s . co m } if (alumni.hasFinishedPublicRegistry()) { registeredAlumniCount++; } DateTime whenRegistered = alumni.getRegisteredWhen(); if (whenRegistered != null) { // long time = // whenRegistered.toLocalDate().toDateTimeAtStartOfDay().getMillis(); long time = whenRegistered.toDateMidnight().getMillis(); Integer count = registrationsByDay.get(time); registrationsByDay.put(time, count == null ? 1 : count + 1); } } int jobCount = Bennu.getInstance().getJobsSet().size(); int formationCount = 0; for (Qualification q : Bennu.getInstance().getQualificationsSet()) { if (q.getClass().equals(Formation.class)) { formationCount++; } } request.setAttribute("chartData", createJsonArray(registrationsByDay)); request.setAttribute("statistics1", Role.getRoleByRoleType(RoleType.ALUMNI).getAssociatedPersonsSet().size()); request.setAttribute("statistics2", totalAlumniCount); request.setAttribute("statistics3", newAlumniCount); request.setAttribute("statistics4", registeredAlumniCount); request.setAttribute("statistics5", jobCount); request.setAttribute("statistics6", formationCount); request.setAttribute("doneJobs", AlumniReportFile.readDoneJobs()); request.setAttribute("undoneJobs", AlumniReportFile.readUndoneJobs()); request.setAttribute("canRequestReport", AlumniReportFile.canRequestReport()); return mapping.findForward("alumni.showAlumniStatistics"); }
From source file:org.apereo.portal.events.aggr.AggregationIntervalHelperImpl.java
License:Apache License
@Override public AggregationIntervalInfo getIntervalInfo(AggregationInterval interval, DateTime date) { //Chop off everything below the minutes (seconds, millis) final DateTime instant = date.minuteOfHour().roundFloorCopy(); final DateTime start, end; switch (interval) { case CALENDAR_QUARTER: { final List<QuarterDetail> quartersDetails = this.eventAggregationManagementDao.getQuartersDetails(); final QuarterDetail quarterDetail = EventDateTimeUtils.findDateRangeSorted(instant, quartersDetails); start = quarterDetail.getStartDateMidnight(date).toDateTime(); end = quarterDetail.getEndDateMidnight(date).toDateTime(); break;/*from ww w . j a v a 2s . co m*/ } case ACADEMIC_TERM: { final List<AcademicTermDetail> academicTermDetails = this.eventAggregationManagementDao .getAcademicTermDetails(); final AcademicTermDetail academicTermDetail = EventDateTimeUtils.findDateRangeSorted(date, academicTermDetails); if (academicTermDetail == null) { return null; } start = academicTermDetail.getStart().toDateTime(); end = academicTermDetail.getEnd().toDateTime(); break; } default: { start = interval.determineStart(instant); end = interval.determineEnd(start); } } final LocalTime startTime = start.toLocalTime(); final TimeDimension startTimeDimension = this.timeDimensionDao.getTimeDimensionByTime(startTime); final DateMidnight startDateMidnight = start.toDateMidnight(); final DateDimension startDateDimension = this.dateDimensionDao.getDateDimensionByDate(startDateMidnight); return new AggregationIntervalInfo(interval, start, end, startDateDimension, startTimeDimension); }
From source file:org.apereo.portal.events.aggr.AggregationIntervalHelperImpl.java
License:Apache License
/** * Return a sorted list of AcademicTermDetail objects where the the first element of the list * where the first element is the first term that starts after the specified start DateTime. *//*w ww. j a va 2s . co m*/ protected List<AcademicTermDetail> getAcademicTermsAfter(DateTime start) { final List<AcademicTermDetail> terms = this.eventAggregationManagementDao.getAcademicTermDetails(); final int index = Collections.binarySearch(terms, new AcademicTermDetailImpl(start.toDateMidnight(), start.plusDays(1).toDateMidnight(), "")); if (index > 0) { return terms.subList(index, terms.size()); } else if (index < 0) { return terms.subList(-(index + 1), terms.size()); } return terms; }
From source file:org.apereo.portal.portlets.statistics.BaseStatisticsReportController.java
License:Apache License
/** Build the aggregation {@link DataTable} */ protected final DataTable buildAggregationReport(F form) throws TypeMismatchException { //Pull data out of form for per-group fetching final AggregationInterval interval = form.getInterval(); final DateMidnight start = form.getStart(); final DateMidnight end = form.getEnd(); final DateTime startDateTime = start.toDateTime(); //Use a query end of the end date at 23:59:59 final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1); //Get the list of DateTimes used on the X axis in the report final List<DateTime> reportTimes = this.intervalHelper.getIntervalStartDateTimesBetween(interval, startDateTime, endDateTime, maxIntervals); final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form); //Determine the ValueType of the date/time column. Use the most specific column type possible final ValueType dateTimeColumnType; if (interval.isHasTimePart()) { //If start/end are the same day just display the time if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) { dateTimeColumnType = ValueType.TIMEOFDAY; }/*from w w w . j a v a2 s .c o m*/ //interval has time data and start/end are on different days, show full date time else { dateTimeColumnType = ValueType.DATETIME; } } //interval is date only else { dateTimeColumnType = ValueType.DATE; } //Setup the date/time column description final ColumnDescription dateTimeColumn; switch (dateTimeColumnType) { case TIMEOFDAY: { dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time"); break; } default: { dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date"); } } final DataTable table = new JsonDataTable(); table.addColumn(dateTimeColumn); //Setup columns in the DataTable final Set<D> columnGroups = groupedAggregations.keySet(); for (final D columnMapping : columnGroups) { final Collection<ColumnDescription> columnDescriptions = this.getColumnDescriptions(columnMapping, form); table.addColumns(columnDescriptions); } //Query for all aggregation data in the time range for all groups. Only the //interval and discriminator data is used from the keys. final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form); final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao(); final Collection<T> aggregations = baseAggregationDao.getAggregations(startDateTime, endDateTime, keys, extractGroupsArray(columnGroups)); //Organize the results by group and sort them chronologically by adding them to the sorted set for (final T aggregation : aggregations) { final D discriminator = aggregation.getAggregationDiscriminator(); final SortedSet<T> results = groupedAggregations.get(discriminator); results.add(aggregation); } //Build Map from discriminator column mapping to result iterator to allow putting results into //the correct column AND the correct time slot in the column Comparator<? super D> comparator = getDiscriminatorComparator(); final Map<D, PeekingIterator<T>> groupedAggregationIterators = new TreeMap<D, PeekingIterator<T>>( (comparator)); for (final Entry<D, SortedSet<T>> groupedAggregationEntry : groupedAggregations.entrySet()) { groupedAggregationIterators.put(groupedAggregationEntry.getKey(), Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator())); } /* * populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the * query range. Then the iterator */ for (final DateTime rowTime : reportTimes) { // create the row final TableRow row = new TableRow(); // add the date to the first cell final Value dateTimeValue; switch (dateTimeColumnType) { case DATE: { dateTimeValue = new DateValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth()); break; } case TIMEOFDAY: { dateTimeValue = new TimeOfDayValue(rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0); break; } default: { dateTimeValue = new DateTimeValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth(), rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0, 0); break; } } row.addCell(new TableCell(dateTimeValue)); for (final PeekingIterator<T> groupedAggregationIteratorEntry : groupedAggregationIterators.values()) { List<Value> values = null; if (groupedAggregationIteratorEntry.hasNext()) { final T aggr = groupedAggregationIteratorEntry.peek(); if (rowTime.equals(aggr.getDateTime())) { //Data is for the correct time slot, advance the iterator groupedAggregationIteratorEntry.next(); values = createRowValues(aggr, form); } } //Gap in the data, fill it in using a null aggregation if (values == null) { values = createRowValues(null, form); } //Add the values to the row for (final Value value : values) { row.addCell(value); } } table.addRow(row); } return table; }