当前位置: 首页>>代码示例>>Java>>正文


Java CronDefinitionBuilder.instanceDefinitionFor方法代码示例

本文整理汇总了Java中com.cronutils.model.definition.CronDefinitionBuilder.instanceDefinitionFor方法的典型用法代码示例。如果您正苦于以下问题:Java CronDefinitionBuilder.instanceDefinitionFor方法的具体用法?Java CronDefinitionBuilder.instanceDefinitionFor怎么用?Java CronDefinitionBuilder.instanceDefinitionFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cronutils.model.definition.CronDefinitionBuilder的用法示例。


在下文中一共展示了CronDefinitionBuilder.instanceDefinitionFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValidCron

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
private boolean isValidCron(String s) {
    boolean isValid = false;
    CronDefinition cronD =
            CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    CronParser parser = new CronParser(cronD);
    com.cronutils.model.Cron cron = null;
    try {
        cron = parser.parse(s);
    } catch (IllegalArgumentException e) {
        LOG.debug("Cron parsing failed!",e);
    }
    if (cron != null) {
        isValid = true;
    }
    return isValid;
}
 
开发者ID:blacklabelops,项目名称:crow,代码行数:17,代码来源:CronValidator.java

示例2: testNextExecution2014

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #79: Next execution skipping valid date.
 */
@Test
public void testNextExecution2014() {
    final String crontab = "0 8 * * 1";//m,h,dom,m,dow ; every monday at 8AM
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final CronParser parser = new CronParser(cronDefinition);
    final Cron cron = parser.parse(crontab);
    final ZonedDateTime date = ZonedDateTime.parse("2014-11-30T00:00:00Z");
    final ExecutionTime executionTime = ExecutionTime.forCron(cron);
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(date);
    if (nextExecution.isPresent()) {
        assertEquals(ZonedDateTime.parse("2014-12-01T08:00:00Z"), nextExecution.get());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }

}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:20,代码来源:ExecutionTimeUnixIntegrationTest.java

示例3: testNextExecutionTimeProperlySet2

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #124:
 * https://github.com/jmrozanec/cron-utils/issues/124
 * Reported case: next execution time is set improperly
 * Potential duplicate: https://github.com/jmrozanec/cron-utils/issues/123
 */
