use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class CronDescriptorTest method testDescribeAtXHours.
@Test
public void testDescribeAtXHours() {
final int hour = 11;
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.SECOND, FieldExpression.always(), nullFieldConstraints));
assertEquals(String.format("at %s:00", hour), descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class CronDescriptorTest method testNearestWeekdayToNthOfMonth.
@Test
public void testNearestWeekdayToNthOfMonth() {
final int dayOfMonth = 22;
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_MONTH, new On(new IntegerFieldValue(dayOfMonth), new SpecialCharFieldValue(SpecialChar.W)), nullFieldConstraints));
assertEquals(String.format("at %s:%s the nearest weekday to the %s of the month", hour, minute, dayOfMonth), descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class CronDescriptorTest method testDescribeEveryXTimeUnits.
@Test
public void testDescribeEveryXTimeUnits() {
final int time = 3;
final Every expression = new Every(new IntegerFieldValue(time));
assertEquals(String.format("every %s seconds", time), descriptor.describe(new SingleCron(mockDefinition, Collections.singletonList(new CronField(CronFieldName.SECOND, expression, nullFieldConstraints)))));
assertEquals(String.format("every %s minutes", time), descriptor.describe(new SingleCron(mockDefinition, Collections.singletonList(new CronField(CronFieldName.MINUTE, expression, nullFieldConstraints)))));
final List<CronField> params = new ArrayList<>();
params.add(new CronField(CronFieldName.HOUR, expression, nullFieldConstraints));
params.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(time)), nullFieldConstraints));
assertEquals(String.format("every %s hours at minute %s", time, time), descriptor.describe(new SingleCron(mockDefinition, params)));
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class OnDayOfMonthValueGeneratorLTest method setUp.
@Before
public void setUp() {
final FieldConstraints constraints = FieldConstraintsBuilder.instance().addLSupport().createConstraintsInstance();
fieldValueGenerator = new OnDayOfMonthValueGenerator(new CronField(CronFieldName.DAY_OF_MONTH, new On(new SpecialCharFieldValue(SpecialChar.L)), constraints), YEAR, MONTH);
}
use of com.cronutils.model.field.expression.On in project cron-utils by jmrozanec.
the class ExecutionTimeBuilder method build.
protected ExecutionTime build() {
boolean lowestAssigned = false;
if (seconds == null) {
seconds = timeNodeLowest(CronFieldName.SECOND, 0, 59);
} else {
lowestAssigned = true;
}
if (minutes == null) {
minutes = lowestAssigned ? timeNodeAlways(CronFieldName.MINUTE, 0, 59) : timeNodeLowest(CronFieldName.MINUTE, 0, 59);
} else {
lowestAssigned = true;
}
if (hours == null) {
hours = lowestAssigned ? timeNodeAlways(CronFieldName.HOUR, 0, 23) : timeNodeLowest(CronFieldName.HOUR, 0, 23);
} else {
lowestAssigned = true;
}
if (daysOfMonthCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_MONTH);
daysOfMonthCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_MONTH, always(), constraints) : new CronField(CronFieldName.DAY_OF_MONTH, new On(new IntegerFieldValue(1)), constraints);
} else {
lowestAssigned = true;
}
if (daysOfWeekCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_WEEK);
daysOfWeekCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_WEEK, always(), constraints) : new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(1)), constraints);
} else {
lowestAssigned = true;
}
if (months == null) {
months = lowestAssigned ? timeNodeAlways(CronFieldName.MONTH, 1, 12) : timeNodeLowest(CronFieldName.MONTH, 1, 12);
}
if (yearsValueGenerator == null) {
yearsValueGenerator = FieldValueGeneratorFactory.forCronField(new CronField(CronFieldName.YEAR, always(), getConstraint(CronFieldName.YEAR)));
}
if (daysOfYearCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_YEAR);
daysOfYearCronField = new CronField(CronFieldName.DAY_OF_YEAR, lowestAssigned ? FieldExpression.questionMark() : always(), constraints);
}
return new SingleExecutionTime(this.cron.getCronDefinition(), this.cron.retrieve(CronFieldName.YEAR), daysOfWeekCronField, daysOfMonthCronField, daysOfYearCronField, months, hours, minutes, seconds);
}
Aggregations