Search in sources :

Example 1 with MutableDateTime

use of org.joda.time.MutableDateTime in project elasticsearch by elastic.

the class DateObjectValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    MutableDateTime joda = new MutableDateTime(0, DateTimeZone.UTC);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int docId) {
            long millis = (long) docValues.get(docId);
            joda.setMillis(millis);
            return function.applyAsInt(joda);
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MutableDateTime(org.joda.time.MutableDateTime) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 2 with MutableDateTime

use of org.joda.time.MutableDateTime in project elasticsearch by elastic.

the class SimpleJodaTests method testRoundingWithTimeZone.

public void testRoundingWithTimeZone() {
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setZone(DateTimeZone.forOffsetHours(-2));
    time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);
    MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
    utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);
    time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
    // the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
    // time zone, the millis diff is not 24, but 22 hours
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
    time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Example 3 with MutableDateTime

use of org.joda.time.MutableDateTime in project elasticsearch by elastic.

the class SimpleJodaTests method testUpperBound.

public void testUpperBound() {
    MutableDateTime dateTime = new MutableDateTime(3000, 12, 31, 23, 59, 59, 999, DateTimeZone.UTC);
    DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
    String value = "2000-01-01";
    int i = formatter.parseInto(dateTime, value, 0);
    assertThat(i, equalTo(value.length()));
    assertThat(dateTime.toString(), equalTo("2000-01-01T23:59:59.999Z"));
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter)

Example 4 with MutableDateTime

use of org.joda.time.MutableDateTime in project elasticsearch by elastic.

the class DateMathParser method parseDateTime.

private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) {
    DateTimeFormatter parser = dateTimeFormatter.parser();
    if (timeZone != null) {
        parser = parser.withZone(timeZone);
    }
    try {
        MutableDateTime date;
        // fields that are filled with times without dates
        if (roundUpIfNoTime) {
            date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC);
        } else {
            date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
        }
        final int end = parser.parseInto(date, value, 0);
        if (end < 0) {
            int position = ~end;
            throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]");
        } else if (end != value.length()) {
            throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]");
        }
        return date.getMillis();
    } catch (IllegalArgumentException e) {
        throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format());
    }
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) MutableDateTime(org.joda.time.MutableDateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 5 with MutableDateTime

use of org.joda.time.MutableDateTime in project head by mifos.

the class SavingsProductFormValidator method validate.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Override
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);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) BindException(org.springframework.validation.BindException) FieldError(org.springframework.validation.FieldError) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Aggregations

MutableDateTime (org.joda.time.MutableDateTime)77 DateTime (org.joda.time.DateTime)13 Date (java.util.Date)6 Instant (org.joda.time.Instant)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 Chronology (org.joda.time.Chronology)4 DateTimeZone (org.joda.time.DateTimeZone)4 ISOChronology (org.joda.time.chrono.ISOChronology)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)3 SlidingWindows (org.apache.beam.sdk.transforms.windowing.SlidingWindows)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 KV (org.apache.beam.sdk.values.KV)2 TimestampedValue (org.apache.beam.sdk.values.TimestampedValue)2 Duration (org.joda.time.Duration)2 Category (org.junit.experimental.categories.Category)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1