List of usage examples for org.joda.time DateTime monthOfYear
public Property monthOfYear()
From source file:org.apache.druid.query.expression.TimestampExtractExprMacro.java
License:Apache License
@Override public Expr apply(final List<Expr> args) { if (args.size() < 2 || args.size() > 3) { throw new IAE("Function[%s] must have 2 to 3 arguments", name()); }/* www . j av a 2s . co m*/ if (!args.get(1).isLiteral() || args.get(1).getLiteralValue() == null) { throw new IAE("Function[%s] unit arg must be literal", name()); } if (args.size() > 2 && !args.get(2).isLiteral()) { throw new IAE("Function[%s] timezone arg must be literal", name()); } final Expr arg = args.get(0); final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue())); final DateTimeZone timeZone; if (args.size() > 2) { timeZone = ExprUtils.toTimeZone(args.get(2)); } else { timeZone = DateTimeZone.UTC; } final ISOChronology chronology = ISOChronology.getInstance(timeZone); class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr { private TimestampExtractExpr(Expr arg) { super(arg); } @Nonnull @Override public ExprEval eval(final ObjectBinding bindings) { Object val = arg.eval(bindings).value(); if (val == null) { // Return null if the argument if null. return ExprEval.of(null); } final DateTime dateTime = new DateTime(val, chronology); long epoch = dateTime.getMillis() / 1000; switch (unit) { case EPOCH: return ExprEval.of(epoch); case MICROSECOND: return ExprEval.of(epoch / 1000); case MILLISECOND: return ExprEval.of(dateTime.millisOfSecond().get()); case SECOND: return ExprEval.of(dateTime.secondOfMinute().get()); case MINUTE: return ExprEval.of(dateTime.minuteOfHour().get()); case HOUR: return ExprEval.of(dateTime.hourOfDay().get()); case DAY: return ExprEval.of(dateTime.dayOfMonth().get()); case DOW: return ExprEval.of(dateTime.dayOfWeek().get()); case ISODOW: return ExprEval.of(dateTime.dayOfWeek().get()); case DOY: return ExprEval.of(dateTime.dayOfYear().get()); case WEEK: return ExprEval.of(dateTime.weekOfWeekyear().get()); case MONTH: return ExprEval.of(dateTime.monthOfYear().get()); case QUARTER: return ExprEval.of((dateTime.monthOfYear().get() - 1) / 3 + 1); case YEAR: return ExprEval.of(dateTime.year().get()); case ISOYEAR: return ExprEval.of(dateTime.year().get()); case DECADE: // The year field divided by 10, See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.floor(dateTime.year().get() / 10)); case CENTURY: return ExprEval.of(dateTime.centuryOfEra().get() + 1); case MILLENNIUM: // Years in the 1900s are in the second millennium. The third millennium started January 1, 2001. // See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.round(Math.ceil(dateTime.year().get() / 1000))); default: throw new ISE("Unhandled unit[%s]", unit); } } @Override public Expr visit(Shuttle shuttle) { Expr newArg = arg.visit(shuttle); return shuttle.visit(new TimestampExtractExpr(newArg)); } } return new TimestampExtractExpr(arg); }
From source file:org.apache.fineract.accounting.closure.storeglaccountbalance.service.GLClosureJournalEntryBalanceReadPlatformServiceImpl.java
License:Apache License
/** * Create the csv file with the balance report data * * @param reportDataList//from w w w . j ava 2s .c om * @return {@link File} object */ private File createGLClosureAccountBalanceReportGreatPlainsFile( final Collection<GLClosureAccountBalanceReportData> reportDataList) { File file = null; try { final String fileDirectory = FileSystemContentRepository.MIFOSX_BASE_DIR + File.separator + ""; if (!new File(fileDirectory).isDirectory()) { new File(fileDirectory).mkdirs(); } DateTime dateTime = DateTime.now(); String year = dateTime.year().getAsString(); String month = String.format("%02d", dateTime.monthOfYear().get()); String day = String.format("%02d", dateTime.dayOfMonth().get()); String hour = String.format("%02d", dateTime.hourOfDay().get()); String minute = String.format("%02d", dateTime.minuteOfHour().get()); String second = String.format("%02d", dateTime.secondOfMinute().get()); file = new File( fileDirectory + "JRNL_" + year + month + day + hour + minute + second + "_001" + ".txt"); // use FileWriter constructor that specifies open for appending FileWriter fileWriter = new FileWriter(file); for (GLClosureAccountBalanceReportData reportData : reportDataList) { final LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("companyId", this.configurationDomainService.getCompanyId()); fields.put("batchNumber", "GLPOS" + year.substring(year.length() - 2) + month + day + hour + minute); fields.put("reference", ""); fields.put("transactionDate", ""); fields.put("transactionType", "0"); //transactionType (0 = regular, 1 = reversing) is always 0 fields.put("transactionId", ""); fields.put("series", "2"); // Always Financial (1=All; 2=Financial; 3=Sales; 4=Purchasing; 5=Inventory; 6=Payroll; 7=Project;) fields.put("currencyId", ""); fields.put("exchangeRate", ""); fields.put("rateTypeId", ""); fields.put("expirationDate", ""); fields.put("exchangeDate", ""); fields.put("exchangeId", ""); fields.put("exchangeRateSource", ""); fields.put("rateExpiration", "0"); // no rate expiration (0=None; 1=Daily; 2=Weekly; 3=Bi-weekly; 4=Semiweekly; 5=Monthly; 6=Quarterly; 7=Annually; 8=Misc.; 9=None;) fields.put("transactionTime", ""); fields.put("userId", ""); fields.put("creditAmount", ""); fields.put("debitAmount", ""); fields.put("accountNoString", ""); fields.put("description", ""); fields.put("originatingControlNo", ""); fields.put("originatingDocNo", ""); fields.put("originatingMasterId", ""); fields.put("originatingMasterName", ""); fields.put("originatingTransationType", ""); fields.put("originatingSequenceNo", ""); fields.put("originatingTransactionDescription", ""); fields.put("taxDetailId", ""); fields.put("taxAmount", ""); fields.put("taxAccount", ""); if (reportData.getTransactionDate() != null) { String transactionDate = year + month + day; fields.put("transactionDate", transactionDate); } if (reportData.getAmount() != null) { String goodsAmount = reportData.getAmount().abs().setScale(2, RoundingMode.CEILING) .toPlainString(); if (reportData.getAmount().compareTo(BigDecimal.ZERO) < 0) { fields.put("creditAmount", goodsAmount); } else { fields.put("debitAmount", goodsAmount); } } if (reportData.getReference() != null) { String reference = reportData.getReference(); fields.put("reference", reference); fields.put("description", reference); } if (reportData.getAccountNumber() != null) { fields.put("accountNoString", reportData.getAccountNumber()); } if (reportData.getClosureId() != null) { fields.put("transactionId", reportData.getClosureId().toString()); } for (String key : fields.keySet()) { fileWriter.write(fields.get(key) + "|"); } fileWriter.write(System.lineSeparator()); } fileWriter.close(); } catch (Exception exception) { logger.error(exception.getMessage(), exception); } return file; }
From source file:org.apache.phoenix.expression.function.CeilMonthExpression.java
License:Apache License
@Override public long roundDateTime(DateTime dateTime) { return dateTime.monthOfYear().roundCeilingCopy().getMillis(); }
From source file:org.apache.phoenix.expression.function.FloorMonthExpression.java
License:Apache License
@Override public long roundDateTime(DateTime datetime) { return datetime.monthOfYear().roundFloorCopy().getMillis(); }
From source file:org.apache.phoenix.expression.function.RoundMonthExpression.java
License:Apache License
@Override public long roundDateTime(DateTime dateTime) { return dateTime.monthOfYear().roundHalfEvenCopy().getMillis(); }
From source file:org.apache.pig.piggybank.evaluation.datetime.truncate.ISOToYear.java
License:Apache License
@Override public String exec(Tuple input) throws IOException { if (input == null || input.size() < 1) { return null; }/*from w w w .j ava 2 s.c om*/ DateTime dt = ISOHelper.parseDateTime(input); // Set the month and day to 1 and the hour, minute, second and milliseconds to 0 DateTime result = dt.monthOfYear().setCopy(1).dayOfMonth().setCopy(1).hourOfDay().setCopy(0).minuteOfHour() .setCopy(0).secondOfMinute().setCopy(0).millisOfSecond().setCopy(0); return result.toString(); }
From source file:org.egov.ptis.domain.service.notice.RecoveryNoticeService.java
License:Open Source License
private ReportRequest generateDistressNotice(final BasicProperty basicProperty, final Map<String, Object> reportParams, final City city, final String noticeNo) { ReportRequest reportInput;// ww w .j a v a2 s . c o m final Address ownerAddress = basicProperty.getAddress(); reportParams.put(TOTAL_TAX_DUE, getTotalPropertyTaxDueIncludingPenalty(basicProperty)); final DateTime noticeDate = new DateTime(); reportParams.put(DOOR_NO, StringUtils.isNotBlank(ownerAddress.getHouseNoBldgApt()) ? ownerAddress.getHouseNoBldgApt().trim() : "N/A"); reportParams.put(CONSUMER_ID, basicProperty.getUpicNo()); reportParams.put(NOTICE_DAY, propertyTaxCommonUtils.getDateWithSufix(noticeDate.getDayOfMonth())); reportParams.put(NOTICE_MONTH, noticeDate.monthOfYear().getAsShortText()); reportParams.put(NOTICE_YEAR, noticeDate.getYear()); if (noticeDate.getMonthOfYear() >= 4 && noticeDate.getMonthOfYear() <= 10) reportParams.put(FIN_HALF_STRAT_MONTH, "April"); else reportParams.put(FIN_HALF_STRAT_MONTH, "October"); reportParams.put(DISTRESS_NOTICE_NUMBER, noticeNo); reportParams.put(DISTRESS_NOTICE_DATE, DateUtils.getDefaultFormattedDate(new Date())); final String cityGrade = city.getGrade(); if (org.apache.commons.lang.StringUtils.isNotEmpty(cityGrade) && cityGrade.equalsIgnoreCase(PropertyTaxConstants.CITY_GRADE_CORPORATION)) { reportParams.put(SECTION_ACT, PropertyTaxConstants.CORPORATION_ESD_NOTICE_SECTION_ACT); reportInput = new ReportRequest(PropertyTaxConstants.REPORT_DISTRESS_CORPORATION, reportParams, reportParams); } else { reportParams.put(SECTION_ACT, PropertyTaxConstants.MUNICIPALITY_DISTRESS_NOTICE_SECTION_ACT); reportInput = new ReportRequest(PropertyTaxConstants.REPORT_DISTRESS_MUNICIPALITY, reportParams, reportParams); } return reportInput; }
From source file:org.egov.ptis.domain.service.notice.RecoveryNoticeService.java
License:Open Source License
private ReportRequest generateInventoryNotice(final BasicProperty basicProperty, final Map<String, Object> reportParams, final City city, final SimpleDateFormat formatter) { ReportRequest reportInput;//from www . ja v a 2 s . c om final Installment currentInstall = propertyTaxCommonUtils.getCurrentPeriodInstallment(); final DateTime dateTime = new DateTime(); final DateTime currInstToDate = new DateTime(currentInstall.getToDate()); reportParams.put(TOTAL_TAX_DUE, String.valueOf(getTotalPropertyTaxDue(basicProperty))); reportParams.put(REPORT_DATE, propertyTaxCommonUtils.getDateWithSufix(dateTime.getDayOfMonth())); reportParams.put(REPORT_MON_YEAR, dateTime.monthOfYear().getAsShortText() + "," + dateTime.getYear()); final String cityGrade = city.getGrade(); if (StringUtils.isNotBlank(cityGrade) && cityGrade.equalsIgnoreCase(PropertyTaxConstants.CITY_GRADE_CORPORATION)) { reportParams.put(INST_LAST_DATE, propertyTaxCommonUtils.getDateWithSufix(currInstToDate.getDayOfMonth())); reportParams.put(INST_MON_YEAR, currInstToDate.monthOfYear().getAsShortText() + "," + currInstToDate.getYear()); reportInput = new ReportRequest(REPORT_INVENTORY_NOTICE_CORPORATION, reportParams, reportParams); } else { reportParams.put(INST_LAST_DATE, formatter.format(currentInstall.getToDate())); reportInput = new ReportRequest(REPORT_INVENTORY_NOTICE_MUNICIPALITY, reportParams, reportParams); } return reportInput; }
From source file:org.egov.tl.service.DemandGenerationService.java
License:Open Source License
private boolean installmentYearValidForDemandGeneration(CFinancialYear installmentYear) { DateTime currentDate = new DateTime(); DateTime startOfCalenderDate = new DateTime(installmentYear.getStartingDate()).monthOfYear() .withMinimumValue().dayOfMonth().withMinimumValue().withTimeAtStartOfDay(); DateTime endOfCalenderDate = startOfCalenderDate.monthOfYear().withMaximumValue().dayOfMonth() .withMaximumValue().millisOfDay().withMaximumValue(); return currentDate.isAfter(startOfCalenderDate) && currentDate.isBefore(endOfCalenderDate); }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }// w w w . j ava 2 s . c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }