Example usage for org.joda.time LocalDateTime toDateTime

List of usage examples for org.joda.time LocalDateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime toDateTime.

Prototype

public DateTime toDateTime(DateTimeZone zone) 

Source Link

Document

Converts this object to a DateTime using the specified zone.

Usage

From source file:org.fixb.quickfix.QuickFixFieldMapBuilder.java

License:Apache License

protected FixMessageBuilder<M> setField(FieldMap message, int tag, LocalDateTime value) {
    message.setUtcTimeStamp(tag, value.toDateTime(DateTimeZone.UTC).toDate());
    return this;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnLocalDateTimeMapper.java

License:Apache License

@Override
public Timestamp toNonNullValue(LocalDateTime value) {

    DateTime zonedValue = value.toDateTime(value.toDateTime());

    final Timestamp timestamp = new Timestamp(zonedValue.getMillis());
    return timestamp;
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZone.java

License:Apache License

@Override
protected DateTime fromConvertedColumns(Object[] convertedColumns) {

    LocalDateTime datePart = (LocalDateTime) convertedColumns[0];
    DateTimeZone zone = (DateTimeZone) convertedColumns[1];

    DateTime result;// w  ww.  j  a v  a 2s  .  com

    if (datePart == null) {
        result = null;
    } else {
        result = datePart.toDateTime(databaseZone == null ? zone : databaseZone);

        if (databaseZone != null) {
            result = result.withZone(zone);
        }
    }

    return result;
}

From source file:org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZoneWithOffset.java

License:Apache License

@Override
protected DateTime fromConvertedColumns(Object[] convertedColumns) {

    LocalDateTime datePart = (LocalDateTime) convertedColumns[0];
    DateTimeZoneWithOffset offset = (DateTimeZoneWithOffset) convertedColumns[1];

    DateTime result;/*  ww  w  . j  a  va 2  s  . com*/

    if (datePart == null) {
        result = null;
    } else {
        result = datePart.toDateTime(databaseZone == null ? offset.getStandardDateTimeZone() : databaseZone);

        if (databaseZone != null) {
            result = result.withZone(offset.getStandardDateTimeZone());
        }
    }

    // Handling DST rollover
    if (result != null && offset.getOffsetDateTimeZone() != null && offset.getStandardDateTimeZone()
            .getOffset(result) > offset.getOffsetDateTimeZone().getOffset(result)) {
        return result.withLaterOffsetAtOverlap();
    }

    return result;
}

From source file:org.kuali.kpme.tklm.leave.calendar.validation.LeaveCalendarValidationUtil.java

License:Educational Community License

public static List<String> validateInterval(CalendarEntry payCalEntry, Long startTime, Long endTime) {
    List<String> errors = new ArrayList<String>();
    LocalDateTime pcb_ldt = payCalEntry.getBeginPeriodLocalDateTime();
    LocalDateTime pce_ldt = payCalEntry.getEndPeriodLocalDateTime();
    DateTimeZone utz = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
    DateTime p_cal_b_dt = pcb_ldt.toDateTime(utz);
    DateTime p_cal_e_dt = pce_ldt.toDateTime(utz);

    Interval payInterval = new Interval(p_cal_b_dt, p_cal_e_dt);
    if (errors.size() == 0 && !payInterval.contains(startTime)) {
        errors.add("The start date/time is outside the pay period");
    }//www.j  av  a  2s . co m
    if (errors.size() == 0 && !payInterval.contains(endTime) && p_cal_e_dt.getMillis() != endTime) {
        errors.add("The end date/time is outside the pay period");
    }
    return errors;
}

From source file:org.kuali.kpme.tklm.leave.summary.service.LeaveSummaryServiceImpl.java

License:Educational Community License

protected LeaveSummary getLeaveSummary(String principalId, LocalDate startDate, LocalDate endDate,
        String accrualCategory, boolean includeFuture) {
    LeaveSummary ls = new LeaveSummary();
    List<LeaveSummaryRow> rows = new ArrayList<LeaveSummaryRow>();

    if (StringUtils.isEmpty(principalId) || startDate == null || endDate == null) {
        return ls;
    }/*www. ja  va2  s  .com*/

    Set<String> leavePlans = getLeavePlans(principalId, startDate, endDate);
    PrincipalHRAttributes pha = getPrincipalHrAttributes(principalId, startDate, endDate);
    if (CollectionUtils.isNotEmpty(leavePlans)) {
        for (String aLpString : leavePlans) {
            LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(aLpString, startDate);
            if (lp == null) {
                continue;
            }
            DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMM d");
            DateTimeFormatter formatter2 = DateTimeFormat.forPattern("MMMM d yyyy");
            DateTime entryEndDate = endDate.toDateTimeAtStartOfDay();
            if (entryEndDate.getHourOfDay() == 0) {
                entryEndDate = entryEndDate.minusDays(1);
            }
            String aString = formatter.print(startDate) + " - " + formatter2.print(entryEndDate);
            ls.setPendingDatesString(aString);

            LeaveCalendarDocumentHeader approvedLcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService()
                    .getMaxEndDateApprovedLeaveCalendar(principalId);
            if (approvedLcdh != null) {
                DateTime endApprovedDate = approvedLcdh.getEndDateTime();
                LocalDateTime aLocalTime = approvedLcdh.getEndDateTime().toLocalDateTime();
                DateTime endApprovedTime = aLocalTime
                        .toDateTime(HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback());
                if (endApprovedTime.getHourOfDay() == 0) {
                    endApprovedDate = endApprovedDate.minusDays(1);
                }
                String datesString = formatter.print(approvedLcdh.getBeginDateTime()) + " - "
                        + formatter2.print(endApprovedDate);
                ls.setYtdDatesString(datesString);
            }

            //until we have something that creates carry over, we need to grab everything.
            // Calculating leave bLocks from Calendar Year start instead of Service Date
            Map<String, LeaveBlock> carryOverBlocks = getLeaveBlockService().getLastCarryOverBlocks(principalId,
                    startDate);

            boolean filterByAccrualCategory = false;
            if (StringUtils.isNotEmpty(accrualCategory)) {
                filterByAccrualCategory = true;
                //remove unwanted carry over blocks from map
                LeaveBlock carryOverBlock = carryOverBlocks.get(accrualCategory);
                carryOverBlocks = new HashMap<String, LeaveBlock>(1);
                if (ObjectUtils.isNotNull(carryOverBlock))
                    carryOverBlocks.put(carryOverBlock.getAccrualCategory(), carryOverBlock);
            }
            List<LeaveBlock> leaveBlocks = getLeaveBlockService().getLeaveBlocksSinceCarryOver(principalId,
                    carryOverBlocks, endDate, filterByAccrualCategory);

            List<LeaveBlock> futureLeaveBlocks = new ArrayList<LeaveBlock>();
            if (includeFuture) {
                if (!filterByAccrualCategory) {
                    futureLeaveBlocks = getLeaveBlockService().getLeaveBlocks(principalId, endDate,
                            endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths())));
                } else {
                    futureLeaveBlocks = getLeaveBlockService().getLeaveBlocksWithAccrualCategory(principalId,
                            endDate, endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths())),
                            accrualCategory);
                }
            }
            Map<String, List<LeaveBlock>> leaveBlockMap = mapLeaveBlocksByAccrualCategory(leaveBlocks);
            Map<String, List<LeaveBlock>> futureLeaveBlockMap = mapLeaveBlocksByAccrualCategory(
                    futureLeaveBlocks);
            List<AccrualCategory> acList = HrServiceLocator.getAccrualCategoryService()
                    .getActiveAccrualCategoriesForLeavePlan(lp.getLeavePlan(), endDate);
            if (CollectionUtils.isNotEmpty(acList)) {
                for (AccrualCategory ac : acList) {
                    if (ac.getShowOnGrid().equals("Y")) {

                        LeaveSummaryRow lsr = new LeaveSummaryRow();
                        lsr.setAccrualCategory(ac.getAccrualCategory());
                        lsr.setAccrualCategoryId(ac.getLmAccrualCategoryId());
                        //get max balances
                        AccrualCategoryRule acRule = HrServiceLocator.getAccrualCategoryRuleService()
                                .getAccrualCategoryRuleForDate(ac, endDate, pha.getServiceLocalDate());
                        //accrual category rule id set on a leave summary row will be useful in generating a relevant balance transfer
                        //document from the leave calendar display. Could put this id in the request for balance transfer document.
                        EmployeeOverride maxUsageOverride = LmServiceLocator.getEmployeeOverrideService()
                                .getEmployeeOverride(principalId, lp.getLeavePlan(), ac.getAccrualCategory(),
                                        "MU", endDate);

                        lsr.setAccrualCategoryRuleId(
                                acRule == null ? null : acRule.getLmAccrualCategoryRuleId());
                        if (acRule != null
                                && (acRule.getMaxBalance() != null || acRule.getMaxUsage() != null)) {
                            if (acRule.getMaxUsage() != null) {
                                lsr.setUsageLimit(new BigDecimal(acRule.getMaxUsage()).setScale(2));
                            } else {
                                lsr.setUsageLimit(null);
                            }

                        } else {
                            lsr.setUsageLimit(null);
                        }

                        if (maxUsageOverride != null)
                            lsr.setUsageLimit(new BigDecimal(maxUsageOverride.getOverrideValue()));

                        //Fetching leaveblocks for accCat with type CarryOver -- This is logic according to the CO blocks created from scheduler job.
                        BigDecimal carryOver = BigDecimal.ZERO.setScale(2);
                        lsr.setCarryOver(carryOver);

                        //handle up to current leave blocks
                        //CalendarEntry.getEndPeriodDate passed to fetch leave block amounts on last day of Calendar period
                        assignApprovedValuesToRow(lsr, ac.getAccrualCategory(),
                                leaveBlockMap.get(ac.getAccrualCategory()), lp, startDate, endDate);

                        //how about the leave blocks on the calendar entry being currently handled??
                        /*                            if(carryOverBlocks.containsKey(lsr.getAccrualCategory())) {
                                                       LeaveBlock carryOverBlock = carryOverBlocks.get(lsr.getAccrualCategory());
                                                       DateTime carryOverBlockLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), carryOverBlock.getLeaveDate());
                                                       DateTime currentLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), TKUtils.getCurrentDate());
                                                       if(carryOverBlockLPStart.equals(currentLPStart))
                          carryOver = carryOverBlock.getLeaveAmount();
                                                    }*/
                        //figure out past carry over values!!!
                        //We now have list of past years accrual and use (with ordered keys!!!)

                        //merge key sets
                        if (carryOverBlocks.containsKey(lsr.getAccrualCategory())) {
                            carryOver = carryOverBlocks.get(lsr.getAccrualCategory()).getLeaveAmount();
                            carryOver = carryOver.setScale(2);
                        }
                        Set<String> keyset = new HashSet<String>();
                        keyset.addAll(lsr.getPriorYearsUsage().keySet());
                        keyset.addAll(lsr.getPriorYearsTotalAccrued().keySet());
                        for (String key : keyset) {
                            BigDecimal value = lsr.getPriorYearsTotalAccrued().get(key);
                            if (value == null) {
                                value = BigDecimal.ZERO;
                            }
                            carryOver = carryOver.add(value);
                            BigDecimal use = lsr.getPriorYearsUsage().containsKey(key)
                                    ? lsr.getPriorYearsUsage().get(key)
                                    : BigDecimal.ZERO;
                            carryOver = carryOver.add(use);
                            EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService()
                                    .getEmployeeOverride(principalId, lp.getLeavePlan(),
                                            ac.getAccrualCategory(), "MAC", endDate);
                            if (acRule != null && acRule.getMaxCarryOver() != null) {
                                BigDecimal carryOverDisplay = BigDecimal.ZERO;
                                if (carryOverOverride != null)
                                    carryOverDisplay = new BigDecimal(
                                            carryOverOverride.getOverrideValue() < carryOver.longValue()
                                                    ? carryOverOverride.getOverrideValue()
                                                    : carryOver.longValue());
                                else
                                    carryOverDisplay = new BigDecimal(
                                            acRule.getMaxCarryOver() < carryOver.longValue()
                                                    ? acRule.getMaxCarryOver()
                                                    : carryOver.longValue());
                                carryOver = carryOverDisplay;
                            }
                        }

                        lsr.setCarryOver(carryOver);
                        if (acRule != null && acRule.getMaxCarryOver() != null) {
                            EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService()
                                    .getEmployeeOverride(principalId, lp.getLeavePlan(),
                                            ac.getAccrualCategory(), "MAC", endDate);
                            if (carryOverOverride != null)
                                lsr.setMaxCarryOver(new BigDecimal(carryOverOverride.getOverrideValue()));
                            else
                                lsr.setMaxCarryOver(
                                        new BigDecimal(acRule.getMaxCarryOver() < carryOver.longValue()
                                                ? acRule.getMaxCarryOver()
                                                : carryOver.longValue()));
                        }

                        //handle future leave blocks
                        assignPendingValuesToRow(lsr, ac.getAccrualCategory(),
                                futureLeaveBlockMap.get(ac.getAccrualCategory()));

                        //compute Leave Balance
                        BigDecimal leaveBalance = lsr.getAccruedBalance()
                                .subtract(lsr.getPendingLeaveRequests());
                        //if leave balance is set
                        //Employee overrides have already been taken into consideration and the appropriate values
                        //for usage have been set by this point.
                        //                            if (acRule != null && StringUtils.equals(acRule.getMaxBalFlag(), "Y")) {
                        //there exists an accrual category rule with max balance limit imposed.
                        //max bal flag = 'Y' has no precedence here with max-bal / balance transfers implemented.
                        //unless institutions are not required to define a max balance limit for action_at_max_bal = LOSE.
                        //Possibly preferable to procure forfeiture blocks through balance transfer
                        if (lsr.getUsageLimit() != null) { //should not set leave balance to usage limit simply because it's not null.
                            BigDecimal availableUsage = lsr.getUsageLimit()
                                    .subtract(lsr.getYtdApprovedUsage().add(lsr.getPendingLeaveRequests()));
                            if (leaveBalance.compareTo(availableUsage) > 0)
                                lsr.setLeaveBalance(availableUsage);
                            else
                                lsr.setLeaveBalance(leaveBalance);
                        } else { //no usage limit
                            lsr.setLeaveBalance(leaveBalance);
                        }

                        rows.add(lsr);
                    }
                }
                // let's check for 'empty' accrual categories
                if (leaveBlockMap.containsKey(null) || futureLeaveBlockMap.containsKey(null)) {
                    LeaveSummaryRow otherLeaveSummary = new LeaveSummaryRow();
                    //otherLeaveSummary.setAccrualCategory("Other");

                    assignApprovedValuesToRow(otherLeaveSummary, null, leaveBlockMap.get(null), lp, startDate,
                            endDate);
                    BigDecimal carryOver = BigDecimal.ZERO.setScale(2);
                    for (Map.Entry<String, BigDecimal> entry : otherLeaveSummary.getPriorYearsTotalAccrued()
                            .entrySet()) {
                        carryOver = carryOver.add(entry.getValue());
                        BigDecimal use = otherLeaveSummary.getPriorYearsUsage().containsKey(entry.getKey())
                                ? otherLeaveSummary.getPriorYearsUsage().get(entry.getKey())
                                : BigDecimal.ZERO;
                        carryOver = carryOver.add(use);
                    }
                    otherLeaveSummary.setCarryOver(carryOver);
                    assignPendingValuesToRow(otherLeaveSummary, null, futureLeaveBlockMap.get(null));
                    otherLeaveSummary.setAccrualCategory("Other");

                    //compute Leave Balance
                    // blank the avail
                    otherLeaveSummary.setUsageLimit(null);
                    otherLeaveSummary.setLeaveBalance(null);

                    rows.add(otherLeaveSummary);
                }
            }
        }
    }
    ls.setLeaveSummaryRows(rows);
    return ls;
}

