use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class CronDescriptorTest method testDescribeAtXTimeBetweenDaysOfWeek.
@Test
public void testDescribeAtXTimeBetweenDaysOfWeek() {
final int hour = 11;
final int minute = 30;
final int start = 2;
final int end = 6;
final Between expression = new Between(new IntegerFieldValue(start), new IntegerFieldValue(end));
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(minute)), nullFieldConstraints));
results.add(new CronField(CronFieldName.DAY_OF_WEEK, expression, nullFieldConstraints));
assertEquals(String.format("at %s:%s every day between Tuesday and Saturday", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class CronDescriptorTest method testLastDayOfWeekInMonth.
@Test
public void testLastDayOfWeekInMonth() {
final int dayOfWeek = 2;
final int hour = 10;
final int minute = 15;
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(minute)), nullFieldConstraints));
results.add(new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(dayOfWeek), new SpecialCharFieldValue(SpecialChar.L)), nullFieldConstraints));
assertEquals(String.format("at %s:%s last Tuesday of every month", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class DescriptionStrategyFactory method daysOfMonthInstance.
/**
* Creates description strategy for days of month.
*
* @param bundle - locale
* @param expression - CronFieldExpression
* @return - DescriptionStrategy instance, never null
*/
public static DescriptionStrategy daysOfMonthInstance(final ResourceBundle bundle, final FieldExpression expression) {
final NominalDescriptionStrategy dom = new NominalDescriptionStrategy(bundle, null, expression);
dom.addDescription(fieldExpression -> {
if (fieldExpression instanceof On) {
final On on = (On) fieldExpression;
switch(on.getSpecialChar().getValue()) {
case W:
return String.format("%s %s %s ", bundle.getString("the_nearest_weekday_to_the"), on.getTime().getValue(), bundle.getString("of_the_month"));
case L:
Integer daysBefore = on.getNth().getValue();
if (daysBefore > 1) {
return MessageFormat.format(bundle.getString("days_before_last_day_of_month"), daysBefore);
} else if (daysBefore == 1) {
return bundle.getString("day_before_last_day_of_month");
} else {
return bundle.getString("last_day_of_month");
}
case LW:
return bundle.getString("last_weekday_of_month");
default:
return "";
}
}
return "";
});
return dom;
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class OnDayOfMonthValueGeneratorTest method setUp.
@Before
public void setUp() {
constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
fieldValueGenerator = new OnDayOfMonthValueGenerator(new CronField(CronFieldName.DAY_OF_MONTH, new On(new IntegerFieldValue(3)), constraints), YEAR, MONTH);
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class OnDayOfWeekValueGeneratorTest method setUp.
@Before
public void setUp() {
constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
mondayDoWValue = new WeekDay(1, false);
fieldValueGenerator = new OnDayOfWeekValueGenerator(new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(3)), constraints), YEAR, MONTH, mondayDoWValue);
}
Aggregations