List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime(Object instant)
From source file:org.gnucash.android.ui.report.LineChartFragment.java
License:Apache License
/** * Returns entries which represent a user data of the specified account type * @param accountType account's type which user data will be processed * @return entries which represent a user data *///w w w.j a v a 2s . co m private List<Entry> getEntryList(AccountType accountType) { List<String> accountUIDList = new ArrayList<>(); for (Account account : mAccountsDbAdapter.getSimpleAccountList()) { if (account.getAccountType() == accountType && !account.isPlaceholderAccount() && account.getCurrency() == mCurrency) { accountUIDList.add(account.getUID()); } } LocalDateTime earliest; LocalDateTime latest; if (mReportStartTime == -1 && mReportEndTime == -1) { earliest = new LocalDateTime(mEarliestTimestampsMap.get(accountType)); latest = new LocalDateTime(mLatestTimestampsMap.get(accountType)); } else { earliest = new LocalDateTime(mReportStartTime); latest = new LocalDateTime(mReportEndTime); } Log.d(TAG, "Earliest " + accountType + " date " + earliest.toString("dd MM yyyy")); Log.d(TAG, "Latest " + accountType + " date " + latest.toString("dd MM yyyy")); int xAxisOffset = getDateDiff(new LocalDateTime(mEarliestTransactionTimestamp), earliest); int count = getDateDiff(earliest, latest); List<Entry> values = new ArrayList<>(count + 1); for (int i = 0; i <= count; i++) { long start = 0; long end = 0; switch (mGroupInterval) { case QUARTER: int quarter = getQuarter(earliest); start = earliest.withMonthOfYear(quarter * 3 - 2).dayOfMonth().withMinimumValue().millisOfDay() .withMinimumValue().toDate().getTime(); end = earliest.withMonthOfYear(quarter * 3).dayOfMonth().withMaximumValue().millisOfDay() .withMaximumValue().toDate().getTime(); earliest = earliest.plusMonths(3); break; case MONTH: start = earliest.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate() .getTime(); end = earliest.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime(); earliest = earliest.plusMonths(1); break; case YEAR: start = earliest.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime(); end = earliest.dayOfYear().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime(); earliest = earliest.plusYears(1); break; } float balance = (float) mAccountsDbAdapter.getAccountsBalance(accountUIDList, start, end).asDouble(); values.add(new Entry(balance, i + xAxisOffset)); Log.d(TAG, accountType + earliest.toString(" MMM yyyy") + ", balance = " + balance); } return values; }
From source file:org.gnucash.android.ui.report.PieChartFragment.java
License:Apache License
@Override public void onAccountTypeUpdated(AccountType accountType) { mAccountType = accountType;/* w w w .java 2 s .c o m*/ mEarliestTransactionDate = new LocalDateTime( mTransactionsDbAdapter.getTimestampOfEarliestTransaction(mAccountType, mCurrencyCode)); mLatestTransactionDate = new LocalDateTime( mTransactionsDbAdapter.getTimestampOfLatestTransaction(mAccountType, mCurrencyCode)); mChartDate = mLatestTransactionDate; displayChart(); }
From source file:org.isisaddons.module.excel.dom.CellMarshaller.java
License:Apache License
@SuppressWarnings("unchecked") private <T> T getCellValue(final Cell cell, final Class<T> requiredType) { final int cellType = cell.getCellType(); if (requiredType == boolean.class || requiredType == Boolean.class) { if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) { boolean booleanCellValue = cell.getBooleanCellValue(); return (T) Boolean.valueOf(booleanCellValue); } else {/* w ww . j a v a2s . co m*/ return null; } } // enum if (Enum.class.isAssignableFrom(requiredType)) { String stringCellValue = cell.getStringCellValue(); @SuppressWarnings("rawtypes") Class rawType = requiredType; return (T) Enum.valueOf(rawType, stringCellValue); } // date if (requiredType == java.util.Date.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) dateCellValue; } if (requiredType == org.apache.isis.applib.value.Date.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) new org.apache.isis.applib.value.Date(dateCellValue); } if (requiredType == org.apache.isis.applib.value.DateTime.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) new org.apache.isis.applib.value.DateTime(dateCellValue); } if (requiredType == LocalDate.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) new LocalDate(dateCellValue.getTime()); } if (requiredType == LocalDateTime.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) new LocalDateTime(dateCellValue.getTime()); } if (requiredType == DateTime.class) { java.util.Date dateCellValue = cell.getDateCellValue(); return (T) new DateTime(dateCellValue.getTime()); } // number if (requiredType == double.class || requiredType == Double.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { double doubleValue = cell.getNumericCellValue(); return (T) Double.valueOf(doubleValue); } else { return null; } } if (requiredType == float.class || requiredType == Float.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { float floatValue = (float) cell.getNumericCellValue(); return (T) Float.valueOf(floatValue); } else { return null; } } if (requiredType == BigDecimal.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { double doubleValue = cell.getNumericCellValue(); return (T) BigDecimal.valueOf(doubleValue); } else { return null; } } if (requiredType == BigInteger.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { long longValue = (long) cell.getNumericCellValue(); return (T) BigInteger.valueOf(longValue); } else { return null; } } if (requiredType == long.class || requiredType == Long.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { long longValue = (long) cell.getNumericCellValue(); return (T) Long.valueOf(longValue); } else { return null; } } if (requiredType == int.class || requiredType == Integer.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { int intValue = (int) cell.getNumericCellValue(); return (T) Integer.valueOf(intValue); } else { return null; } } if (requiredType == short.class || requiredType == Short.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { short shortValue = (short) cell.getNumericCellValue(); return (T) Short.valueOf(shortValue); } else { return null; } } if (requiredType == byte.class || requiredType == Byte.class) { if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { byte byteValue = (byte) cell.getNumericCellValue(); return (T) Byte.valueOf(byteValue); } else { return null; } } if (requiredType == String.class) { if (cellType == HSSFCell.CELL_TYPE_STRING) { return (T) cell.getStringCellValue(); } else { return null; } } return null; }
From source file:org.jobscheduler.dashboard.repository.CustomAuditEventRepository.java
License:Apache License
@Bean public AuditEventRepository auditEventRepository() { return new AuditEventRepository() { @Inject/* w w w. java 2s. c o m*/ private AuditEventConverter auditEventConverter; @Override public List<AuditEvent> find(String principal, Date after) { final List<PersistentAuditEvent> persistentAuditEvents; if (principal == null && after == null) { persistentAuditEvents = persistenceAuditEventRepository.findAll(); } else if (after == null) { persistentAuditEvents = persistenceAuditEventRepository.findByPrincipal(principal); } else { persistentAuditEvents = persistenceAuditEventRepository .findByPrincipalAndAuditEventDateGreaterThan(principal, new LocalDateTime(after)); } return auditEventConverter.convertToAuditEvent(persistentAuditEvents); } @Override public void add(AuditEvent event) { PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent(); persistentAuditEvent.setPrincipal(event.getPrincipal()); persistentAuditEvent.setAuditEventType(event.getType()); persistentAuditEvent.setAuditEventDate(new LocalDateTime(event.getTimestamp())); persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData())); persistenceAuditEventRepository.save(persistentAuditEvent); } }; }
From source file:org.kitodo.production.services.security.SessionService.java
License:Open Source License
/** * Gets all active sessions./*w w w. java 2 s . c o m*/ * * @return The active sessions. */ public List<SecuritySession> getActiveSessions() { List<Object> allPrincipals = sessionRegistry.getAllPrincipals(); List<SecuritySession> activeSessions = new ArrayList<>(); UserDetails user = null; for (final Object principal : allPrincipals) { if (principal instanceof SecurityUserDetails) { user = (SecurityUserDetails) principal; } if (Objects.nonNull(user)) { List<SessionInformation> activeSessionInformation = new ArrayList<>( sessionRegistry.getAllSessions(principal, false)); for (SessionInformation sessionInformation : activeSessionInformation) { SecuritySession securitySession = new SecuritySession(); securitySession.setUserName(user.getUsername()); securitySession.setSessionId(sessionInformation.getSessionId()); securitySession.setLastRequest(new LocalDateTime(sessionInformation.getLastRequest())); activeSessions.add(securitySession); } } } return activeSessions; }
From source file:org.kitodo.services.security.SessionService.java
License:Open Source License
/** * Gets all active sessions./* www. j av a 2s . co m*/ * * @return The active sessions. */ public List<SecuritySession> getActiveSessions() { List<Object> allPrincipals = sessionRegistry.getAllPrincipals(); List<SecuritySession> activeSessions = new ArrayList<>(); UserDetails user = null; for (final Object principal : allPrincipals) { if (principal instanceof LdapUserDetails) { user = (LdapUserDetailsImpl) principal; } if (principal instanceof SecurityUserDetails) { user = (SecurityUserDetails) principal; } if (user != null) { List<SessionInformation> activeSessionInformation = new ArrayList<>( sessionRegistry.getAllSessions(principal, false)); for (SessionInformation sessionInformation : activeSessionInformation) { SecuritySession securitySession = new SecuritySession(); securitySession.setUserName(user.getUsername()); securitySession.setSessionId(sessionInformation.getSessionId()); securitySession.setLastRequest(new LocalDateTime(sessionInformation.getLastRequest())); activeSessions.add(securitySession); } } } return activeSessions; }
From source file:org.kuali.kpme.core.api.util.jaxb.LocalDateTimeAdapter.java
License:Educational Community License
@Override public LocalDateTime unmarshal(Calendar calendar) throws Exception { return calendar == null ? null : new LocalDateTime(calendar.getTimeInMillis()); }
From source file:org.kuali.kpme.tklm.leave.batch.CarryOverJob.java
License:Educational Community License
@Override public void execute(JobExecutionContext context) throws JobExecutionException { String batchUserPrincipalId = getBatchUserPrincipalId(); if (batchUserPrincipalId != null) { JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); String leavePlan = jobDataMap.getString("leavePlan"); if (leavePlan != null) { LocalDate asOfDate = LocalDate.now(); LeavePlan leavePlanObj = getLeavePlanService().getLeavePlan(leavePlan, asOfDate); List<Assignment> assignments = getAssignmentService().getActiveAssignments(asOfDate); //holds a list of principalIds so this isn't run multiple time for the same person Set<String> principalIds = new HashSet<String>(); for (Assignment assignment : assignments) { String principalId = assignment.getPrincipalId(); if (assignment.getJob().isEligibleForLeave() && !principalIds.contains(principalId)) { PrincipalHRAttributes principalHRAttributes = getPrincipalHRAttributesService() .getPrincipalCalendar(principalId, asOfDate); principalIds.add(principalId); if (principalHRAttributes != null) { LocalDate serviceDate = principalHRAttributes.getServiceLocalDate(); if (serviceDate != null) { if (leavePlanObj != null && leavePlanObj.getLeavePlan() .equalsIgnoreCase(principalHRAttributes.getLeavePlan())) { DateTime leavePlanStartDate = getLeavePlanService() .getFirstDayOfLeavePlan(leavePlan, LocalDate.now()); DateTime lpPreviousLastDay = (new LocalDateTime(leavePlanStartDate)) .toDateTime().minus(1); DateTime lpPreviousFirstDay = getLeavePlanService() .getFirstDayOfLeavePlan(leavePlan, lpPreviousLastDay.toLocalDate()); List<LeaveBlock> prevYearCarryOverleaveBlocks = getLeaveBlockService() .getLeaveBlocksWithType(principalId, lpPreviousFirstDay.toLocalDate(), lpPreviousLastDay.toLocalDate(), LMConstants.LEAVE_BLOCK_TYPE.CARRY_OVER); LeaveSummary leaveSummary = getLeaveSummaryService() .getLeaveSummaryAsOfDateWithoutFuture(principalId, lpPreviousLastDay.toLocalDate()); //no existing carry over blocks. just create new if (CollectionUtils.isEmpty(prevYearCarryOverleaveBlocks)) { getLeaveBlockService().saveLeaveBlocks(createCarryOverLeaveBlocks( principalId, lpPreviousLastDay, leaveSummary)); } else { Map<String, LeaveBlock> existingCarryOver = new HashMap<String, LeaveBlock>( prevYearCarryOverleaveBlocks.size()); // just easier to get to things when in a map... for (LeaveBlock lb : prevYearCarryOverleaveBlocks) { existingCarryOver.put(lb.getAccrualCategory(), lb); }//from w ww .jav a 2 s. com // update existing first for (Map.Entry<String, LeaveBlock> entry : existingCarryOver.entrySet()) { LeaveBlock carryOverBlock = entry.getValue(); LeaveSummaryRow lsr = leaveSummary .getLeaveSummaryRowForAccrualCtgy(entry.getKey()); //update values if (lsr.getAccruedBalance() != null) { if (lsr.getMaxCarryOver() != null && lsr.getAccruedBalance() .compareTo(lsr.getMaxCarryOver()) > 0) { carryOverBlock.setLeaveAmount(lsr.getMaxCarryOver()); } else { carryOverBlock.setLeaveAmount(lsr.getAccruedBalance()); } } getLeaveBlockService().updateLeaveBlock(carryOverBlock, batchUserPrincipalId); //remove row from leave summary leaveSummary.getLeaveSummaryRows().remove(lsr); } // create for any new accrual categories getLeaveBlockService().saveLeaveBlocks(createCarryOverLeaveBlocks( principalId, lpPreviousLastDay, leaveSummary)); } } } } } } } } else { String principalName = ConfigContext.getCurrentContextConfig() .getProperty(TkConstants.BATCH_USER_PRINCIPAL_NAME); LOG.error("Could not run batch jobs due to missing batch user " + principalName); } }
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java
License:Educational Community License
protected void setLeaveSummary(LeaveCalendarForm leaveCalendarForm) throws Exception { String principalId = HrContext.getTargetPrincipalId(); CalendarEntry calendarEntry = leaveCalendarForm.getCalendarEntry(); PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate()); //check to see if we are on a previous leave plan if (principalHRAttributes != null) { DateTime currentYearBeginDate = HrServiceLocator.getLeavePlanService() .getFirstDayOfLeavePlan(principalHRAttributes.getLeavePlan(), LocalDate.now()); DateTime calEntryEndDate = calendarEntry.getEndPeriodFullDateTime(); if (calEntryEndDate.getMillis() > currentYearBeginDate.getMillis()) { //current or future year LeaveSummary ls = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(principalId, calendarEntry);//from www . ja va 2 s . c o m leaveCalendarForm.setLeaveSummary(ls); } else { //current year roll over date has been passed, all previous calendars belong to the previous leave plan calendar year. DateTime effDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan( principalHRAttributes.getLeavePlan(), calEntryEndDate.minusDays(1).toLocalDate()); LeaveSummary ls = LmServiceLocator.getLeaveSummaryService() .getLeaveSummaryAsOfDateWithoutFuture(principalId, effDate.toLocalDate()); //override title element (based on date passed in) DateFormat formatter = new SimpleDateFormat("MMMM d"); DateFormat formatter2 = new SimpleDateFormat("MMMM d yyyy"); DateTime entryEndDate = new LocalDateTime(calendarEntry.getEndPeriodDate()).toDateTime(); if (entryEndDate.getHourOfDay() == 0) { entryEndDate = entryEndDate.minusDays(1); } String aString = formatter.format(calendarEntry.getBeginPeriodDate()) + " - " + formatter2.format(entryEndDate.toDate()); ls.setPendingDatesString(aString); DateTimeFormatter fmt = DateTimeFormat.forPattern("MMM d, yyyy"); ls.setNote("Values as of: " + fmt.print(effDate)); leaveCalendarForm.setLeaveSummary(ls); } } }
From source file:org.kuali.student.r2.common.dto.TimeOfDayInfo.java
License:Educational Community License
/** * * @param date a java.util.Date to which timeOfDay is added (the hours, minutes, seconds * and milliseconds are ignored and treated as 0. Only the month, day, year * of date is relevant)//from w ww . j a v a2s . c om * @param timeOfDay the TimeOfDay that is added to the date parameter * @return a java.util.Date that is the sum of date and timeOfDay */ public static Date getDateWithTimeOfDay(Date date, TimeOfDay timeOfDay) { if (date == null || timeOfDay == null) { return null; } // This is JODA which is the preferred way to deal with time. // One issue: Java's Date class doesn't have a way to store the timezone associated with the date. // Instead, it saves millis since Jan 1, 1970 (GMT), and uses the local machine's timezone to // interpret it (although, it can also handle UTC as a timezone). To store the timezone, you either // need Joda's LocalDateTime or use the Calendar class. Thus, it is recommended that you either // pass in the date relative to the current timezone, or perhaps redo this class where you pass // a timezone in, and don't use a Date class, but use a Joda DateTime class. --cclin LocalDateTime time = new LocalDateTime(date); LocalDateTime result = new LocalDateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), timeOfDay.getHour() == null ? 0 : timeOfDay.getHour(), timeOfDay.getMinute() == null ? 0 : timeOfDay.getMinute(), timeOfDay.getSecond() == null ? 0 : timeOfDay.getSecond(), 0); return result.toDate(); }