List of usage examples for org.joda.time MutableDateTime MutableDateTime
public MutableDateTime()
ISOChronology
in the default time zone. From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJISOSetGetHour() { int COUNT = COUNT_VERY_FAST; // Is it fair to use only MutableDateTime here? You decide. MutableDateTime dt = new MutableDateTime(); for (int i = 0; i < AVERAGE; i++) { start("JISO", "setGetHour"); for (int j = 0; j < COUNT; j++) { dt.setHourOfDay(13);/* w w w. j av a 2 s . co m*/ int val = dt.getHourOfDay(); if (dt == null) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.kuali.rice.kew.docsearch.service.impl.DocumentSearchServiceImpl.java
License:Educational Community License
protected DocumentSearchCriteria applyCriteriaDefaults(DocumentSearchCriteria criteria) { DocumentSearchCriteria.Builder comparisonCriteria = createEmptyComparisonCriteria(criteria); boolean isCriteriaEmpty = criteria.equals(comparisonCriteria.build()); boolean isTitleOnly = false; boolean isDocTypeOnly = false; if (!isCriteriaEmpty) { comparisonCriteria.setTitle(criteria.getTitle()); isTitleOnly = criteria.equals(comparisonCriteria.build()); }/*from w ww .j a v a 2 s .c o m*/ if (!isCriteriaEmpty && !isTitleOnly) { comparisonCriteria = createEmptyComparisonCriteria(criteria); comparisonCriteria.setDocumentTypeName(criteria.getDocumentTypeName()); isDocTypeOnly = criteria.equals(comparisonCriteria.build()); } if (isCriteriaEmpty || isTitleOnly || isDocTypeOnly) { DocumentSearchCriteria.Builder criteriaBuilder = DocumentSearchCriteria.Builder.create(criteria); Integer defaultCreateDateDaysAgoValue = null; if (isCriteriaEmpty || isDocTypeOnly) { // if they haven't set any criteria, default the from created date to today minus days from constant variable defaultCreateDateDaysAgoValue = KewApiConstants.DOCUMENT_SEARCH_NO_CRITERIA_CREATE_DATE_DAYS_AGO; } else if (isTitleOnly) { // If the document title is the only field which was entered, we want to set the "from" date to be X // days ago. This will allow for a more efficient query. defaultCreateDateDaysAgoValue = KewApiConstants.DOCUMENT_SEARCH_DOC_TITLE_CREATE_DATE_DAYS_AGO; } if (defaultCreateDateDaysAgoValue != null) { // add a default create date MutableDateTime mutableDateTime = new MutableDateTime(); mutableDateTime.addDays(defaultCreateDateDaysAgoValue.intValue()); criteriaBuilder.setDateCreatedFrom(mutableDateTime.toDateTime()); } criteria = criteriaBuilder.build(); } return criteria; }
From source file:org.mifos.ui.core.controller.SavingsProductFormValidator.java
License:Open Source License
@SuppressWarnings({ "ThrowableInstanceNeverThrown" }) @Override/* w ww. j a va 2 s . c om*/ public void validate(Object target, Errors errors) { SavingsProductFormBean formBean = (SavingsProductFormBean) target; if (formBean.getGeneralDetails().getName().trim().isEmpty()) { errors.reject("NotEmpty.generalDetails.name"); } if (formBean.getGeneralDetails().getDescription().length() > 200) { errors.reject("Size.generalDetails.description"); } if (formBean.getGeneralDetails().getShortName().trim().isEmpty()) { errors.reject("NotEmpty.generalDetails.shortName"); } if (formBean.getGeneralDetails().getSelectedCategory().trim().isEmpty()) { errors.reject("NotEmpty.generalDetails.selectedCategory"); } if (null == formBean.getGeneralDetails().getStartDateDay() || 1 > formBean.getGeneralDetails().getStartDateDay() || 31 < formBean.getGeneralDetails().getStartDateDay()) { errors.reject("Min.generalDetails.startDateDay"); } if (null == formBean.getGeneralDetails().getStartDateMonth() || 1 > formBean.getGeneralDetails().getStartDateMonth() || 12 < formBean.getGeneralDetails().getStartDateMonth()) { errors.reject("Min.generalDetails.startDateMonth"); } if (null == formBean.getGeneralDetails().getStartDateAsDateTime() || !(formBean.getGeneralDetails().getStartDateYear().length() == 4)) { errors.reject("Min.generalDetails.startDate"); } else { MutableDateTime nextYear = new MutableDateTime(); nextYear.setDate(new Date().getTime()); nextYear.addYears(1); if (formBean.getGeneralDetails().getStartDateAsDateTime() != null && formBean.getGeneralDetails().getStartDateAsDateTime().compareTo(nextYear) > 0) { errors.reject("Min.generalDetails.startDate"); } } if ((null != formBean.getGeneralDetails().getEndDateDay() || null != formBean.getGeneralDetails().getEndDateMonth() || null != formBean.getGeneralDetails().getEndDateMonth()) && formBean.getGeneralDetails().getEndDateAsDateTime() == null) { errors.reject("Min.generalDetails.endDate"); } if (formBean.getGeneralDetails().getStartDateAsDateTime() != null && formBean.getGeneralDetails().getEndDateAsDateTime() != null && formBean.getGeneralDetails().getStartDateAsDateTime() .compareTo(formBean.getGeneralDetails().getEndDateAsDateTime()) > 0) { errors.reject("Min.generalDetails.endDate"); } if (formBean.getGeneralDetails().getSelectedApplicableFor().trim().isEmpty()) { errors.reject("NotEmpty.generalDetails.selectedApplicableFor"); } if (formBean.getSelectedDepositType().trim().isEmpty()) { errors.reject("NotEmpty.savingsProduct.selectedDepositType"); } else if (formBean.isMandatory() && (null == formBean.getAmountForDeposit() || formBean.getAmountForDeposit() <= 0)) { errors.reject("Min.savingsProduct.amountForDesposit"); } if (formBean.isGroupSavingAccount() && formBean.getSelectedGroupSavingsApproach().trim().isEmpty()) { errors.reject("NotEmpty.savingsProduct.selectedGroupSavingsApproach"); } if (!formBean.isInterestRateZero()) { if (null == formBean.getInterestRate() || formBean.getInterestRate().doubleValue() < 1.0 || formBean.getInterestRate().doubleValue() > 100.0 || errorProcessor.getRejectedValue("interestRate") != null) { if (errorProcessor.getTarget() == null) { errors.reject("NotNull.savingsProduct.interestRate"); } else { BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName()); bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestRate", errorProcessor.getRejectedValue("interestRate"), true, new String[] { "NotNull.savingsProduct.interestRate" }, null, null)); errors.addAllErrors(bindException); } } if (formBean.getSelectedInterestCalculation().trim().isEmpty()) { errors.reject("NotEmpty.savingsProduct.selectedInterestCalculation"); } if (null == formBean.getInterestCalculationFrequency() || formBean.getInterestCalculationFrequency() < 1 || errorProcessor.getRejectedValue("interestCalculationFrequency") != null) { if (errorProcessor.getTarget() == null) { errors.reject("NotNull.savingsProduct.interestCalculationFrequency"); } else { BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName()); bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestCalculationFrequency", errorProcessor.getRejectedValue("interestCalculationFrequency"), true, new String[] { "NotNull.savingsProduct.interestCalculationFrequency" }, null, null)); errors.addAllErrors(bindException); } } if (null == formBean.getInterestPostingMonthlyFrequency() || formBean.getInterestPostingMonthlyFrequency() < 1 || errorProcessor.getRejectedValue("interestPostingMonthlyFrequency") != null) { if (errorProcessor.getTarget() == null) { errors.reject("Min.savingsProduct.interestPostingMonthlyFrequency"); } else { BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName()); bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestPostingMonthlyFrequency", errorProcessor.getRejectedValue("interestPostingMonthlyFrequency"), true, new String[] { "Min.savingsProduct.interestPostingMonthlyFrequency" }, null, null)); errors.addAllErrors(bindException); } } } BigDecimal minBalanceForInterestCalculation; try { minBalanceForInterestCalculation = BigDecimal .valueOf(Double.valueOf(formBean.getMinBalanceRequiredForInterestCalculation())); } catch (NumberFormatException e) { minBalanceForInterestCalculation = new BigDecimal("-1"); } if (minBalanceForInterestCalculation.compareTo(BigDecimal.ZERO) < 0) { errors.reject("Min.savingsProduct.balanceRequiredForInterestCalculation"); } if (formBean.getSelectedPrincipalGlCode().trim().isEmpty()) { errors.reject("NotEmpty.savingsProduct.selectedPrincipalGlCode"); } if (formBean.getSelectedInterestGlCode().trim().isEmpty()) { errors.reject("NotEmpty.savingsProduct.selectedInterestGlCode"); } Short digsAfterDec = configurationServiceFacade.getAccountingConfiguration().getDigitsAfterDecimal(); Short digsBeforeDec = configurationServiceFacade.getAccountingConfiguration().getDigitsBeforeDecimal(); Double maxWithdrawalObj = formBean.getMaxWithdrawalAmount(); String maxWithdrawalString; if (maxWithdrawalObj == null) { maxWithdrawalString = ""; } else { maxWithdrawalString = maxWithdrawalObj.toString(); } int dot = maxWithdrawalString.lastIndexOf('.'); int max = digsAfterDec + digsBeforeDec + dot; int withdrawalLength = maxWithdrawalString.length(); if (maxWithdrawalString.lastIndexOf(0, dot) > digsBeforeDec) { errors.reject("MaxDigitsBefore.savingProduct.withdrawal", new String[] { digsBeforeDec.toString() }, null); } if (maxWithdrawalString.lastIndexOf(dot, withdrawalLength) > digsAfterDec) { errors.reject("MaxDigitsAfter.savingProduct.withdrawal", new String[] { digsAfterDec.toString() }, null); } if (withdrawalLength > max) { errors.reject("MaxDigitsNumber.savingProduct.withdrawal", new String[] { String.valueOf(max) }, null); } Double amountForDepositObj = formBean.getAmountForDeposit(); String amountForDepositString; if (amountForDepositObj == null) { amountForDepositString = ""; } else { amountForDepositString = amountForDepositObj.toString(); } int depositLength = amountForDepositString.length(); if (amountForDepositString.lastIndexOf(0, dot) > digsBeforeDec) { errors.reject("MaxDigitsBefore.savingProduct.deposit", new String[] { digsBeforeDec.toString() }, null); } if (amountForDepositString.lastIndexOf(dot, depositLength) > digsAfterDec) { errors.reject("MaxDigitsAfter.savingProduct.deposit", new String[] { digsAfterDec.toString() }, null); } if (depositLength > max) { errors.reject("MaxDigitsNumber.savingProduct.deposit", new String[] { String.valueOf(max) }, null); } }
From source file:org.openmhealth.shim.fatsecret.FatsecretShim.java
License:Apache License
@Override public ShimDataResponse getData(ShimDataRequest shimDataRequest) throws ShimException { long numToSkip = 0; long numToReturn = 3; Calendar cal = Calendar.getInstance(); cal.set(2014, Calendar.AUGUST, 1); Date endDate = new Date(cal.getTimeInMillis()); cal.add(Calendar.DATE, -1);//from w w w .j a v a2 s .com Date startDate = new Date(cal.getTimeInMillis()); DateTime startTime = new DateTime(startDate.getTime()); DateTime endTime = new DateTime(endDate.getTime()); MutableDateTime epoch = new MutableDateTime(); epoch.setDate(0); int days = 16283; //Days.daysBetween(epoch, new DateTime()).getDays() - 1; String endPoint = "food_entries.get"; String accessToken = shimDataRequest.getAccessParameters().getAccessToken(); String tokenSecret = shimDataRequest.getAccessParameters().getTokenSecret(); URL url = signUrl(DATA_URL + "?date=" + days + "&format=json&method=" + endPoint, accessToken, tokenSecret, null); System.out.println("Signed URL is: \n\n" + url); // Fetch and decode the JSON data. ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonData; HttpGet get = new HttpGet(url.toString()); HttpResponse response; try { response = httpClient.execute(get); HttpEntity responseEntity = response.getEntity(); jsonData = objectMapper.readTree(responseEntity.getContent()); return ShimDataResponse.result(FatsecretShim.SHIM_KEY, jsonData); } catch (IOException e) { throw new ShimException("Could not fetch data", e); } finally { get.releaseConnection(); } }
From source file:org.specrunner.converters.core.ConverterMutableDateTimeCurrentTemplate.java
License:Open Source License
@Override protected MutableDateTime instance() { return new MutableDateTime(); }
From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java
License:Open Source License
@Override public XMLGregorianCalendar convertToDatum(Object timestamp) { if (timestamp == null) { return null; }// w ww . ja va 2s . co m long timestampMillis; if (timestamp instanceof Long) { timestampMillis = ((Long) timestamp).longValue(); } else if (timestamp instanceof Date) { timestampMillis = ((Date) timestamp).getTime(); } else { throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp); } MutableDateTime dateTime = new MutableDateTime(); dateTime.setMillis(timestampMillis); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java
License:Open Source License
@Override public Object convertToAvro(XMLGregorianCalendar xts) { if (xts == null) { return null; }/*from w w w . j a v a 2s . c o m*/ MutableDateTime dateTime = new MutableDateTime(); try { dateTime.setYear(xts.getYear()); dateTime.setMonthOfYear(xts.getMonth()); dateTime.setDayOfMonth(xts.getDay()); dateTime.setHourOfDay(xts.getHour()); dateTime.setMinuteOfHour(xts.getMinute()); dateTime.setSecondOfMinute(xts.getSecond()); dateTime.setMillisOfSecond(xts.getMillisecond()); DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000); if (tz != null) { dateTime.setZoneRetainFields(tz); } return Long.valueOf(dateTime.getMillis()); } catch (IllegalArgumentException e) { throw new ComponentException(e); } }
From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java
License:Apache License
public T convertToObject(String value, Locale locale) { if (Strings.isEmpty(value)) { return null; }// w w w . ja v a 2 s . c o m DateTimeFormatter format = formatProvider.getFormatter(); if (format == null) { throw new IllegalStateException("format must be not null"); } format = format.withLocale(locale).withPivotYear(pivotYear); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); // instantiate now/ current time MutableDateTime dt = new MutableDateTime(); if (zone != null) { // set time zone for client format = format.withZone(DateTimeZone.forTimeZone(zone)); dt.setZone(DateTimeZone.forTimeZone(zone)); } try { // parse date retaining the time of the submission int result = format.parseInto(dt, value, 0); if (result < 0) { throw new ConversionException(new ParseException("unable to parse date " + value, ~result)); } } catch (RuntimeException e) { throw new ConversionException(e); } // apply the server time zone to the parsed value dt.setZone(getServerTimeZone()); return translator.fromDateTime(dt.toDateTime()); } else { try { DateTime date = format.parseDateTime(value); return date == null ? null : translator.fromDateTime(date); } catch (RuntimeException e) { throw new ConversionException(e); } } }
From source file:org.wicketstuff.calendar.util.DateConverter.java
License:Apache License
/** * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String, * java.util.Locale)/* w ww . java 2 s. c o m*/ */ public Object convertToObject(String value, Locale locale) { DateTimeFormatter format = getFormat(); if (applyTimeZoneDifference) { TimeZone zone = getClientTimeZone(); // instantiate now/ current time MutableDateTime dt = new MutableDateTime(); if (zone != null) { // set time zone for client format = format.withZone(DateTimeZone.forTimeZone(zone)); dt.setZone(DateTimeZone.forTimeZone(zone)); } // parse date retaining the time of the submission format.parseInto(dt, value, 0); // apply the server time zone to the parsed value dt.setZone(getTimeZone()); return dt.toDate(); } else { return format.parseDateTime(value).toDate(); } }
From source file:rapture.kernel.ScheduleApiImpl.java
License:Open Source License
@Override public List<TimedEventRecord> getCurrentWeekTimeRecords(CallingContext context, int weekOffsetfromNow) { // Based on today, get current events MutableDateTime now = new MutableDateTime(); now.setDayOfWeek(1);/*from w w w .ja va2 s . c om*/ return RangedEventGenerator.generateWeeklyEvents(now.toDateTime()); }