本文整理汇总了Java中com.cronutils.model.CronType类的典型用法代码示例。如果您正苦于以下问题:Java CronType类的具体用法?Java CronType怎么用?Java CronType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CronType类属于com.cronutils.model包,在下文中一共展示了CronType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidCron
import com.cronutils.model.CronType; //导入依赖的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;
}
示例2: test
import com.cronutils.model.CronType; //导入依赖的package包/类
@Test
public void test() {
CronDefinition def = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
CronParser parser = new CronParser(def);
Cron cron = parser.parse(cronText);
ExecutionTime et = ExecutionTime.forCron(cron);
ZonedDateTime vs = ZonedDateTime.of(2017, 12, 1, 9, 30, 0, 0, ZONE);
assertEquals(DayOfWeek.FRIDAY, vs.getDayOfWeek());
// Last match prior to our reference time
ZonedDateTime expected = ZonedDateTime.of(2017, 11, 30, 18, 15, 0, 0, ZONE);
assertEquals(DayOfWeek.THURSDAY, expected.getDayOfWeek());
Optional<ZonedDateTime> lastExecution = et.lastExecution(vs);
if (lastExecution.isPresent()) {
ZonedDateTime actual = lastExecution.get();
assertEquals(expected, actual);
} else {
fail("last execution was not present");
}
}
示例3: supportQuartzCronExpressionIncrementsOnYears
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #154: Quartz Cron Year Pattern is not fully supported - i.e. increments on years are not supported
* https://github.com/jmrozanec/cron-utils/issues/154
* Duplicate of #148
*/
@Test
public void supportQuartzCronExpressionIncrementsOnYears() {
final String[] sampleCronExpressions = {
"0 0 0 1 * ? 2017/2",
"0 0 0 1 * ? 2017/3",
"0 0 0 1 * ? 2017/10",
"0 0 0 1 * ? 2017-2047/2",
};
final CronParser quartzCronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
for (final String cronExpression : sampleCronExpressions) {
final Cron quartzCron = quartzCronParser.parse(cronExpression);
quartzCron.validate();
}
}
示例4: testEveryTwoMinRollsOverHour
import com.cronutils.model.CronType; //导入依赖的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.");
}
示例5: testMondayWeekdayNextExecution
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #45: next execution does not match expected date. Result is not in same timezone as reference date.
*/
@Test
public void testMondayWeekdayNextExecution() {
final String crontab = "* * * * 1";
final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
final CronParser parser = new CronParser(cronDefinition);
final Cron cron = parser.parse(crontab);
final ZonedDateTime date = ZonedDateTime.parse("2015-10-13T17:26:54.468-07:00");
final ExecutionTime executionTime = ExecutionTime.forCron(cron);
final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(date);
if (nextExecution.isPresent()) {
assertEquals(ZonedDateTime.parse("2015-10-19T00:00:00.000-07:00"), nextExecution.get());
} else {
fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
}
}
示例6: testNextExecutionDaylightSaving
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #61: nextExecution over daylight savings is wrong.
*/
@Test
public void testNextExecutionDaylightSaving() {
final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0 17 * * *"));// daily at 17:00
// Daylight savings for New York 2016 is Mar 13 at 2am
final ZonedDateTime last = ZonedDateTime.of(2016, 3, 12, 17, 0, 0, 0, ZONE_ID_NEW_YORK);
final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(last);
if (nextExecution.isPresent()) {
final long millis = Duration.between(last, nextExecution.get()).toMillis();
assertEquals(23, (millis / 3600000));
assertEquals(last.getZone(), nextExecution.get().getZone());
} else {
fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
}
}
示例7: testLastExecutionDaylightSaving
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #61: lastExecution over daylight savings is wrong.
*/
@Test
public void testLastExecutionDaylightSaving() {
final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0 17 * * *"));// daily at 17:00
// Daylight savings for New York 2016 is Mar 13 at 2am
final ZonedDateTime now = ZonedDateTime.of(2016, 3, 12, 17, 0, 0, 0, ZoneId.of("America/Phoenix"));
final Optional<ZonedDateTime> lastExecution = executionTime.lastExecution(now);
if (lastExecution.isPresent()) {
final long millis = Duration.between(lastExecution.get(), now).toMillis();
assertEquals(24, (millis / 3600000));
assertEquals(now.getZone(), lastExecution.get().getZone());
} else {
fail(LAST_EXECUTION_NOT_PRESENT_ERROR);
}
}
示例8: testNextExecution2014
import com.cronutils.model.CronType; //导入依赖的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);
}
}
示例9: testWrongNextExecutionOnDSTEnd
import com.cronutils.model.CronType; //导入依赖的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);
}
}
示例10: testNextExecutionProducesStackTraces
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #125: Prints stack trace for NoSuchValueException for expressions with comma-separated values
* https://github.com/jmrozanec/cron-utils/issues/125
*/
@Test
public void testNextExecutionProducesStackTraces() {
final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("45 1,13 * * *"));
executionTime.nextExecution(ZonedDateTime.parse("2016-05-24T01:02:50Z"));
}
示例11: testEveryWednesdayOfEveryDayNextExecution
import com.cronutils.model.CronType; //导入依赖的package包/类
/**
* Issue #223: for dayOfWeek value == 3 && division of day, nextExecution do not return correct results.
*/
@Test
public void testEveryWednesdayOfEveryDayNextExecution() {
final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
final CronParser parser = new CronParser(cronDefinition);
final Cron myCron = parser.parse("* * * * 3");
ZonedDateTime time = ZonedDateTime.parse("2017-09-05T11:31:55.407-05:00");
final Optional<ZonedDateTime> nextExecution = ExecutionTime.forCron(myCron).nextExecution(time);
if (nextExecution.isPresent()) {
assertEquals(ZonedDateTime.parse("2017-09-06T00:00-05:00"), nextExecution.get());
} else {
fail("next execution was not present");
}
final Cron myCron2 = parser.parse("* * */1 * 3");
time = ZonedDateTime.parse("2017-09-05T11:31:55.407-05:00");
final Optional<ZonedDateTime> nextExecution2 = ExecutionTime.forCron(myCron2).nextExecution(time);
if (nextExecution2.isPresent()) {
assertEquals(ZonedDateTime.parse("2017-09-06T00:00-05:00"), nextExecution2.get());
} else {
fail("next execution was not present");
}
}
示例12: main
import com.cronutils.model.CronType; //导入依赖的package包/类
public static void main(String[] args) {
Scheduler scheduler = new Scheduler();
Job job = new Job("Hello world!") {
@Override
protected ExecutionStatus execute() {
System.out.println("Hello world!");
return ExecutionStatus.SUCCESS;
}
};
Trigger trigger = new CronTrigger(new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).parse("* * * ? * * *"));
scheduler.schedule(new ExecutableUnit(job, trigger));
}
示例13: validate
import com.cronutils.model.CronType; //导入依赖的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);
}
}
示例14: parseQuartzCron
import com.cronutils.model.CronType; //导入依赖的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();
}
示例15: initializeExecutionTime
import com.cronutils.model.CronType; //导入依赖的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;
}