List of usage examples for org.joda.time Duration getMillis
public long getMillis()
From source file:es.jpons.temporal.types.PossibilisticVTP.java
License:Open Source License
public PossibilisticVTP(Integer day, Integer month, Integer year, Integer leftDays, Integer rightDays, OpenInterval side) {/* w ww . j ava2s .com*/ DateTime dateMainPoint, dateLeft, dateRight; dateMainPoint = new DateTime(year, month, day, 0, 0); dateLeft = dateMainPoint.minusDays(leftDays); dateRight = dateMainPoint.plusDays(rightDays); Duration d = new Duration(dateLeft, dateMainPoint); Duration d1 = new Duration(dateMainPoint, dateRight); switch (side) { case UC: this.startMP = dateMainPoint.getMillis(); this.startLeft = d.getMillis(); this.startRight = d1.getMillis(); this.startDate = dateMainPoint.toDate(); this.side = OpenInterval.UC; break; case FB: this.endMP = dateMainPoint.getMillis(); this.endLeft = d.getMillis(); this.endRight = d1.getMillis(); this.endDate = dateMainPoint.toDate(); this.side = OpenInterval.FB; break; } }
From source file:es.ugr.decsai.jpons.testapplication.Main.java
License:Open Source License
protected static PossibilisticVTP createVTP(Integer sday, Integer smonth, Integer syear, Integer eday, Integer emonth, Integer eyear) { DateTime dateStartingMainPoint, dateStartingLeft, dateStartingRight; DateTime dateEndingMainPoint, dateEndingLeft, dateEndingRight; dateStartingMainPoint = new DateTime(syear, smonth, sday, 0, 0); dateStartingLeft = dateStartingMainPoint.minusDays(3); dateStartingRight = dateStartingMainPoint.plusDays(3); Duration d = new Duration(dateStartingLeft, dateStartingMainPoint); Duration d1 = new Duration(dateStartingMainPoint, dateStartingRight); dateEndingMainPoint = new DateTime(eyear, emonth, eday, 0, 0); dateEndingLeft = dateEndingMainPoint.minusDays(3); dateEndingRight = dateEndingMainPoint.plusDays(3); Duration d2 = new Duration(dateEndingLeft, dateEndingMainPoint); Duration d3 = new Duration(dateEndingMainPoint, dateEndingRight); PossibilisticTP start, end;//from w w w .j av a2 s . c o m PossibilisticVTP pvp; // start = new PossibilisticTP( // dateStartingMainPoint.toDate(), // dateStartingLeft.toDate(), // dateStartingRight.toDate()); // end = new PossibilisticTP( // dateEndingMainPoint.toDate(), // dateEndingLeft.toDate(), // dateEndingRight.toDate()); pvp = new PossibilisticVTP(dateStartingMainPoint.toDate(), d.getMillis(), d1.getMillis(), dateEndingMainPoint.toDate(), d2.getMillis(), d3.getMillis()); return pvp; }
From source file:es.ugr.decsai.jpons.testapplication.Main.java
License:Open Source License
public static void main(String[] args) { Main pp = new Main(); log.trace("Initializing hibernate session"); try {//from w ww . ja v a 2s . c om Properties prop = new Properties(); prop.load(pp.getClass().getResourceAsStream("hibernate.properties")); List<Class> annotatedClasses = new ArrayList<Class>(); annotatedClasses.add(Employee.class); // annotatedClasses.add(TemporalPK.class); // annotatedClasses.add(PossibilisticTP.class); // annotatedClasses.add(PossibilisticVTP.class); // Session session = TemporalHibernateUtil.getSession(prop, annotatedClasses); // }catch(Exception ex){ // log.error(ex); // } // EntityManagerFactory emf = Persistence.createEntityManagerFactory("TemporalPU"); // EntityManager em = emf.createEntityManager(); // // // TemporalWebEntityManager manager = pp.configure(); // TemporalEntityManagerInterface entityManager = TemporalWebEntityManager.getEntityManager(); // TemporalPersistenceManager manager = TemporalPersistenceManager.getInstance(prop, annotatedClasses); // try { //// TemporalEntityManager manager = TemporalEntityManagerFactory.getInstance().createTemporalEntityManager(); // } catch (NamingException ex) { // log.error(ex); // } DateTime dateStartingMainPoint, dateStartingLeft, dateStartingRight; DateTime dateEndingMainPoint, dateEndingLeft, dateEndingRight; dateStartingMainPoint = new DateTime(2012, 3, 15, 0, 0); dateStartingLeft = new DateTime(2012, 3, 1, 0, 0); dateStartingRight = new DateTime(2012, 3, 21, 0, 0); Duration d = new Duration(dateStartingLeft, dateStartingMainPoint); Duration d1 = new Duration(dateStartingMainPoint, dateStartingRight); dateEndingMainPoint = new DateTime(2012, 3, 30, 0, 0); dateEndingLeft = new DateTime(2012, 3, 27, 0, 0); dateEndingRight = new DateTime(2012, 4, 3, 0, 0); Duration d2 = new Duration(dateEndingLeft, dateEndingMainPoint); Duration d3 = new Duration(dateEndingMainPoint, dateEndingRight); PossibilisticTP start, end; PossibilisticVTP pvp; start = new PossibilisticTP(dateStartingMainPoint.toDate(), dateStartingLeft.toDate(), dateStartingRight.toDate()); end = new PossibilisticTP(dateEndingMainPoint.toDate(), dateEndingLeft.toDate(), dateEndingRight.toDate()); pvp = new PossibilisticVTP(dateStartingMainPoint.toDate(), d.getMillis(), d1.getMillis(), dateEndingMainPoint.toDate(), d2.getMillis(), d3.getMillis()); //new date to compare to DateTime dateStartingMainPoint1, dateStartingLeft1, dateStartingRight1; DateTime dateEndingMainPoint1, dateEndingLeft1, dateEndingRight1; dateStartingMainPoint1 = new DateTime(2011, 3, 1, 0, 0); dateStartingLeft1 = new DateTime(2011, 3, 1, 0, 0); dateStartingRight1 = new DateTime(2011, 3, 21, 0, 0); Duration d4 = new Duration(dateStartingLeft1, dateStartingMainPoint1); Duration d5 = new Duration(dateStartingMainPoint1, dateStartingRight1); dateEndingMainPoint1 = new DateTime(2011, 3, 27, 0, 0); dateEndingLeft1 = new DateTime(2011, 3, 27, 0, 0); dateEndingRight1 = new DateTime(2011, 4, 3, 0, 0); Duration d6 = new Duration(dateEndingLeft1, dateEndingMainPoint1); Duration d7 = new Duration(dateEndingMainPoint1, dateEndingRight1); PossibilisticTP start1, end1; PossibilisticVTP pvp1; start1 = new PossibilisticTP(dateStartingMainPoint1.toDate(), dateStartingLeft1.toDate(), dateStartingRight1.toDate()); end1 = new PossibilisticTP(dateEndingMainPoint1.toDate(), dateEndingLeft1.toDate(), dateEndingRight1.toDate()); pvp1 = new PossibilisticVTP(dateStartingMainPoint1.toDate(), d4.getMillis(), d5.getMillis(), dateEndingMainPoint1.toDate(), d6.getMillis(), d7.getMillis()); PossibilisticVTP pvp2, pvp3, pvp4; pvp2 = createVTP(10, 3, 2012, 30, 4, 2012); pvp3 = createVTP(1, 5, 2012, 27, 5, 2012); pvp4 = createVTP(30, 3, 2012, 25, 4, 2012); // overlapsTM(pvp1, pvp); // overlapsTM(pvp, pvp1); // // overlapsTM(pvp, pvp2); // overlapsTM(pvp, pvp3); // overlapsTM(pvp, pvp4); // System.out.println("These two do overlap"); // overlapsTM(pvp2, pvp4); //ejemplo pvp4.setSide(OpenInterval.UC); pvp4.setEndLeft(null); pvp4.setEndMP(null); pvp4.setEndRight(null); // try{ // manager.closeR(pvp4, pvp); // an error // }catch(Exception e){ // log.error(e); // } // PossibilisticVTP closed = manager.closeR(pvp4, pvp3); // System.out.println(" Closed interval: " + closed); // Employee e1 = new Employee(new TemporalPK(23, 1), "emp3"); pvp.setSide(OpenInterval.UC); e1.setPvp(pvp2); Employee e2 = new Employee(new TemporalPK(2, 2), "emp4"); e2.setPvp(pvp4); Employee e3 = new Employee(new TemporalPK(2, 3), "emp4"); e3.setPvp(pvp3); // Employee e1 = new Employee(22, null, "emp2"); // try { // Transaction t =.beginTransaction(); Transaction beginTransaction = manager.beginTransaction(); // beginTransaction.begin(); manager.save(e1); manager.save(e2); manager.save(e3); // manager.update(e3); beginTransaction.commit(); TemporalQuery tq = manager.createTemporalQuery(e3); tq.setAllenRelation(AllenRelation.before, pvp3); List<QueryResult> list = tq.getList(); for (QueryResult qr : list) { System.out .println("aggregation: " + qr.getAggregation() + " temporal " + qr.getTemporalSatisfaction() + " endmp: " + qr.getVtp().getEndMP() + " vid: " + qr.getKey()); } PossibilisticVTP pvpafter = createVTP(28, 4, 2012, 30, 4, 2013); TemporalQuery tq1 = manager.createTemporalQuery(e3); tq1.setAllenRelation(AllenRelation.meets, pvpafter); List<QueryResult> list1 = tq1.getList(); for (QueryResult qr : list1) { System.out .println("aggregation: " + qr.getAggregation() + " temporal " + qr.getTemporalSatisfaction() + " endmp: " + qr.getVtp().getEndMP() + " vid: " + qr.getKey()); } //test for the cartesian product: tq1.createTemporalQuery(e1); System.out.println("---- CARTESIAN PRODUCT ----"); List<QueryResult> list2 = tq1.cartesianProduct(); for (QueryResult qr : list2) { System.out .println("aggregation: " + qr.getAggregation() + " temporal " + qr.getTemporalSatisfaction() + " endmp: " + qr.getVtp().getEndMP() + " vid: " + qr.getKeys()); } // String tableName = e3.getClass().getSimpleName(); // TemporalPersistenceManager.getSession().createQuery("Delete from "+ tableName + " where tid.id = :idval" ).setParameter("idval", e3.getTid().getId()).executeUpdate(); //// //query: // Session s = TemporalPersistenceManager.getSession(); // Date startdate = new DateTime(2012, 3, 10, 0, 0).toDate(); // Date enddate = new DateTime(2012,3,21,1,0,0).toDate(); // List list = s.createQuery("from Employee e Where (:startdate < e.pvp.startMP ) and ((:enddate > e.pvp.startMP and :enddate < e.pvp.endMP ) or (:enddate > e.pvp.endMP)) "). // setParameter("startdate", startdate). // setParameter("enddate", enddate). // list(); // // if(list!=null){ // for(int i=0;i<list.size();i++){ // Employee e = (Employee) list.get(i); // System.out.println("Time: " + e.getPvp().getStartMP() + " , "+e.getPvp().getEndMP()); // } // } // // beginTransaction.commit(); manager.close(); // t.commit(); // em.getTransaction().begin(); //// // em.persist(e1); //// // em.getTransaction().commit(); // // session.close(); } catch (Throwable t) { log.error(t); } }
From source file:eu.vranckaert.worktime.service.impl.TimeRegistrationServiceImpl.java
License:Apache License
/** * {@inheritDoc}/*from ww w. ja va 2 s .c o m*/ */ public TimeRegistration create(Date startTime, Task task) { TimeRegistration timeRegistration = new TimeRegistration(); timeRegistration.setTask(task); timeRegistration.setStartTime(startTime); /* * Issue 61 * If the start time of registration, and the end time of the previous registration, have a difference * off less than 60 seconds, we start the time registration at the same time the previous one is ended. * This is to prevent gaps in the time registrations that should be modified manual. This is default * configured to happen (defined in the preferences). */ if (Preferences.getTimeRegistrationsAutoClose60sGap(ctx)) { Log.d(LOG_TAG, "Check for gap between this new time registration and the previous one"); TimeRegistration previousTimeRegistration = getPreviousTimeRegistration(timeRegistration); if (previousTimeRegistration != null) { Log.d(LOG_TAG, "The previous time registrations ended on " + previousTimeRegistration.getEndTime()); Log.d(LOG_TAG, "The new time registration starts on " + timeRegistration.getStartTime()); Duration duration = DateUtils.TimeCalculator.calculateExactDuration(ctx, timeRegistration.getStartTime(), previousTimeRegistration.getEndTime()); Log.d(LOG_TAG, "The duration between the previous end time and the new start time is " + duration); long durationMillis = duration.getMillis(); Log.d(LOG_TAG, "The duration in milliseconds is " + durationMillis); if (durationMillis < 60000) { Log.d(LOG_TAG, "Gap is less than 60 seconds, setting start time to end time of previous registration"); timeRegistration.setStartTime(previousTimeRegistration.getEndTime()); } } } timeRegistration = dao.save(timeRegistration); return timeRegistration; }
From source file:fr.amap.commons.animation.Timeline.java
/** * Get the nearest index in the timeline from the DateTime. * @param timePosition//w w w. j av a2 s .co m * @return */ private int getNearestIndex(DateTime timePosition) { //get array index from timePosition Duration durationFromStart = new Duration(startTime, timePosition); long millisDuration = durationFromStart.getMillis(); int index = (int) Math.round((millisDuration / 1000.0 / 3600.0) / timeStep); if (index >= nbSteps) { index = nbSteps - 1; } else if (index < 0/* || index >= nbSteps*/) { index = 0; } return index; }
From source file:google.registry.dns.DnsQueue.java
License:Open Source License
/** Returns handles for a batch of tasks, leased for the specified duration. */ public List<TaskHandle> leaseTasks(Duration leaseDuration) { try {/*ww w .ja v a 2s .c o m*/ return queue.leaseTasks(leaseDuration.getMillis(), MILLISECONDS, writeBatchSize); } catch (TransientFailureException | DeadlineExceededException e) { logger.severe(e, "Failed leasing tasks too fast"); return ImmutableList.of(); } }
From source file:google.registry.dns.writer.dnsupdate.DnsMessageTransport.java
License:Open Source License
/** * Class constructor./*from ww w.j a v a 2s.c o m*/ * * @param factory a factory for TCP sockets * @param updateHost host name of the DNS server * @param updateTimeout update I/O timeout */ @Inject public DnsMessageTransport(SocketFactory factory, @Config("dnsUpdateHost") String updateHost, @Config("dnsUpdateTimeout") Duration updateTimeout) { this.factory = factory; this.updateHost = updateHost; this.updateTimeout = Ints.checkedCast(updateTimeout.getMillis()); }
From source file:google.registry.model.CacheUtils.java
License:Open Source License
/** * Memoize a supplier, with a short expiration specified in the environment config. * * <p>Use this for things that might change while code is running. (For example, the various * lists downloaded from the TMCH get updated in datastore and the caches need to be refreshed.) *//*from ww w .jav a 2 s . co m*/ public static <T> Supplier<T> memoizeWithShortExpiration(Supplier<T> original) { Duration expiration = getSingletonCacheRefreshDuration(); return expiration.isEqual(ZERO) ? original : memoizeWithExpiration(original, expiration.getMillis(), MILLISECONDS); }
From source file:google.registry.util.CacheUtils.java
License:Open Source License
/** Memoize a supplier, with a given expiration. */ private static <T> Supplier<T> memoizeForDuration(Supplier<T> original, Duration expiration) { return expiration.isEqual(ZERO) ? original // memoizeWithExpiration won't accept 0 as a refresh duration. : memoizeWithExpiration(original, expiration.getMillis(), MILLISECONDS); }
From source file:io.coala.dsol.util.DsolUtil.java
License:Apache License
/** @return the specified duration in the replication's time unit */ public static double simTime(final Duration duration, final Treatment treatment) { return toTimeUnit(treatment.getTimeUnit(), duration.getMillis(), TimeUnitInterface.MILLISECOND) .doubleValue();// w w w. j ava 2s .com }