List of usage examples for org.joda.time DateTime plusYears
public DateTime plusYears(int years)
From source file:projectresurrection.Schedule.java
public void run() { while (true) { DateTime date = Eve.clock.getCurrent(); try {//from www . j a va 2 s . c o m for (int i = 0; i < container.get(0).size(); i++) { DateTime setDate = new DateTime(container.get(0).get(i).get(1)); if (date.getMillis() > setDate.getMillis()) { Eve.addCommand(container.get(0).get(i).get(2).toString()); container.get(0).remove(i); save(); } } for (int i = 0; i < container.get(1).size(); i++) { DateTime setDate = new DateTime(container.get(1).get(i).get(1)); if (date.getMillis() > setDate.getMillis()) { announce(container.get(1).get(i).get(0).toString()); container.get(1).remove(i); save(); } } for (int i = 0; i < container.get(2).size(); i++) { DateTime setDate = new DateTime(container.get(2).get(i).get(1)); if (date.getMillis() > setDate.getMillis()) { announce(container.get(2).get(i).get(0).toString()); DateTime temp = new DateTime(container.get(2).get(i).get(1)); container.get(2).get(i).remove(1); switch (container.get(2).get(i).get(1).toString()) { case "Annual": container.get(2).get(i).add(1, new DateTime(temp.plusYears(1))); break; case "Bi-annaul": container.get(2).get(i).add(1, new DateTime(temp.plusMonths(6))); break; case "Monthly": container.get(2).get(i).add(1, new DateTime(temp.plusMonths(1))); break; case "Weekly": container.get(2).get(i).add(1, new DateTime(temp.plusWeeks(1))); break; case "Daily": container.get(2).get(i).add(1, new DateTime(temp.plusDays(1))); break; } save(); } } Thread.sleep(1000); } catch (Exception e) { Thread.currentThread().interrupt(); } } }
From source file:rapture.kernel.schedule.CronParser.java
License:Open Source License
/** * Returns the next run date based on a fromPoint (starting date). Returns null if there is no more future runs. * * @param fromPoint//from w w w . j av a 2s. co m * @return */ public DateTime nextRunDate(DateTime fromPoint) { if (years != null) { int year = fromPoint.getYear(); if (year > getHighestYear()) { // year specified in the cron spec is in the past, so no more runs return null; } while (!years.contains(year)) { fromPoint = fromPoint.plusYears(1).withDayOfYear(1).withTime(0, 0, 0, 0); year = fromPoint.getYear(); } DateTime result = cronExpression.nextTimeAfter(fromPoint); year = result.getYear(); if (year > getHighestYear()) { // year specified in the cron spec is in the past, so no more runs return null; } else { return result; } } else { return cronExpression.nextTimeAfter(fromPoint); } }
From source file:ru.caramel.juniperbot.core.moderation.service.MuteServiceImpl.java
License:Open Source License
private void storeState(ModerationActionRequest request) { MuteState state = new MuteState(); state.setGlobal(request.isGlobal()); state.setUserId(request.getViolator().getUser().getId()); state.setGuildId(request.getViolator().getGuild().getIdLong()); DateTime dateTime = DateTime.now(); if (request.getDuration() != null) { dateTime = dateTime.plusMinutes(request.getDuration()); } else {/*ww w . j a v a 2 s. c om*/ dateTime = dateTime.plusYears(100); } state.setExpire(dateTime.toDate()); state.setReason(request.getReason()); if (request.getChannel() != null) { state.setChannelId(request.getChannel().getId()); } muteStateRepository.save(state); }
From source file:singlejartest.StrategyTesterLoop.java
License:Open Source License
public static void main(String[] args) throws Exception { final ClimberProperties properties = new ClimberProperties(); if (args.length < 1) { LOGGER.error("One argument needed (name of config file)"); System.exit(1);/*w w w.j a v a2s .com*/ } try { properties.load(new FileInputStream(args[0])); } catch (IOException e) { LOGGER.error("Can't open or can't read properties file " + args[0] + "..."); System.exit(1); } if (properties.getProperty("noConsoleOutput", "no").equals("yes")) System.setOut(new PrintStream( ".\\Strategy_log_" + FXUtils.getFileTimeStamp(System.currentTimeMillis()) + ".log")); properties.validate(LOGGER); // get the instance of the IClient interface final ITesterClient client = TesterFactory.getDefaultInstance(); // set the listener that will receive system events client.setSystemListener(new ISystemListener() { @Override public void onStart(long processId) { LOGGER.info("Strategy started: " + processId); } @Override public void onStop(long processId) { LOGGER.info("Strategy stopped: " + processId); File reportFile = new File(properties.getProperty("reportDirectory", ".") + "\\Strategy_run_report_" + FXUtils.getFileTimeStamp(System.currentTimeMillis()) + ".html"); try { client.createReport(processId, reportFile); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } @Override public void onConnect() { LOGGER.info("Connected"); } @Override public void onDisconnect() { // tester doesn't disconnect } }); FXUtils.setDbToUse(properties.getProperty("dbToUse")); String timePeriod = properties.getProperty("period"); if (timePeriod == null || timePeriod.length() == 0 || !(timePeriod.equalsIgnoreCase("y") || timePeriod.equalsIgnoreCase("m"))) { LOGGER.error("property period needed, must by either m - for months or y - for years"); System.exit(1); } String repeat = properties.getProperty("repeat"); int repeatNo = -1; if (repeat == null || repeat.length() == 0) { LOGGER.error("repeat property must be set !"); System.exit(1); } else { try { repeatNo = Integer.parseInt(repeat); } catch (NumberFormatException e) { LOGGER.error("Format of repeat property wrong, must be integer: " + repeat + ", exception " + e.getMessage()); System.exit(1); } } String noOfPeriodsStr = properties.getProperty("howManyPeriods"); int noOfPeriods = -1; if (noOfPeriodsStr == null || noOfPeriodsStr.length() == 0) { LOGGER.error("howManyPeriods property must be set !"); System.exit(1); } else { try { noOfPeriods = Integer.parseInt(noOfPeriodsStr); } catch (NumberFormatException e) { LOGGER.error("Format of repeat property wrong, must be integer: " + repeat + ", exception " + e.getMessage()); System.exit(1); } } // set instruments that will be used in testing StringTokenizer st = new StringTokenizer(properties.getProperty("pairsToCheck"), ";"); Set<Instrument> instruments = new HashSet<Instrument>(); String pair = null; while (st.hasMoreTokens()) { String nextPair = st.nextToken(); instruments.add(Instrument.fromString(nextPair)); if (pair == null) pair = new String(nextPair); } Instrument selectedInstrument = Instrument.fromString(pair); DateTime startDate = new DateTime(properties.getTestIntervalStart().getMillis()); for (int j = 0; j < repeatNo; j++) { DateTime endDate = null; if (timePeriod.equalsIgnoreCase("m")) endDate = startDate.plusMonths(noOfPeriods); else endDate = startDate.plusYears(noOfPeriods); LOGGER.info("Starting backtest for the period: " + startDate.toString("dd.MM.yyyy") + " to " + endDate.toString("dd.MM.yyyy")); LOGGER.info("Connecting..."); // connect to the server using jnlp, user name and password // connection is needed for data downloading client.connect(jnlpUrl, properties.getProperty("username"), properties.getProperty("password")); // wait for it to connect int i = 10; // wait max ten seconds while (i > 0 && !client.isConnected()) { Thread.sleep(1000); i--; } if (!client.isConnected()) { LOGGER.error("Failed to connect Dukascopy servers"); System.exit(1); } LOGGER.info("Subscribing instruments..."); client.setCacheDirectory(new File(properties.getProperty("cachedir"))); client.setSubscribedInstruments(instruments); // setting initial deposit client.setInitialDeposit(Instrument.EURUSD.getSecondaryJFCurrency(), Double.parseDouble(properties.getProperty("initialdeposit", "100000.0"))); client.setDataInterval(Period.TICK, null, null, startDate.getMillis(), endDate.getMillis()); // load data LOGGER.info("Downloading data"); Future<?> future = client.downloadData(null); // wait for downloading to complete Thread.sleep(10000); // this timeout helped future.get(); // start the strategy LOGGER.info("Starting strategy"); // client.startStrategy(new IchiAutoEntry(properties, // properties.getTestIntervalStart().getMillis(), // properties.getTestIntervalEnd().getMillis(), startTime), tradeTestRunningSignal = new File("strategyTestRunning.bin"); if (tradeTestRunningSignal.exists()) tradeTestRunningSignal.delete(); tradeTestRunningSignal.createNewFile(); // once test run is finished this file should be deleted ! client.startStrategy(//new SimpleMAsIDCrossTrendFollow(properties), new FlatCascTest(selectedInstrument, properties), new LoadingProgressListener() { @Override public void dataLoaded(long startTime, long endTime, long currentTime, String information) { LOGGER.info(information); } @Override public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) { } @Override public boolean stopJob() { return false; } }); // now it's running while (tradeTestRunningSignal.exists()) { } startDate = endDate; } if (client.getStartedStrategies().size() == 0) { System.exit(0); } }
From source file:stroom.entity.server.util.PeriodUtil.java
License:Apache License
/** * Create a year period.//www . j a va2 s . co m * * @param year * e.g. 2001 */ public static Period createYearPeriod(final Integer year) { final DateTime startOfYear = new DateTime(year, 1, 1, 0, 0, 0, 0); return new Period(startOfYear.getMillis(), startOfYear.plusYears(1).getMillis()); }
From source file:stroom.index.server.IndexShardKeyUtil.java
License:Apache License
public static IndexShardKey createTimeBasedKey(final Index index, final long timeMs, final int shardNo) { String partition = ALL;/*from w w w . j a va 2 s . c om*/ DateTime dateFrom = null; DateTime dateTo = null; if (index.getPartitionBy() != null && index.getPartitionSize() > 0) { dateFrom = new DateTime(timeMs); if (PartitionBy.YEAR.equals(index.getPartitionBy())) { int year = dateFrom.get(DateTimeFieldType.year()); year = fix(year, index.getPartitionSize()); dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateTo = dateFrom.plusYears(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 4); } else if (PartitionBy.MONTH.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int month = dateFrom.get(DateTimeFieldType.monthOfYear()); month = fix(month, index.getPartitionSize()); if (month < 1) { month = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusMonths(month - 1); dateTo = dateFrom.plusMonths(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 7); } else if (PartitionBy.WEEK.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int week = dateFrom.get(DateTimeFieldType.weekOfWeekyear()); week = fix(week, index.getPartitionSize()); if (week < 1) { week = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusWeeks(week - 1); dateTo = dateFrom.plusWeeks(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 10); } else if (PartitionBy.DAY.equals(index.getPartitionBy())) { final int year = dateFrom.get(DateTimeFieldType.year()); int day = dateFrom.get(DateTimeFieldType.dayOfYear()); day = fix(day, index.getPartitionSize()); if (day < 1) { day = 1; } dateFrom = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dateFrom = dateFrom.plusDays(day - 1); dateTo = dateFrom.plusDays(index.getPartitionSize()); partition = DateUtil.createFileDateTimeString(dateFrom.getMillis()); partition = partition.substring(0, 10); } } Long partitionFromTime = null; if (dateFrom != null) { partitionFromTime = dateFrom.getMillis(); } Long partitionToTime = null; if (dateTo != null) { partitionToTime = dateTo.getMillis(); } return new IndexShardKey(index, partition, partitionFromTime, partitionToTime, shardNo); }
From source file:test.integ.be.fedict.performance.CAConfiguration.java
License:Open Source License
private X509Certificate generateCertificate(PublicKey publicKey, String issuerName, PrivateKey issuerPrivateKey, X509Certificate issuerCertificate, long maxRevokedSn) throws Exception { DateTime now = new DateTime(); DateTime notBefore = now.minusYears(10); DateTime notAfter = now.plusYears(10); return TestUtils.generateCertificate(publicKey, name, issuerPrivateKey, issuerCertificate, notBefore, notAfter, "SHA512WithRSAEncryption", true, true, false, OcspServlet.getPath(issuerName), CrlServlet.getPath(issuerName), new KeyUsage(KeyUsage.cRLSign), new BigInteger(Long.toString(maxRevokedSn + 1))); }
From source file:tud.time4maps.help.SplitTimeParams.java
License:Apache License
/** * This method extracts the default time from the time string of the dimension tag. * If the time information is malformed or can't be handled by the javascript code the year will be corrected and set to 1800. * //from w w w .jav a 2 s . c om * @param timeVals_ - an array with start date, end date and period time or time steps * @return a date object with default date information */ public Date getDefaultTime(String[] timeVals_) { DateTime defaultDate = null; int minYear = 1800; //dojo calendar can't handle earlier years if (timeVals_.length == 3 || timeVals_.length == 2) { if (timeVals_[0] != "" && timeVals_[0] != null) { defaultDate = new DateTime(timeVals_[0]); if (defaultDate.getYear() < minYear) defaultDate = defaultDate.plusYears(minYear - defaultDate.getYear()); return defaultDate.toDate(); } } else if (timeVals_.length == 1) { if (timeVals_[0].contains(",")) timeVals_ = timeVals_[0].split(","); if (timeVals_[0] != "" && timeVals_[0] != null) { defaultDate = new DateTime(timeVals_[0]); if (defaultDate.getYear() < minYear) defaultDate = defaultDate.plusYears(minYear - defaultDate.getYear()); return defaultDate.toDate(); } } return null; }
From source file:tud.time4maps.help.SplitTimeParams.java
License:Apache License
/** * This method extracts the start date from the time string of the dimension tag. * //from w w w . j a v a 2 s. c o m * @param timeVals_ - an array with start date, end date and period time or time steps * @return a date object with information about start of given time range */ public Date getStartDate(String[] timeVals_) { DateTime startDate = null; int minYear = 1800; if (timeVals_.length == 3 || timeVals_.length == 2) { if (timeVals_[0].contains("T00:00:00.000Z")) timeVals_[0] = timeVals_[0].replace("T00:00:00.000Z", ""); timeVals_[0] = timeVals_[0].replace("Z", ""); startDate = new DateTime(timeVals_[0]); if (startDate.getYear() < minYear) startDate = startDate.plusYears(minYear - startDate.getYear()); return startDate.toDate(); } else if (timeVals_.length == 1 && timeVals_ != null && timeVals_[0] != "") { if (timeVals_[0].contains(",")) timeVals_ = timeVals_[0].split(","); if (timeVals_[0] != "") { if (timeVals_[0].contains("T0:0:0.0Z")) timeVals_[0] = timeVals_[0].replace("T0:0:0.0Z", ""); if (timeVals_[0].contains("T00:00:00.000Z")) timeVals_[0] = timeVals_[0].replace("T00:00:00.000Z", ""); timeVals_[0] = timeVals_[0].replace("Z", ""); startDate = new DateTime(timeVals_[0]); return startDate.toDate(); } return null; } return null; }
From source file:TVShowTimelineMaker.timeConstraints.AgeConstraint.java
@Override public boolean complexApplyConstraint() { boolean changed = this.applyConstraint(); OnceDayEvent birthDay = this.mCharacter.getBirthday(); if ((!birthDay.isMarkedForComplexEval()) && this.mAtEvent.isMarkedForComplexEval()) { birthDay.setUpForComplexEval();/*from www.ja v a 2 s . c o m*/ } if (birthDay.isMarkedForComplexEval() && (!this.mAtEvent.isMarkedForComplexEval())) { this.mAtEvent.setUpForComplexEval(); } if (birthDay.isMarkedForComplexEval() && this.mAtEvent.isMarkedForComplexEval()) { NavigableSet<DateTime> birthDayDates = birthDay.getPossibleDays(); NavigableSet<DateTime> EventAtDates = this.mAtEvent.getPossibleDays(); DateTime lowerBoundOnBirthDay = EventAtDates.first().minusYears(this.upperBound).withHourOfDay(1); DateTime upperBoundOnBirthDay = EventAtDates.first().minusYears(this.lowerBound).withHourOfDay(23); Iterator<DateTime> birthDayIterator = birthDayDates.iterator(); Iterator<DateTime> EventAtDatesIterator = EventAtDates.iterator(); DateTime curBirthDay = birthDayIterator.next(); DateTime curEventAtDate = EventAtDatesIterator.next(); boolean cont = true; //while (birthDayIterator.hasNext()) { while (cont) { if (curBirthDay.isBefore(lowerBoundOnBirthDay)) { birthDayIterator.remove(); if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } changed = true; } else if (curBirthDay.isAfter(upperBoundOnBirthDay)) { if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); lowerBoundOnBirthDay = curEventAtDate.minusYears(this.upperBound).withHourOfDay(1); upperBoundOnBirthDay = curEventAtDate.minusYears(this.lowerBound).withHourOfDay(23); } else { birthDayIterator.remove(); if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } changed = true; } } else { if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } } } birthDayIterator = birthDayDates.iterator(); EventAtDatesIterator = EventAtDates.iterator(); curBirthDay = birthDayIterator.next(); curEventAtDate = EventAtDatesIterator.next(); cont = true; DateTime lowerBoundOnEvent = birthDayDates.first().plusYears(this.lowerBound).withHourOfDay(1); DateTime upperBoundOnEvent = birthDayDates.first().plusYears(this.upperBound).withHourOfDay(23); while (cont) { if (curEventAtDate.isBefore(lowerBoundOnEvent)) { EventAtDatesIterator.remove(); if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } changed = true; } else if (curEventAtDate.isAfter(upperBoundOnEvent)) { if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); lowerBoundOnEvent = curBirthDay.plusYears(this.lowerBound).withHourOfDay(1); upperBoundOnEvent = curBirthDay.plusYears(this.upperBound).withHourOfDay(23); } else { EventAtDatesIterator.remove(); if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } } } } return changed; }