List of usage examples for org.joda.time DateTime minusHours
public DateTime minusHours(int hours)
From source file:rapture.dp.invocable.CheckPrerequisiteStep.java
License:Open Source License
private DateTime getDateTime(DateTime dateTime, String dateWithin, String timeNoEarlierThan) { if (!StringUtils.isEmpty(timeNoEarlierThan)) { DateTime hours = getDateTime(timeNoEarlierThan); if (dateTime == null) dateTime = hours;/* w w w .j ava 2s . co m*/ else { dateTime = dateTime.withMillisOfDay(hours.getMillisOfDay()).withZone(hours.getZone()); } } if (!StringUtils.isEmpty(dateWithin)) { int number = Integer.valueOf(dateWithin.substring(0, dateWithin.length() - 1)); char dateUnit = dateWithin.charAt(dateWithin.length() - 1); switch (dateUnit) { case 'M': dateTime = dateTime.minusMonths(number); break; case 'W': dateTime = dateTime.minusWeeks(number); break; case 'D': dateTime = dateTime.minusDays(number); break; case 'H': dateTime = dateTime.minusHours(number); break; case 'B': dateTime = USCalendar.minusBusinessDays(dateTime, number); break; default: throw RaptureExceptionFactory.create("Invalid date unit " + dateUnit); } } return dateTime; }
From source file:singlejartest.LastNightExplorer.java
License:Open Source License
public static void main(String[] args) throws Exception { // get the instance of the IClient interface final ITesterClient client = TesterFactory.getDefaultInstance(); final ClimberProperties properties = new ClimberProperties(); if (args.length < 1) { LOGGER.error("One argument needed: name of config file"); System.exit(1);/*from w w w . jav a 2s . 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); } properties.validate(LOGGER); // key idea is here: ignore config file and setup test interval // artificially last 20 pm - 6 am interval int daysBack = 0; if (args.length > 1) { try { daysBack = Integer.parseInt(args[1]); } catch (NumberFormatException e) { LOGGER.error("Second argument format wrong: must be a positive integer number"); System.exit(1); } if (daysBack < 1) { LOGGER.error("Second argument format wrong: must be a positive integer number"); System.exit(1); } } DateTime roundedEnd = calcEndBar(daysBack); String tsString = roundedEnd.toString("yyyy_MM_dd_HH_mm"); final jforex.utils.log.Logger reportLogger = new jforex.utils.log.Logger(null, properties.getProperty("reportDirectory", ".") + "//" + "Overnight 4h Report for " + tsString + ".txt"); // 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) { reportLogger.close(); LOGGER.info("Strategy stopped: " + processId); // TODO: find a way to run in Java repeatedly if (client.getStartedStrategies().size() == 0) { System.exit(0); } } @Override public void onConnect() { LOGGER.info("Connected"); } @Override public void onDisconnect() { // tester doesn't disconnect } }); 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); } // set instruments that will be used in testing StringTokenizer st = new StringTokenizer(properties.getProperty("pairsToCheck"), ";"); Set<Instrument> instruments = new HashSet<Instrument>(); while (st.hasMoreTokens()) { String nextPair = st.nextToken(); instruments.add(Instrument.fromString(nextPair)); } LOGGER.info("Subscribing instruments..."); client.setSubscribedInstruments(instruments); // setting initial deposit client.setInitialDeposit(Instrument.EURUSD.getSecondaryCurrency(), Double.parseDouble(properties.getProperty("initialdeposit", "50000.0"))); client.setCacheDirectory(new File(properties.getProperty("cachedir"))); DateTime startInterval = new DateTime(roundedEnd.minusHours(10)); client.setDataInterval(Period.TICK, null, null, startInterval.getMillis(), roundedEnd.getMillis()); // load data LOGGER.info("Downloading data"); Future<?> future = client.downloadData(null); Thread.sleep(15000); // wait for downloading to complete future.get(); reportLogger.print("Overnight report for period " + FXUtils.getFormatedTimeCET(startInterval.getMillis()) + " - " + FXUtils.getFormatedTimeCET(roundedEnd.getMillis()) + "\n"); // start the strategy LOGGER.info("Starting strategy"); client.startStrategy(new LastNightStatsCollector(properties, reportLogger), 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; } }); }
From source file:uiuc.dm.miningTools.ui.ParametersSelectionFrame.java
private List<Trajectory> getSubTrajectory(List<Trajectory> trajs, Date start, Date end) { DateTime startDateTime = new DateTime(start); startDateTime = startDateTime.minusHours(12); DateTime endDateTime = new DateTime(end); endDateTime = endDateTime.plusHours(12); List<Trajectory> subs = new ArrayList<>(); for (Trajectory traj : trajs) { Trajectory sub = new Trajectory(); sub.setId(traj.getId());/*from w w w. jav a 2 s . c om*/ for (Point p : traj.getPoints()) { // if pTime >= start and pTime <= end; if ((p.getTime().equals(startDateTime) || p.getTime().isAfter(startDateTime)) && (p.getTime().equals(endDateTime) || p.getTime().isBefore(endDateTime))) { sub.addPoint(p); } } subs.add(sub); } return subs; }