From source file:org.kuali.kpme.tklm.time.flsa.FlsaDay.java

License:Educational Community License

/**
 *
 * @param flsaDate A LocalDateTime because we want to be conscious of the
 * relative nature of this flsa/window/*w  w w .  java 2 s  .c o  m*/
 * @param timeBlocks
 * @param timeZone The timezone we are constructing, relative.
 */
public FlsaDay(LocalDateTime flsaDate, List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks,
        DateTimeZone timeZone) {
    this.flsaDate = flsaDate;
    this.timeZone = timeZone;
    flsaDateInterval = new Interval(flsaDate.toDateTime(timeZone), flsaDate.toDateTime(timeZone).plusHours(24));
    this.setTimeBlocks(timeBlocks);
    this.setLeaveBlocks(leaveBlocks);
}

From source file:org.kuali.kpme.tklm.time.rules.shiftdifferential.shift.ShiftCalendarInterval.java

License:Educational Community License

protected List<Shift> createShifts(ShiftDifferentialRule rule, LocalDateTime spanBegin, LocalDateTime spanEnd,
        DateTimeZone zone) {/*www.j a v a 2 s.  com*/
    DateTime spanBeginDT = spanBegin.toDateTime(zone);
    DateTime spanEndDT = spanEnd.toDateTime(zone);
    Interval calendarEntryInterval = new Interval(spanBeginDT, spanEndDT);
    DateTime shiftEnd = LocalTime.fromDateFields(rule.getEndTime()).toDateTime(spanBeginDT).minusDays(1);
    DateTime shiftStart = LocalTime.fromDateFields(rule.getBeginTime()).toDateTime(spanBeginDT).minusDays(1);

    if (shiftEnd.isBefore(shiftStart) || shiftEnd.isEqual(shiftStart)) {
        shiftEnd = shiftEnd.plusDays(1);
    }

    List<Shift> shifts = new ArrayList<Shift>();
    Interval shiftInterval = new Interval(shiftStart, shiftEnd);
    //possible that there is no overlap between 1st interval and cal entry interval... if so, add a day.
    if (!calendarEntryInterval.overlaps(shiftInterval)) {
        shiftInterval = incrementShift(shiftInterval);
    }
    while (calendarEntryInterval.overlaps(shiftInterval)) {
        if (ruleIsActiveForDay(shiftInterval.getStart(), rule)) {
            shifts.add(new Shift(rule, shiftInterval, zone));
        }
        shiftInterval = incrementShift(shiftInterval);
    }
    return shifts;
}

