Search in sources :

Example 16 with On

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)));
}
Also used : Between(com.cronutils.model.field.expression.Between) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 17 with On

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)));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 18 with On

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;
}
Also used : On(com.cronutils.model.field.expression.On)

Example 19 with On

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);
}
Also used : IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Before(org.junit.Before)

Example 20 with On

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);
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Before(org.junit.Before)

Aggregations

On (com.cronutils.model.field.expression.On)21 CronField (com.cronutils.model.field.CronField)15 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)13 Test (org.junit.Test)10 SingleCron (com.cronutils.model.SingleCron)9 ArrayList (java.util.ArrayList)9 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)5 Before (org.junit.Before)4 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)2 Between (com.cronutils.model.field.expression.Between)2 Every (com.cronutils.model.field.expression.Every)2 Function (com.cronutils.Function)1 WeekDay (com.cronutils.mapper.WeekDay)1 DayOfWeekFieldDefinition (com.cronutils.model.field.definition.DayOfWeekFieldDefinition)1 FieldDefinition (com.cronutils.model.field.definition.FieldDefinition)1 And (com.cronutils.model.field.expression.And)1 FieldExpression (com.cronutils.model.field.expression.FieldExpression)1 MessageFormat (java.text.MessageFormat)1 DayOfWeek (java.time.DayOfWeek)1 Month (java.time.Month)1