List of usage examples for org.joda.time LocalDate getMonthOfYear
public int getMonthOfYear()
From source file:eu.europa.ec.grow.espd.xml.common.importing.UblRequestResponseImporter.java
License:EUPL
protected final Date readIssueDate(IssueDateType issueDateType, IssueTimeType issueTimeType) { if (issueDateType == null || issueDateType.getValue() == null) { return null; }/* w w w . j a va2 s .c om*/ LocalDate localDate = issueDateType.getValue(); if (issueTimeType != null && issueTimeType.getValue() != null) { LocalTime localTime = issueTimeType.getValue(); return new LocalDateTime(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), localTime.getHourOfDay(), localTime.getMinuteOfHour(), localTime.getSecondOfMinute()).toDate(); } return new LocalDateTime(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), 0, 0, 0).toDate(); }
From source file:eu.trentorise.game.sample.DemoGameFactory.java
License:Apache License
private String generateCronExp() { // sample 0 2 0 4 JUN ? * LocalDate now = LocalDate.now(); return String.format("0 0 0 %s %s ? %s", now.getDayOfMonth() - 1, now.getMonthOfYear(), now.getYear()); }
From source file:fr.esecure.banking.PDFTransactionRapport.java
public String generateReport(List<Transaction> listInput, String outputFilename) throws Exception { remplirListTransactionRow(listInput); if (outputFilename == null) { outputFilename = defaultPath;//w ww . j a v a2 s . c o m } LocalDate localDate = new LocalDate(); String rapportDate = localDate.getDayOfMonth() + "_" + localDate.getMonthOfYear() + "_" + localDate.getYear(); outputFilename = outputFilename + "/rapport_" + rapportDate + ".pdf"; try { generateAndSaveReport(outputFilename); listInput = null; } catch (Exception ex) { LOG.log(Level.SEVERE, "Une exception s'est produite pendant la generation du rapport PDF : " + ex.getMessage()); throw ex; } return outputFilename; }
From source file:gg.db.datamodel.Period.java
License:Open Source License
/** * Is the specified period valid?/*from w w w . jav a 2 s .com*/ * @param startDate Start date of the period * @param endDate End date of the period * @param periodType Type of the period * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/> * To be valid, a period has to be a "full" period: * <UL> * <LI> For each type of period: Start date > End date</LI> * <LI> For DAY period: number of days between Start date and End date = 0<BR/> * Example: <I>From 12/30/2005 to 12/30/2005</I></LI> * <LI> For WEEK period: number of days between Start date and End date = 6<BR/> * The period has to start on MONDAY<BR/> * The period has to end on SUNDAY<BR/> * Example: <I>From 12/01/2005 to 12/18/2005</I></LI> * <LI> For MONTH period: number of month between Start date and End date = 0<BR/> * The period has to start on the first day of the month (05/01/2006)<BR/> * The period has to end on the last day of the month (05/31/2006)<BR/> * Number of months between Start date - 1 day and End date = 1<BR/> * Number of months between Start date and End date + 1 day = 1<BR/> * Example: <I>From 03/01/2005 to 03/31/2005</I></LI> * <LI> For YEAR period: number of years between Start date and End date = 0<BR/> * The period has to start on the first day of the first month (01/01/2006)<BR/> * The period has to end in December<BR/> * The period has to end on the last day of the last month (12/31/2006)<BR/> * Number of years between Start date - 1 day and End date = 1<BR/> * Number of years between Start date and End date + 1 day = 1<BR/> * Example: <I>From 01/01/2006 to 12/31/2006</I></LI> * </UL> */ private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) { boolean periodValid = true; // Is the period valid // Check if Start date < End date if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) { periodValid = false; } // Check if the period is a "full" period if (periodValid && startDate != null && endDate != null && periodType != null) { switch (periodType) { case DAY: // i.e. a DAY period: from 05/12/2006 to 05/12/2006 if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1 (Nb of days = 1) (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0) (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1) periodValid = false; } break; case WEEK: // i.e. a WEEK period: from 05/12/2006 to 05/18/2006 if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1) (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0) (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1) periodValid = false; } break; case MONTH: // i.e. a MONTH period: from 05/01/2006 to 05/30/2006 if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1) (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0) (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1) periodValid = false; } break; case YEAR: // i.e. a YEAR period: from 01/01/2006 to 12/31/2006 if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1) (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0) (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1) periodValid = false; } break; case FREE: // There is no constraint on the number of units for FREE type of period break; default: // Should never happen throw new AssertionError("The PeriodType is unknown"); } } return periodValid; }
From source file:it.webappcommon.lib.DateUtils.java
License:Open Source License
public static DateTime mergeDateTime2(Date date, Date time) { // setup objects // LocalDate localDate = new LocalDate(date.getYear(), date.getMonth(), // date.getDate()); // LocalTime localTime = new LocalTime(time.getHours(), // time.getMinutes(), time.getSeconds()); // LocalDate localDate = new LocalDate(date.getTime()); // LocalTime localTime = new LocalTime(time.getHours(), // time.getMinutes(), time.getSeconds()); // DateTime dt = localDate.toDateTime(localTime); // DateTime dt = new DateTime(date.getYear(), date.getMonth(), // date.getDate(), time.getHours(), time.getMinutes(), // time.getSeconds()); // DateTime dt1 = new DateTime(date.getTime()); // DateTime dt2 = new DateTime(time.getTime()); // DateTime dt = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), // dt1.getDayOfMonth(), dt2.getHourOfDay(), dt2.getMinuteOfHour(), // dt2.getSecondOfMinute()); LocalDate localDate = new LocalDate(date.getTime()); int year = localDate.getYear(); // date.getYear(); int month = localDate.getMonthOfYear(); // date.getMonth(); int day = localDate.getDayOfMonth(); // date.getDate(); int h = time.getHours(); int m = time.getMinutes(); int s = time.getSeconds(); logger.debug(String.format("%s-%s-%s %s:%s:%s", year, month, day, h, m, s)); DateTime dt = new DateTime(year, month, day, h, m, s, DateTimeZone.UTC); return dt;/*from w w w .j av a 2s .com*/ }
From source file:julian.lylly.model.Util.java
public static String daysToDate(LocalDate date) {//TODO: weak int y = date.getYear(); int m = date.getMonthOfYear(); int d = date.getDayOfMonth(); return y + "-" + longTo2DigitString(m) + "-" + longTo2DigitString(d); }
From source file:module.mission.domain.EmailDigesterUtil.java
License:Open Source License
public static void executeTask() { I18N.setLocale(new Locale(CoreConfiguration.getConfiguration().defaultLocale())); for (Person person : getPeopleToProcess()) { final User user = person.getUser(); if (user.getPerson() != null && user.getExpenditurePerson() != null) { Authenticate.mock(user, "System Automation"); try { final MissionYear missionYear = MissionYear.getCurrentYear(); final LocalDate today = new LocalDate(); final MissionYear previousYear = today.getMonthOfYear() == Month.JANUARY ? MissionYear.findOrCreateMissionYear(today.getYear() - 1) : null;// w w w . ja va2 s . co m Map<String, List<MissionProcessBean>> processesTypeMap = new LinkedHashMap<>(); processesTypeMap.put(TAKEN, getMissionProcessBeans(getTaken(missionYear, previousYear))); if (previousYear == null) { processesTypeMap.put(PENDING_APPROVAL, getMissionProcessBeans(missionYear.getPendingAproval())); processesTypeMap.put(PENDING_VEHICLE, getMissionProcessBeans(missionYear.getPendingVehicleAuthorization())); processesTypeMap.put(PENDING_AUTHORIZATION, getMissionProcessBeans(missionYear.getPendingAuthorization())); processesTypeMap.put(PENDING_FUND, getMissionProcessBeans(missionYear.getPendingFundAllocation())); processesTypeMap.put(PENDING_PROCESSING, getMissionProcessBeans(missionYear.getPendingProcessingPersonelInformation())); } else { processesTypeMap.put(PENDING_APPROVAL, getMissionProcessBeans( previousYear.getPendingAproval(() -> missionYear.getPendingAproval()))); processesTypeMap.put(PENDING_VEHICLE, getMissionProcessBeans(previousYear.getPendingVehicleAuthorization( () -> missionYear.getPendingVehicleAuthorization()))); processesTypeMap.put(PENDING_AUTHORIZATION, getMissionProcessBeans( previousYear.getPendingAuthorization(() -> missionYear.getPendingAuthorization()))); processesTypeMap.put(PENDING_FUND, getMissionProcessBeans(previousYear .getPendingFundAllocation(() -> missionYear.getPendingFundAllocation()))); processesTypeMap.put(PENDING_PROCESSING, getMissionProcessBeans(previousYear.getPendingProcessingPersonelInformation( () -> missionYear.getPendingProcessingPersonelInformation()))); } final int totalPending = processesTypeMap.values().stream().map(Collection::size).reduce(0, Integer::sum); if (totalPending > 0) { Message.fromSystem().to(Group.users(person.getUser())) .template("expenditures.mission.pending") .parameter("applicationTitle", Bennu.getInstance().getConfiguration().getApplicationSubTitle() .getContent()) .parameter("applicationUrl", CoreConfiguration.getConfiguration().applicationUrl()) .parameter("processesByType", processesTypeMap) .parameter("processesTotal", totalPending).and().send(); } } finally { Authenticate.unmock(); } } } }
From source file:module.mission.domain.EmailDigesterUtil.java
License:Open Source License
private static Collection<Person> getPeopleToProcess() { final Set<Person> people = new HashSet<Person>(); final LocalDate today = new LocalDate(); final ExpenditureTrackingSystem expendituresSystem = ExpenditureTrackingSystem.getInstance(); for (User user : MissionSystem.getInstance().getVehicleAuthorizersSet()) { people.add(user.getExpenditurePerson()); }/*from w w w . j a va 2s . c o m*/ for (final Authorization authorization : expendituresSystem.getAuthorizationsSet()) { if (authorization.isValidFor(today)) { final Person person = authorization.getPerson(); if (person.getOptions().getReceiveNotificationsByEmail()) { people.add(person); } } } for (final RoleType roleType : RoleType.values()) { addPeopleWithRole(people, roleType); } for (final AccountingUnit accountingUnit : expendituresSystem.getAccountingUnitsSet()) { addPeople(people, accountingUnit.getPeopleSet()); addPeople(people, accountingUnit.getProjectAccountantsSet()); addPeople(people, accountingUnit.getResponsiblePeopleSet()); addPeople(people, accountingUnit.getResponsibleProjectAccountantsSet()); addPeople(people, accountingUnit.getTreasuryMembersSet()); } final MissionYear missionYear = MissionYear.getCurrentYear(); addRequestorsAndResponsibles(people, missionYear); if (today.getMonthOfYear() == Month.JANUARY) { final MissionYear previousYear = MissionYear.findOrCreateMissionYear(today.getYear() - 1); addRequestorsAndResponsibles(people, previousYear); } return people; }
From source file:module.mission.domain.util.MissionPendingProcessCounter.java
License:Open Source License
@Override public int getCount() { try {/*from w w w. j ava 2s.c o m*/ final MissionYear missionYear = MissionYear.getCurrentYear(); final LocalDate today = new LocalDate(); final MissionYear previousYear = today.getMonthOfYear() == Month.JANUARY ? MissionYear.findOrCreateMissionYear(today.getYear() - 1) : null; final int takenByUser = (int) (missionYear.getTakenStream().count() + (previousYear == null ? 0 : previousYear.getTakenStream().count())); final long pendingApprovalCount = missionYear.getPendingAproval().count() + (previousYear == null ? 0 : previousYear.getPendingAproval().count()); final long pendingAuthorizationCount = missionYear.getPendingAuthorization().count() + (previousYear == null ? 0 : previousYear.getPendingAuthorization().count()); final long pendingFundAllocationCount = missionYear.getPendingFundAllocation().count() + (previousYear == null ? 0 : previousYear.getPendingFundAllocation().count()); final long pendingProcessingCount = missionYear.getPendingProcessingPersonelInformation().count() + (previousYear == null ? 0 : previousYear.getPendingProcessingPersonelInformation().count()); return (int) (takenByUser + pendingApprovalCount + pendingAuthorizationCount + pendingFundAllocationCount + pendingProcessingCount); } catch (final Throwable t) { t.printStackTrace(); //throw new Error(t); return 0; } }
From source file:module.siadap.domain.util.SiadapMiscUtilClass.java
License:Open Source License
/** * //from w w w .j av a 2s . com * @param date * the {@link LocalDate} that will be converted to represent the * date at the beginning of the day * @return an {@link ReadableInstant} with the same day/month/year but the * last instant of it, that is the last hour, last minute, last * second etc... */ public static ReadableInstant convertDateToEndOfDay(LocalDate date) { ReadableInstant newLocalDate = null; if (date != null) { return new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 23, 59, 59, 59); } return newLocalDate; }