@Test
public void testNextExecutionTimeProperlySet2() {
    final CronParser quartzCronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(QUARTZ));
    final String quartzCronExpression2 = "0 3/27 10-14 * * ? *";
    final Cron parsedQuartzCronExpression = quartzCronParser.parse(quartzCronExpression2);

    final ExecutionTime executionTime = ExecutionTime.forCron(parsedQuartzCronExpression);

    final ZonedDateTime zonedDateTime = LocalDateTime.of(2016, 1, 1, 10, 0, 0, 0).atZone(ZoneOffset.UTC);

    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(zonedDateTime);
    if (nextExecution.isPresent()) {
        final ZonedDateTime nextExecutionTime = nextExecution.get();
        assertEquals("2016-01-01T10:03Z", nextExecutionTime.toString());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:25,代码来源:ExecutionTimeQuartzIntegrationTest.java

示例4: testNextExecutionTimeProperlySet

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #123:
 * https://github.com/jmrozanec/cron-utils/issues/123
 * Reported case: next execution time is set improperly
 * Potential duplicate: https://github.com/jmrozanec/cron-utils/issues/124
 */
@Test
public void testNextExecutionTimeProperlySet() {
    final CronParser quartzCronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(QUARTZ));
    final String quartzCronExpression2 = "0 5/15 * * * ? *";
    final Cron parsedQuartzCronExpression = quartzCronParser.parse(quartzCronExpression2);

    final ExecutionTime executionTime = ExecutionTime.forCron(parsedQuartzCronExpression);

    final ZonedDateTime zonedDateTime = LocalDateTime.of(2016, 7, 30, 15, 0, 0, 527).atZone(ZoneOffset.UTC);
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(zonedDateTime);
    final Optional<ZonedDateTime> lastExecution = executionTime.lastExecution(zonedDateTime);
    if (nextExecution.isPresent() && lastExecution.isPresent()) {
        final ZonedDateTime nextExecutionTime = nextExecution.get();
        final ZonedDateTime lastExecutionTime = lastExecution.get();

        assertEquals("2016-07-30T14:50Z", lastExecutionTime.toString());
        assertEquals("2016-07-30T15:05Z", nextExecutionTime.toString());
    } else {
        fail(ASSERTED_EXECUTION_NOT_PRESENT);
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:28,代码来源:ExecutionTimeQuartzIntegrationTest.java

示例5: testWrongNextExecutionOnDSTEnd

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #112: Calling nextExecution exactly on the first instant of the fallback hour (after the DST ends) makes it go back to DST.
 * https://github.com/jmrozanec/cron-utils/issues/112
 */
@Test
public void testWrongNextExecutionOnDSTEnd() {
    final ZoneId zone = ZoneId.of("America/Sao_Paulo");

    //2016-02-20T23:00-03:00[America/Sao_Paulo], first minute of fallback hour
    final ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1456020000000L), zone);
    final ZonedDateTime expected = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1456020000000L + 60000), zone);

    final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("* * * * *"));
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(date);
    if (nextExecution.isPresent()) {
        assertEquals(expected, nextExecution.get());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:22,代码来源:ExecutionTimeUnixIntegrationTest.java

示例6: testEveryTwoMinRollsOverHour

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #38: every 2 min schedule doesn't roll over to next hour.
 */
@Test
public void testEveryTwoMinRollsOverHour() {
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final Cron cron = new CronParser(cronDefinition).parse("*/2 * * * *");
    final ExecutionTime executionTime = ExecutionTime.forCron(cron);
    final ZonedDateTime time = ZonedDateTime.parse("2015-09-05T13:56:00.000-07:00");
    final Optional<ZonedDateTime> nextExecutionTime = executionTime.nextExecution(time);
    if (nextExecutionTime.isPresent()) {
        final ZonedDateTime next = nextExecutionTime.get();
        final Optional<ZonedDateTime> shouldBeInNextHourExecution = executionTime.nextExecution(next);
        if (shouldBeInNextHourExecution.isPresent()) {
            assertEquals(next.plusMinutes(2), shouldBeInNextHourExecution.get());
            return;
        }
    }
    fail("one of the asserted values was not present.");
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:21,代码来源:ExecutionTimeUnixIntegrationTest.java

示例7: validate

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
@Override
public void validate() {
    CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
    try {
        parser.parse(expression);
    } catch (IllegalArgumentException iae) {
        throw new CronitSystemException("expression.not.valid", expression);
    }
}
 
开发者ID:212data,项目名称:cronit-repository,代码行数:10,代码来源:CronScheduler.java

示例8: parseQuartzCron

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
private static String parseQuartzCron(final String cron) {

        final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J);
        //create a parser based on provided definition
        final com.cronutils.parser.CronParser parser = new com.cronutils.parser.CronParser(cronDefinition);
        final Cron cron4jCron = parser.parse(cron);
        cron4jCron.validate();

        // Migrate types
        final CronMapper cronMapper = CronMapper.fromCron4jToQuartz();
        final Cron quartzCron = cronMapper.map(cron4jCron);

        return quartzCron.asString();
    }
 
开发者ID:ftsakiris,项目名称:async-engine,代码行数:15,代码来源:ScheduledTaskService.java

示例9: initializeExecutionTime

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
private ExecutionTime initializeExecutionTime() {
    ExecutionTime executionTime = null;
    CronDefinition cronD =
            CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    CronParser parser = new CronParser(cronD);
    Cron cron = parser.parse(cronString);
    executionTime = ExecutionTime.forCron(cron);
    return executionTime;
}
 
开发者ID:blacklabelops,项目名称:crow,代码行数:10,代码来源:CronUtilsExecutionTime.java

示例10: fromQuartzToUnix

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
public static CronMapper fromQuartzToUnix() {
    return new CronMapper(
            CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ),
            CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX),
            sameCron()
    );
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:8,代码来源:CronMapper.java