From source file:org.mobicents.servlet.restcomm.RvdProjectsMigrator.java

License:Open Source License

private String getTimeStamp() {
    LocalDateTime date = LocalDateTime.now();
    DateTimeZone tz = DateTimeZone.getDefault();
    return new Timestamp(date.toDateTime(tz).toDateTime(DateTimeZone.UTC).getMillis()).toString();
}

From source file:org.odata4j.producer.inmemory.BeanModel.java

License:Open Source License

/**
 * Updates an instance to set a property to a given value
 * This method is only intended to be used for simple properties
 *
 * @param target the instance to update/*from   w w  w  .  j  av  a2s.c  o  m*/
 * @param propertyName the name of the property
 * @param propertyValue the value to set in the property
 */
public void setPropertyValue(Object target, String propertyName, Object propertyValue) {
    Method method = getSetter(propertyName);
    if (!method.isAccessible())
        method.setAccessible(true);
    try {

        // if a joda time, make sure the pojo also expects a joda time
        // otherwise try to set the value as a java.util.Date
        Class<?> argumentType = method.getParameterTypes()[0];
        if (propertyValue instanceof LocalDateTime) {
            if (argumentType.isAssignableFrom(LocalDateTime.class)) {
                method.invoke(target, propertyValue);
                return;
            } else if (argumentType.isAssignableFrom(Date.class)) {
                LocalDateTime jodaDate = (LocalDateTime) propertyValue;
                Date javaDate = new Date(jodaDate.toDateTime(DateTimeZone.UTC).getMillis());
                method.invoke(target, javaDate);
                return;
            }
        } else if (propertyValue instanceof Guid) {
            if (argumentType.isAssignableFrom(String.class)) {
                Guid guid = (Guid) propertyValue;
                propertyValue = guid.getValue();
            }
        }
        method.invoke(target, propertyValue);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}