Search in sources :

Example 6 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class LatinDateParserTest method testFormat.

private void testFormat(String language, DateFormat format) {
    LatinDateParser converter = new LatinDateParser();
    for (int year = 1950; year < 2050; ++year) {
        for (int month = 1; month <= 12; ++month) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, month - 1);
            int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            for (int day = 1; day <= daysInMonth; ++day) {
                calendar.set(Calendar.DAY_OF_MONTH, day);
                Date date = calendar.getTime();
                LocalDate localDate = new LocalDate(date);
                String string = format.format(date);
                try {
                    LocalDate converted = converter.parse(string);
                    if (!converted.equals(localDate)) {
                        System.out.println("[" + language + "] " + string + " => " + converted + " [expected: " + localDate + "]");
                    }
                } catch (Exception e) {
                    System.out.println("[" + language + "] " + string + " => " + "ERROR: " + e.getMessage());
                }
            }
        }
    }
}
Also used : Calendar(java.util.Calendar) LocalDate(org.activityinfo.model.type.time.LocalDate) LocalDate(org.activityinfo.model.type.time.LocalDate) Date(java.util.Date)

Example 7 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class YearFracFunction method apply.

@Override
public FieldValue apply(List<FieldValue> arguments) {
    if (arguments.size() != 2) {
        throw new FormulaSyntaxException("YEARFRAC() requires two arguments");
    }
    LocalDate startDate = (LocalDate) arguments.get(0);
    LocalDate endDate = (LocalDate) arguments.get(1);
    if (startDate == null || endDate == null) {
        return null;
    }
    return new Quantity(compute(startDate, endDate));
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) Quantity(org.activityinfo.model.type.number.Quantity) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 8 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class AddDateFunction method columnApply.

@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
    ColumnView dateView = arguments.get(0);
    ColumnView daysView = arguments.get(1);
    String[] result = new String[dateView.numRows()];
    for (int i = 0; i < dateView.numRows(); i++) {
        LocalDate date = LocalDate.parse(dateView.getString(i));
        int days = (int) daysView.getDouble(i);
        result[i] = date.plusDays(days).toString();
    }
    return new StringArrayColumnView(result);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView) LocalDate(org.activityinfo.model.type.time.LocalDate) StringArrayColumnView(org.activityinfo.model.query.StringArrayColumnView)

Example 9 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class AddDateFunction method apply.

@Override
public FieldValue apply(List<FieldValue> arguments) {
    LocalDate date = (LocalDate) arguments.get(0);
    Quantity days = (Quantity) arguments.get(1);
    return date.plusDays((int) days.getValue());
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 10 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class DateComponentFunction method apply.

@Override
public final FieldValue apply(List<FieldValue> arguments) {
    checkArity(arguments, 1);
    FieldValue argument = arguments.get(0);
    if (!(argument instanceof LocalDate)) {
        throw new FormulaSyntaxException("Expected date argument");
    }
    LocalDate date = (LocalDate) argument;
    return new Quantity(apply(date));
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) LocalDate(org.activityinfo.model.type.time.LocalDate)

Aggregations

LocalDate (org.activityinfo.model.type.time.LocalDate)24 Test (org.junit.Test)11 Quantity (org.activityinfo.model.type.number.Quantity)8 FormInstance (org.activityinfo.model.form.FormInstance)7 RecordRef (org.activityinfo.model.type.RecordRef)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 ResourceId (org.activityinfo.model.resource.ResourceId)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 FormClass (org.activityinfo.model.form.FormClass)4 FieldValue (org.activityinfo.model.type.FieldValue)4 ReferenceValue (org.activityinfo.model.type.ReferenceValue)4 Date (java.util.Date)3 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)3 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)3 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)3 FormField (org.activityinfo.model.form.FormField)2 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)2 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)2 FilterConfig (com.sencha.gxt.data.shared.loader.FilterConfig)1 Calendar (java.util.Calendar)1