示例11: exactHitReturnsFullIntervalDuration

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #130: Wrong last execution time if schedule hit is less than one second ago
 * https://github.com/jmrozanec/cron-utils/issues/130
 */
@Test
public void exactHitReturnsFullIntervalDuration() {
    final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
    final Cron cron = parser.parse("0 12 * * *");
    final ZonedDateTime time = ZonedDateTime.of(2016, 12, 2, 12, 0, 0, 0, ZoneId.of("Europe/Vienna"));
    final Optional<Duration> timeFromLastExecution = ExecutionTime.forCron(cron).timeFromLastExecution(time);
    if (timeFromLastExecution.isPresent()) {
        assertEquals(timeFromLastExecution.get(), Duration.ofHours(24));
    } else {
        fail(LAST_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:17,代码来源:ExecutionTimeUnixIntegrationTest.java

示例12: testMatchExact

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
@Test
public void testMatchExact() {
    final CronDefinition cronDefinition =
            CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);

    final CronParser parser = new CronParser(cronDefinition);
    final Cron quartzCron = parser.parse("00 00 10 * * ?");

    quartzCron.validate();

    final ZonedDateTime zdt = ZonedDateTime.of(1999, 07, 18, 10, 00, 00, 00, ZoneId.systemDefault());

    assertTrue("Nano seconds must not affect matching of Cron Expressions", ExecutionTime.forCron(quartzCron).isMatch(zdt));
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:15,代码来源:Issue200Test.java

示例13: testCronTypeQuartz

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
@Test
public void testCronTypeQuartz() {
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
    final CronParser parser = new CronParser(cronDefinition);
    final Cron cron = parser.parse(ISSUE_EXPRESSION);
    assertThat("cron is not null", cron != null);
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:8,代码来源:Issue281Test.java

示例14: testSerialization

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    final CronDefinition cron4jcd = CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J);
    final CronDefinition unixcd = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final CronDefinition quartzcd = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
    final CronParser unix = new CronParser(unixcd);
    final CronParser quartz = new CronParser(quartzcd);
    final CronParser cron4j = new CronParser(cron4jcd);

    final Cron[] toTest = new Cron[] {
            unix.parse("* * * * MON"),
            unix.parse("*/1 * * * 1"),
            unix.parse("0 * * * *"),
            unix.parse("*/2 * * * *"),
            quartz.parse("0 * * ? * MON *"),
            cron4j.parse("* 1 1,2 * 4"),
            cron4j.parse("* 1 1-2 * 4"),
            cron4j.parse("0 18 * * 1"),
            cron4j.parse("0/15 * * * *"),
            cron4j.parse("0 0/2 * * *"),
            cron4j.parse("0 6 * * MON-FRI")
    };

    for (final Cron expected : toTest) {
        final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        try (ObjectOutputStream objOut = new ObjectOutputStream(byteOut)) {
            objOut.writeObject(expected);
        }

        try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()))) {
            final Cron actual = (Cron) objIn.readObject();
            assertEquals(expected.asString(), actual.asString());
        }
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:36,代码来源:CronTest.java

示例15: testEveryTuesdayAtThirdHourOfDayLastExecution

import com.cronutils.model.definition.CronDefinitionBuilder; //导入方法依赖的package包/类
/**
 * Issue #41: for everything other than a dayOfWeek value == 1, nextExecution and lastExecution do not return correct results.
 */
@Test
public void testEveryTuesdayAtThirdHourOfDayLastExecution() {
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final CronParser parser = new CronParser(cronDefinition);
    final Cron myCron = parser.parse("0 3 * * 3");
    final ZonedDateTime time = ZonedDateTime.parse("2015-09-17T00:00:00.000-07:00");
    final Optional<ZonedDateTime> lastExecution = ExecutionTime.forCron(myCron).lastExecution(time);
    if (lastExecution.isPresent()) {
        assertEquals(ZonedDateTime.parse("2015-09-16T03:00:00.000-07:00"), lastExecution.get());
    } else {
        fail(LAST_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:17,代码来源:ExecutionTimeUnixIntegrationTest.java


注:本文中的com.cronutils.model.definition.CronDefinitionBuilder.instanceDefinitionFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。