List of usage examples for org.joda.time DateTime withDayOfMonth
public DateTime withDayOfMonth(int dayOfMonth)
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
private void calculateFirstAndLastInstantInMonthlyMode(YearMonthDay begin) { if (begin == null) { throw new IllegalArgumentException(); }//from w ww. ja va 2 s. c o m DateTime beginDateTime = begin.toDateTimeAtMidnight(); beginDateTime = (beginDateTime.getDayOfMonth() != 1) ? beginDateTime.withDayOfMonth(1) : beginDateTime; setFirstInstant(beginDateTime); setLastInstant(beginDateTime.plusMonths(1).minusDays(1)); }
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
public int getMonthsDaysSize() { int result = 0; for (DateTime month : getMonths()) { DateTime firstDayOfMonth = (month.getDayOfMonth() != 1) ? month.withDayOfMonth(1) : month; DateTime lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1); int monthNumberOfDays = Days.daysBetween(firstDayOfMonth, lastDayOfMonth).getDays() + 1; result += monthNumberOfDays;/*from w w w . ja v a 2 s .c o m*/ } return result; }
From source file:org.efaps.esjp.accounting.SubJournal_Base.java
License:Apache License
/** * Insert post trigger.// ww w. j a v a2 s . c om * * @param _parameter the parameter * @return the return * @throws EFapsException the e faps exception */ public Return insertPostTrigger(final Parameter _parameter) throws EFapsException { final PrintQuery print = new PrintQuery(_parameter.getInstance()); final SelectBuilder selRepInst = SelectBuilder.get() .linkto(CIAccounting.ReportSubJournal2Transaction.FromLink).instance(); final SelectBuilder selRepName = SelectBuilder.get() .linkto(CIAccounting.ReportSubJournal2Transaction.FromLink) .attribute(CIAccounting.ReportSubJournal.Name); final SelectBuilder selTransDate = SelectBuilder.get() .linkto(CIAccounting.ReportSubJournal2Transaction.ToLink).attribute(CIAccounting.Transaction.Date); print.addSelect(selRepInst, selRepName, selTransDate); print.executeWithoutAccessCheck(); final Instance repInst = print.<Instance>getSelect(selRepInst); final String repName = print.<String>getSelect(selRepName); final DateTime transDate = print.<DateTime>getSelect(selTransDate); final QueryBuilder attrQueryBldr = new QueryBuilder(CIAccounting.Transaction); attrQueryBldr.addWhereAttrGreaterValue(CIAccounting.Transaction.Date, transDate.withDayOfMonth(1).withTimeAtStartOfDay().minusSeconds(1)); attrQueryBldr.addWhereAttrLessValue(CIAccounting.Transaction.Date, transDate.withDayOfMonth(1).withTimeAtStartOfDay().plusMonths(1)); final AttributeQuery attrQuery = attrQueryBldr.getAttributeQuery(CIAccounting.Transaction.ID); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.ReportSubJournal2Transaction); queryBldr.addWhereAttrEqValue(CIAccounting.ReportSubJournal2Transaction.FromLink, repInst); queryBldr.addWhereAttrInQuery(CIAccounting.ReportSubJournal2Transaction.ToLink, attrQuery); queryBldr.addWhereAttrNotEqValue(CIAccounting.ReportSubJournal2Transaction.ID, _parameter.getInstance()); queryBldr.addOrderByAttributeDesc(CIAccounting.ReportSubJournal2Transaction.Number); final MultiPrintQuery multi = queryBldr.getPrint(); multi.setEnforceSorted(true); multi.addAttribute(CIAccounting.ReportSubJournal2Transaction.Number); multi.executeWithoutAccessCheck(); String numberStr = ""; if (multi.next()) { numberStr = multi.<String>getAttribute(CIAccounting.ReportSubJournal2Transaction.Number); } final int month = transDate.getMonthOfYear(); Integer curr = 0; try { final Pattern pattern = Pattern.compile("\\d*$"); final Matcher matcher = pattern.matcher(numberStr.trim()); if (matcher.find()) { curr = Integer.parseInt(matcher.group()); } } catch (final NumberFormatException e) { SubJournal_Base.LOG.warn("Catched NumberFormatException"); } curr = curr + 1; numberStr = String.format("%s/%02d/%04d", repName, month, curr); final Update update = new Update(_parameter.getInstance()); update.add(CIAccounting.ReportSubJournal2Transaction.Number, numberStr); update.executeWithoutTrigger(); return new Return(); }
From source file:org.efaps.esjp.common.datetime.JodaTimeUtils.java
License:Apache License
/** * @param _parameter parameter as passed by the eFaps API * @return new DateTime//from w ww.j ava 2s. c om * @throws EFapsException on error */ public static DateTime getDefaultvalue(final Parameter _parameter) throws EFapsException { final JodaTimeUtils utils = new JodaTimeUtils(); DateTime ret = new DateTime().withTimeAtStartOfDay() .withChronology(Context.getThreadContext().getChronology()); for (final DateDefaultValues value : DateDefaultValues.values()) { if (utils.containsProperty(_parameter, value.toString())) { final String strValue = utils.getProperty(_parameter, value.toString()); switch (value) { case TODAY: ret = new DateTime().withChronology(Context.getThreadContext().getChronology()); break; case WEEKS: ret = ret.plusWeeks(Integer.valueOf(strValue)); break; case MONTHS: ret = ret.plusMonths(Integer.valueOf(strValue)); break; case YEARS: ret = ret.plusYears(Integer.valueOf(strValue)); break; case WITHDAYOFMONTH: ret = ret.withDayOfMonth(Integer.valueOf(strValue)); break; case WITHDAYOFWEEK: ret = ret.withDayOfWeek(Integer.valueOf(strValue)); break; case LASTDAYOFMONTH: ret = ret.dayOfMonth().withMaximumValue(); break; case WITHDAYOFYEAR: ret = ret.withDayOfYear(Integer.valueOf(strValue)); default: break; } } } return ret; }
From source file:org.efaps.esjp.common.uiform.Field_Base.java
License:Apache License
/** * Method to get a Datevalue for a field on create to set a more "intelligent" * value like "monday of current week" etc. * Properties://from w w w. ja va 2 s . c o m * <table> * <tr><th>Property</th><th>Value</th><th>Description</th></tr> * <tr><td>withDayOfWeek</td><td>1,2,3,4,5,6,7</td> * <td>the Integer represents on of the weekdays starting with Monday, Tuesday...</td></tr> * <tr><td>withDayOfMonth</td><td>Integer</td><td>day of month</td></tr> * <tr><td>minusDays</td><td>Integer</td><td>days to subtract</td></tr> * <tr><td>plusDays</td><td>Integer</td><td>days to add</td></tr> * <tr><td>minusWeeks</td><td>Integer</td><td>weeks to subtract</td></tr> * <tr><td>plusWeeks</td><td>Integer</td><td>weeks to add</td></tr> * </table> * * @param _parameter Parameter as passed by the eFaps API * @return ReturnValue containing the date * @throws EFapsException on error */ public Return getDefault4DateFieldValue(final Parameter _parameter) throws EFapsException { final Return ret = new Return(); final TargetMode mode = (TargetMode) _parameter.get(ParameterValues.ACCESSMODE); final Collection<TargetMode> modes = new ArrayList<>(); for (final String aMode : analyseProperty(_parameter, "TargetMode").values()) { modes.add(EnumUtils.getEnum(TargetMode.class, aMode.toUpperCase())); } if ((TargetMode.CREATE.equals(mode) || TargetMode.EDIT.equals(mode)) && (modes.isEmpty() || modes.contains(mode))) { DateTime date = new DateTime(); if (containsProperty(_parameter, "withDayOfWeek")) { final int dayOfWeek = Integer.parseInt(getProperty(_parameter, "withDayOfWeek")); date = date.withDayOfWeek(dayOfWeek); } if (containsProperty(_parameter, "withDayOfMonth")) { final int dayOfMonth = Integer.parseInt(getProperty(_parameter, "withDayOfMonth")); date = date.withDayOfMonth(dayOfMonth); } if (containsProperty(_parameter, "days")) { final int days = Integer.parseInt(getProperty(_parameter, "days")); date = date.plusDays(days); } if (containsProperty(_parameter, "weeks")) { final int weeks = Integer.parseInt(getProperty(_parameter, "weeks")); date = date.plusWeeks(weeks); } if (containsProperty(_parameter, "months")) { final int months = Integer.parseInt(getProperty(_parameter, "months")); date = date.plusMonths(months); } if (containsProperty(_parameter, "years")) { final int years = Integer.parseInt(getProperty(_parameter, "years")); date = date.plusYears(years); } ret.put(ReturnValues.VALUES, date); } return ret; }
From source file:org.egov.wtms.web.controller.application.MeterReadingController.java
License:Open Source License
private WaterConnectionDetails calculateDemandForDamagedMeter( final WaterConnectionDetails waterConnectionDetails, final Date previousDate, final int noOfMonths, final Boolean currentMonthIncluded) { BigDecimal amountValue;//from w w w . j a va 2 s . com new WaterConnectionDetails(); Installment currentInstallment; List<Installment> newInstallmentList; DateTime dateTime = new DateTime(previousDate); DateTime lastInstReadingDate; DateTime lastInstStartDate; newInstallmentList = installmentDao.getInstallmentsByModuleForGivenDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), previousDate, MONTHLY); currentInstallment = connectionDemandService.getCurrentInstallment(MODULE_NAME, MONTHLY, new Date()); if (newInstallmentList.isEmpty() || !newInstallmentList.contains(currentInstallment)) newInstallmentList.add(currentInstallment); for (final Installment installment : newInstallmentList) { lastInstReadingDate = dateTime.minusMonths(6); lastInstStartDate = lastInstReadingDate.withDayOfMonth(1).withTimeAtStartOfDay(); final List<Installment> lastInstallmentList = installmentDao .getInstallmentsByModuleBetweenFromDateAndToDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), lastInstStartDate.toDate(), installment.getFromDate(), MONTHLY); amountValue = calculateDamagedMeterAverageDemand(lastInstallmentList, waterConnectionDetails); if (amountValue.compareTo(BigDecimal.ZERO) > 0) connectionDemandService.updateDemandForMeteredConnection(waterConnectionDetails, amountValue, installment.getFromDate(), previousDate, noOfMonths, currentMonthIncluded); dateTime = new DateTime(installment.getFromDate()); dateTime = dateTime.plusMonths(1); } return waterConnectionDetails; }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds. * @param epochSeconds//w w w . ja v a 2 s .com * @param granularity * @return */ public static long getPreviousPartitionLastSecond(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); DateTime previousPartitionLastSecond = null; switch (granularity) { case PARTITION_YEAR: previousPartitionLastSecond = dateTime.minusYears(1).withMonthOfYear(12).withDayOfMonth(31) .withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_MONTH: previousPartitionLastSecond = dateTime.withDayOfMonth(1).minusDays(1).withHourOfDay(23) .withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_DAY: previousPartitionLastSecond = dateTime.minusDays(1).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_HOUR: previousPartitionLastSecond = dateTime.minusHours(1).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); int startOfPartition_Min = (dateTime.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; previousPartitionLastSecond = dateTime.withMinuteOfHour(startOfPartition_Min).withSecondOfMinute(0) .minusSeconds(1); return previousPartitionLastSecond.getMillis() / 1000; default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.fenixedu.spaces.domain.occupation.config.ExplicitConfigWithSettings.java
License:Open Source License
private static int getNthDayOfWeek(DateTime when) { DateTime checkpoint = when; int whenDayOfWeek = checkpoint.getDayOfWeek(); int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek); checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth()); int i = 0;//from w w w . ja v a 2 s . c o m while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) { checkpoint = checkpoint.plusWeeks(1); i++; } return i; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private int getNthDayOfWeek(DateTime when) { DateTime checkpoint = when; int whenDayOfWeek = checkpoint.getDayOfWeek(); int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek); checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth()); int i = 0;/*w w w .java 2 s.com*/ while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) { checkpoint = checkpoint.plusWeeks(1); i++; } return i; }
From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java
License:Open Source License
private DateTime getNextNthdayOfWeek(DateTime when, int nthdayOfTheWeek, int dayOfTheWeek) { DateTime checkpoint = when; int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.plusWeeks(month - checkpoint.getMonthOfYear()); int i = nthdayOfTheWeek; if (i > 3) { DateTime lastDayOfMonth = checkpoint.dayOfMonth().withMaximumValue(); lastDayOfMonth = lastDayOfMonth.withDayOfWeek(dayOfTheWeek); return lastDayOfMonth.plusWeeks(month - lastDayOfMonth.getMonthOfYear()); } else {/*from ww w .j a v a 2 s . c om*/ return checkpoint.plusWeeks(nthdayOfTheWeek); } }