Example usage for org.joda.time Interval getStartMillis

List of usage examples for org.joda.time Interval getStartMillis

Introduction

In this page you can find the example usage for org.joda.time Interval getStartMillis.

Prototype

public long getStartMillis() 

Source Link

Document

Gets the start of this time interval which is inclusive.

Usage

From source file:org.kuali.kpme.tklm.leave.block.service.LeaveBlockServiceImpl.java

License:Educational Community License

@Override
public void addLeaveBlocks(DateTime beginDate, DateTime endDate, CalendarEntry ce, String selectedEarnCode,
        BigDecimal hours, String description, Assignment selectedAssignment, String spanningWeeks,
        String leaveBlockType, String principalId) {

    DateTimeZone timezone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
    DateTime calBeginDateTime = beginDate;
    DateTime calEndDateTime = endDate;//from  w w w  .j  ava  2s  .  c  o  m

    if (ce != null) {
        calBeginDateTime = ce.getBeginPeriodLocalDateTime().toDateTime();
        calEndDateTime = ce.getEndPeriodLocalDateTime().toDateTime();
    } else {
        LOG.error("Calendar Entry parameter is null.");
        return;
        //          throw new RuntimeException("Calendar Entry parameter is null.");
    }

    Interval calendarInterval = new Interval(calBeginDateTime, calEndDateTime);

    // To create the correct interval by the given begin and end dates,
    // we need to plus one day on the end date to include that date
    List<Interval> leaveBlockIntervals = TKUtils.createDaySpan(beginDate.toLocalDate().toDateTimeAtStartOfDay(),
            endDate.toLocalDate().toDateTimeAtStartOfDay().plusDays(1), TKUtils.getSystemDateTimeZone());

    // need to use beginDate and endDate of the calendar to find all leaveBlocks since LeaveCalendarDocument Id is not always available
    List<LeaveBlock> currentLeaveBlocks = getLeaveBlocks(principalId, calBeginDateTime.toLocalDate(),
            calEndDateTime.toLocalDate());

    // use the current calendar's begin and end date to figure out if this pay period has a leaveDocument
    LeaveCalendarDocumentHeader lcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService()
            .getDocumentHeader(principalId, ce.getBeginPeriodLocalDateTime().toDateTime(),
                    ce.getEndPeriodLocalDateTime().toDateTime());
    String docId = lcdh == null ? null : lcdh.getDocumentId();

    // TODO: need to integrate with the scheduled timeoff.
    Interval firstDay = null;
    DateTime currentDate = beginDate;
    for (Interval leaveBlockInt : leaveBlockIntervals) {
        if (calendarInterval.contains(leaveBlockInt)) {
            // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the leaveblock list
            if (StringUtils.isEmpty(spanningWeeks)
                    && (leaveBlockInt.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY
                            || leaveBlockInt.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) {

                // do nothing
            } else {

                // Currently, we store the accrual category value in the leave code table, but store accrual category id in the leaveBlock.
                // That's why there is a two step server call to get the id. This might be changed in the future.

                CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService()
                        .getCurrentCalendarEntryByCalendarId(ce.getHrCalendarId(),
                                new LocalDate().toDateTimeAtStartOfDay());
                DateTime leaveBlockDate = leaveBlockInt.getStart();

                String requestStatus = HrConstants.REQUEST_STATUS.USAGE;
                if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(
                        principalId, HrConstants.FLSA_STATUS_NON_EXEMPT, true)) {
                    TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService()
                            .getDocumentHeaderForDate(principalId, leaveBlockDate);
                    if (tdh != null) {
                        if (DateUtils.isSameDay(leaveBlockDate.toDate(), tdh.getEndDate())
                                || leaveBlockDate.isAfter(tdh.getEndDateTime())) {
                            requestStatus = HrConstants.REQUEST_STATUS.PLANNED;
                        }
                    } else {
                        requestStatus = HrConstants.REQUEST_STATUS.PLANNED;
                    }
                } else {
                    if (DateUtils.isSameDay(leaveBlockDate.toDate(), calendarEntry.getEndPeriodDateTime())
                            || leaveBlockDate.isAfter(calendarEntry.getEndPeriodFullDateTime())) {
                        requestStatus = HrConstants.REQUEST_STATUS.PLANNED;
                    }
                }

                EarnCode earnCodeObj = HrServiceLocator.getEarnCodeService().getEarnCode(selectedEarnCode,
                        ce.getEndPeriodLocalDateTime().toDateTime().toLocalDate());

                if (earnCodeObj != null
                        && earnCodeObj.getRecordMethod().equals(HrConstants.RECORD_METHOD.TIME)) {
                    if (firstDay != null) {
                        if (!leaveBlockInt.contains(endDate)) {
                            currentDate = leaveBlockInt.getStart();
                        } else if ((leaveBlockInt.getStartMillis() - endDate.getMillis()) != 0) {

                            hours = TKUtils.getHoursBetween(leaveBlockInt.getStartMillis(),
                                    endDate.getMillis());
                            hours = negateHoursIfNecessary(leaveBlockType, hours);

                            LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(),
                                    docId, principalId, selectedEarnCode, hours, description,
                                    earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus,
                                    leaveBlockType, leaveBlockInt.getStart(), endDate);

                            if (!currentLeaveBlocks.contains(leaveBlock)) {
                                currentLeaveBlocks.add(leaveBlock);
                            }
                            break;
                        }
                    }
                    if (leaveBlockInt.contains(currentDate)) {

                        firstDay = leaveBlockInt;

                        if (leaveBlockInt.contains(endDate)
                                || (endDate.getMillis() == leaveBlockInt.getEnd().getMillis())) {

                            hours = TKUtils.getHoursBetween(currentDate.getMillis(), endDate.getMillis());
                            hours = negateHoursIfNecessary(leaveBlockType, hours);

                            LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(),
                                    docId, principalId, selectedEarnCode, hours, description,
                                    earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus,
                                    leaveBlockType, currentDate, endDate);

                            if (!currentLeaveBlocks.contains(leaveBlock)) {
                                currentLeaveBlocks.add(leaveBlock);
                            }

                            break;

                        } else {
                            // create a leave block that wraps the 24 hr day
                            hours = TKUtils.getHoursBetween(currentDate.getMillis(), firstDay.getEndMillis());
                            hours = negateHoursIfNecessary(leaveBlockType, hours);

                            LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(),
                                    docId, principalId, selectedEarnCode, hours, description,
                                    earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus,
                                    leaveBlockType, currentDate, firstDay.getEnd());

                            if (!currentLeaveBlocks.contains(leaveBlock)) {
                                currentLeaveBlocks.add(leaveBlock);
                            }

                        }
                    }
                } else {
                    hours = negateHoursIfNecessary(leaveBlockType, hours);
                    LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(), docId,
                            principalId, selectedEarnCode, hours, description, earnCodeObj.getAccrualCategory(),
                            selectedAssignment, requestStatus, leaveBlockType, null, null);
                    if (!currentLeaveBlocks.contains(leaveBlock)) {
                        currentLeaveBlocks.add(leaveBlock);
                    }
                }
            }
        }
    }
    saveLeaveBlocks(currentLeaveBlocks);
}

