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());
}
}
}
}
}
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));
}
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);
}
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());
}
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));
}
Aggregations