List of usage examples for org.joda.time DateTime dayOfMonth
public Property dayOfMonth()
From source file:op.tools.SYSCalendar.java
License:Open Source License
public static DateTime bom(DateTime d) { return d.dayOfMonth().withMinimumValue().hourOfDay().withMinimumValue().minuteOfHour().withMinimumValue() .secondOfMinute().withMinimumValue().millisOfSecond().withMinimumValue(); }
From source file:op.tools.SYSCalendar.java
License:Open Source License
public static DateTime eom(DateTime d) { return d.dayOfMonth().withMaximumValue().hourOfDay().withMaximumValue().minuteOfHour().withMaximumValue() .secondOfMinute().withMaximumValue().millisOfSecond().withMaximumValue(); }
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()); }//w ww .j a v a2 s . c o 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/*ww w . j ava 2s. c o m*/ * @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.isis.applib.value.Date.java
License:Apache License
private void checkDate(final int year, final int month, final int day) { if ((month < 1) || (month > 12)) { throw new IllegalArgumentException("Month must be in the range 1 - 12 inclusive"); }/* w w w .j a v a2s .c om*/ final DateTime newDate = newDateTime(year, month, 1); final int lastDayOfMonth = newDate.dayOfMonth().getMaximumValue(); ; if ((day < 1) || (day > lastDayOfMonth)) { throw new IllegalArgumentException( "Day must be in the range 1 - " + lastDayOfMonth + " inclusive: " + day); } }
From source file:org.apache.pig.piggybank.evaluation.datetime.truncate.ISOToMonth.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 a va 2s . co m*/ DateTime dt = ISOHelper.parseDateTime(input); // Set the day to 1 and the hour, minute, second and milliseconds to 0 DateTime result = dt.dayOfMonth().setCopy(1).hourOfDay().setCopy(0).minuteOfHour().setCopy(0) .secondOfMinute().setCopy(0).millisOfSecond().setCopy(0); return result.toString(); }
From source file:org.beer30.jdefault.JDefaultBusiness.java
License:Apache License
/** * Typically Cards are good for 3 years. Will create a random date between 24 and 48 months * * @return date//from w w w . j a va 2s. c o m */ public static Date creditCardExpiryDate() { DateTime dateTime = new DateTime(); DateTime addedMonths = dateTime.plusMonths(JDefaultNumber.randomIntBetweenTwoNumbers(24, 48)); return addedMonths.dayOfMonth().withMaximumValue().toDate(); }
From source file:org.broadleafcommerce.core.payment.service.NullPaymentGatewayTransactionServiceImpl.java
License:Apache License
/** * Does minimal Credit Card Validation (luhn check and expiration date is after today). * Mimics the Response of a real Payment Gateway. * * @param creditCardDTO//from w ww. j av a2 s .c o m * @return */ protected PaymentResponseDTO commonCreditCardProcessing(PaymentRequestDTO requestDTO, PaymentTransactionType paymentTransactionType) { PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.CREDIT_CARD, NullPaymentGatewayType.NULL_GATEWAY); responseDTO.valid(true).paymentTransactionType(paymentTransactionType); CreditCardDTO creditCardDTO = requestDTO.getCreditCard(); String transactionAmount = requestDTO.getTransactionTotal(); CreditCardValidator visaValidator = new CreditCardValidator(CreditCardValidator.VISA); CreditCardValidator amexValidator = new CreditCardValidator(CreditCardValidator.AMEX); CreditCardValidator mcValidator = new CreditCardValidator(CreditCardValidator.MASTERCARD); CreditCardValidator discoverValidator = new CreditCardValidator(CreditCardValidator.DISCOVER); if (StringUtils.isNotBlank(transactionAmount) && StringUtils.isNotBlank(creditCardDTO.getCreditCardNum()) && (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpDate()) || (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpMonth()) && StringUtils.isNotBlank(creditCardDTO.getCreditCardExpYear())))) { boolean validCard = false; if (visaValidator.isValid(creditCardDTO.getCreditCardNum())) { validCard = true; } else if (amexValidator.isValid(creditCardDTO.getCreditCardNum())) { validCard = true; } else if (mcValidator.isValid(creditCardDTO.getCreditCardNum())) { validCard = true; } else if (discoverValidator.isValid(creditCardDTO.getCreditCardNum())) { validCard = true; } boolean validDateFormat = false; boolean validDate = false; String[] parsedDate = null; if (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpDate())) { parsedDate = creditCardDTO.getCreditCardExpDate().split("/"); } else { parsedDate = new String[2]; parsedDate[0] = creditCardDTO.getCreditCardExpMonth(); parsedDate[1] = creditCardDTO.getCreditCardExpYear(); } if (parsedDate.length == 2) { String expMonth = parsedDate[0]; String expYear = parsedDate[1]; try { DateTime expirationDate = new DateTime(Integer.parseInt("20" + expYear), Integer.parseInt(expMonth), 1, 0, 0); expirationDate = expirationDate.dayOfMonth().withMaximumValue(); validDate = expirationDate.isAfterNow(); validDateFormat = true; } catch (Exception e) { //invalid date format } } if (!validDate || !validDateFormat) { responseDTO.amount(new Money(0)).rawResponse("cart.payment.expiration.invalid").successful(false); } else if (!validCard) { responseDTO.amount(new Money(0)).rawResponse("cart.payment.card.invalid").successful(false); } else { responseDTO.amount(new Money(requestDTO.getTransactionTotal())).rawResponse("Success!") .successful(true); } } else { responseDTO.amount(new Money(0)).rawResponse("cart.payment.invalid").successful(false); } return responseDTO; }
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 ww w .j av a 2 s . 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.egov.tl.service.DemandNoticeService.java
License:Open Source License
private void getMonthWiseLatePenaltyFeeDetails(TradeLicense license, Installment currentInstallment, BigDecimal currLicenseFee, BigDecimal arrLicenseFee, BigDecimal arrLicensePenalty, List<LicenseDemandDetail> monthWiseDemandDetails) { String currentInstallmentYear = toYearFormat(currentInstallment.getFromDate()); for (Map.Entry<Integer, String> month : getAllMonths().entrySet()) { DateTime financialYearDate = new DateTime(currentInstallment.getFromDate()) .withMonthOfYear(month.getKey()); Date monthEndDate = new DateTime(financialYearDate) .withDayOfMonth(financialYearDate.dayOfMonth().getMaximumValue()).toDate(); BigDecimal penaltyAmt = penaltyRatesService.calculatePenalty(license, currentInstallment.getFromDate(), monthEndDate, currLicenseFee); LicenseDemandDetail demandBillDtl = new LicenseDemandDetail(); demandBillDtl.setLicenseFee(currLicenseFee); demandBillDtl.setPenalty(penaltyAmt.setScale(0, ROUND_HALF_UP)); demandBillDtl.setArrersWithPenalty(arrLicenseFee.add(arrLicensePenalty)); demandBillDtl.setMonth(month.getValue().concat(", ").concat(currentInstallmentYear)); demandBillDtl.setTotalDues(arrLicenseFee.add(arrLicensePenalty).add(currLicenseFee).add(penaltyAmt) .setScale(0, ROUND_HALF_UP)); monthWiseDemandDetails.add(demandBillDtl); }// w w w . j av a2 s . co m }