From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java

License:Educational Community License

public List<TimeBlock> buildTimeBlocks(Assignment assignment, String earnCode,
        TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours,
        BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String userPrincipalId) {

    //Create 1 or many timeblocks if the span of timeblocks exceed more than one
    //day that is determined by pay period day(24 hrs + period begin date)
    Interval firstDay = null;//from  w  w  w.  j a v  a2s .  c  om
    List<Interval> dayIntervals = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry());
    List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
    DateTime currentDateTime = beginDateTime;

    for (Interval dayInt : dayIntervals) {
        // the time period spans more than one day
        if (firstDay != null) {
            if (!dayInt.contains(endDateTime)) {
                currentDateTime = dayInt.getStart();
            } else if ((dayInt.getStartMillis() - endDateTime.getMillis()) != 0) {
                TimeBlock tb = createTimeBlock(timesheetDocument, dayInt.getStart(), endDateTime, assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                lstTimeBlocks.add(tb);
                break;
            }
        }
        if (dayInt.contains(currentDateTime)) {
            firstDay = dayInt;
            // KPME-361
            // added a condition to handle the time block which ends at 12a, e.g. a 10p-12a timeblock
            // this is the same fix as TkTimeBlockAggregate
            if (dayInt.contains(endDateTime) || (endDateTime.getMillis() == dayInt.getEnd().getMillis())) {
                //create one timeblock if contained in one day interval
                TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, endDateTime, assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                tb.setBeginDateTime(currentDateTime);
                tb.setEndDateTime(endDateTime);
                lstTimeBlocks.add(tb);
                break;
            } else {
                // create a timeblock that wraps the 24 hr day
                TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, dayInt.getEnd(), assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                tb.setBeginDateTime(currentDateTime);
                tb.setEndDateTime(firstDay.getEnd());
                lstTimeBlocks.add(tb);
            }
        }
    }
    return lstTimeBlocks;
}

From source file:org.n52.epos.pattern.eml.filter.temporal.AnyInteractsFilter.java

License:Open Source License

@Override
public String createExpressionString(boolean complexPatternGuard) {

    //get reference interval
    BinaryTemporalOpType anyInteracts = (BinaryTemporalOpType) this.temporalOp;
    Interval intersectsInterval = this.parseGMLTimePeriodFromBinaryTemporalOp(anyInteracts);

    //build expression
    StringBuilder sb = new StringBuilder();

    //add property check
    sb.append("(");
    sb.append(MethodNames.PROPERTY_EXISTS_NAME);
    sb.append("(this, \"");
    sb.append(anyInteracts.getValueReference());
    sb.append("\") AND "); //property check close

    //add any interacts
    sb.append(MethodNames.ANY_INTERACTS_OPERATION);
    sb.append("(this, \"");

    //add test time reference
    sb.append(anyInteracts.getValueReference());

    //add reference interval
    sb.append("\", \"");
    sb.append(intersectsInterval.getStartMillis());
    sb.append(TemporalMethods.INTERVAL_SEPARATOR);
    sb.append(intersectsInterval.getEndMillis());
    sb.append("\")"); //any interacts close

    sb.append(")"); //all close

    return sb.toString();
}

From source file:org.n52.epos.pattern.eml.filter.temporal.BeforeFilter.java

License:Open Source License

@Override
public String createExpressionString(boolean complexPatternGuard) {
    StringBuilder sb = new StringBuilder();

    XmlObject[] valRef = this.temporalOp.selectChildren(VALUE_REFERENCE_QNAME);

    Interval time = null;
    if (valRef != null) {
        try {/* w  w w  .  jav  a2 s  .c om*/
            time = getTimeFromValueReference(valRef[0]);
        } catch (Exception e) {
            //TODO log exception and throw
            logger.warn(e.getMessage(), e);
        }
    }

    if (time != null) {
        sb.append(MapEposEvent.END_KEY + " < " + time.getStartMillis());
    }
    return sb.toString();
}

From source file:org.n52.epos.pattern.eml.filter.temporal.MeetsFilter.java

License:Open Source License

@Override
public String createExpressionString(boolean complexPatternGuard) {
    StringBuilder sb = new StringBuilder();

    XmlObject[] valRef = this.temporalOp.selectChildren(VALUE_REFERENCE_QNAME);

    Interval time = null;
    if (valRef != null) {
        try {/*from   w ww.  ja  v a  2  s .c  om*/
            time = getTimeFromValueReference(valRef[0]);
        } catch (Exception e) {
            //TODO log exception and throw
            logger.warn(e.getMessage(), e);
        }
    }

    if (time != null) {
        sb.append(MapEposEvent.END_KEY + " = " + time.getStartMillis());
    }
    return sb.toString();
}

From source file:org.n52.series.api.proxy.v0.srv.DataService.java

License:Open Source License

protected DesignOptions createDesignOptions(ParameterSet parameterSet, ArrayList<TimeseriesProperties> props,
        boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    return new DesignOptions(props, begin, end, renderGrid);
}

From source file:org.n52.series.api.proxy.v1.srv.DataService.java

License:Open Source License

protected DesignOptions createDesignOptions(UndesignedParameterSet parameterSet,
        ArrayList<TimeseriesProperties> props, boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    DesignOptions designOptions = new DesignOptions(props, begin, end, renderGrid);
    if (parameterSet.getResultTime() != null) {
        Instant resultTime = Instant.parse(parameterSet.getResultTime());
        designOptions.setResultTime(resultTime.getMillis());
    }//from w ww. j  a va 2  s.com
    return designOptions;
}

From source file:org.n52.ses.eml.v001.filter.temporal.BeforeFilter.java

License:Open Source License

@Override
public String createExpressionString(boolean complexPatternGuard) {
    StringBuilder sb = new StringBuilder();

    XmlObject[] valRef = this.temporalOp.selectChildren(VALUE_REFERENCE_QNAME);

    Interval time = null;
    if (valRef != null) {
        try {//from   w ww  .j a  va  2 s . co  m
            time = getTimeFromValueReference(valRef[0]);
        } catch (FESParseException e) {
            //TODO log exception and throw
            logger.warn(e.getMessage(), e);
        }
    }

    if (time != null) {
        sb.append(MapEvent.END_KEY + " < " + time.getStartMillis());
    }
    return sb.toString();
}

From source file:org.n52.ses.eml.v001.filter.temporal.MeetsFilter.java

License:Open Source License

@Override
public String createExpressionString(boolean complexPatternGuard) {
    StringBuilder sb = new StringBuilder();

    XmlObject[] valRef = this.temporalOp.selectChildren(VALUE_REFERENCE_QNAME);

    Interval time = null;
    if (valRef != null) {
        try {/*  w w  w.  ja  v a 2s .c o  m*/
            time = getTimeFromValueReference(valRef[0]);
        } catch (FESParseException e) {
            //TODO log exception and throw
            logger.warn(e.getMessage(), e);
        }
    }

    if (time != null) {
        sb.append(MapEvent.END_KEY + " = " + time.getStartMillis());
    }
    return sb.toString();
}

From source file:org.oxymores.chronix.core.timedata.RunStats.java

License:Apache License

public static void storeMetrics(RunLog rlog, EntityManager em) {
    if (rlog.getStoppedRunningAt() != null && rlog.getResultCode() == 0) {
        DateTime s = new DateTime(rlog.getBeganRunningAt());
        DateTime e = new DateTime(rlog.getStoppedRunningAt());
        Interval i = new Interval(s, e);
        RunMetrics rm = new RunMetrics();
        rm.setDuration(i.getEndMillis() - i.getStartMillis());
        rm.setPlaceId(rlog.getPlaceId());
        rm.setStartTime(rlog.getBeganRunningAt());
        rm.setStateId(rlog.getStateId());

        em.persist(rm);//from ww  w  .  j  a  v  a2  s  . co m
    }
}