@Test public void testDistance() throws Throwable { Entity sprint = new Entity("release-cycle", 1); Assert.assertEquals(Long.MAX_VALUE, SprintService.distance(new Date().getTime(), sprint)); sprint.setProperty("start-date", "2013-05-02"); sprint.setProperty("end-date", "2013-05-09"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Assert.assertEquals(1000, SprintService.distance(format.parse("2013-05-01 23:59:59").getTime(), sprint)); Assert.assertEquals(1000, SprintService.distance(format.parse("2013-05-10 00:00:01").getTime(), sprint)); Assert.assertEquals(0, SprintService.distance(format.parse("2013-05-07 13:12:11").getTime(), sprint)); }
public static long distance(long now, Entity entity) { try { Date startDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("start-date")); if(now < startDate.getTime()) { return startDate.getTime() - now; } Date endDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("end-date")); Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); calendar.add(Calendar.DATE, 1); endDate = calendar.getTime(); if(now > endDate.getTime()) { return now - endDate.getTime(); } return 0; } catch(Exception e) { return Long.MAX_VALUE; } }
SprintService implements PersistentStateComponent<Element>, ServerTypeListener, CachingEntityListener { public static long distance(long now, Entity entity) { try { Date startDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("start-date")); if(now < startDate.getTime()) { return startDate.getTime() - now; } Date endDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("end-date")); Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); calendar.add(Calendar.DATE, 1); endDate = calendar.getTime(); if(now > endDate.getTime()) { return now - endDate.getTime(); } return 0; } catch(Exception e) { return Long.MAX_VALUE; } } }
SprintService implements PersistentStateComponent<Element>, ServerTypeListener, CachingEntityListener { public static long distance(long now, Entity entity) { try { Date startDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("start-date")); if(now < startDate.getTime()) { return startDate.getTime() - now; } Date endDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("end-date")); Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); calendar.add(Calendar.DATE, 1); endDate = calendar.getTime(); if(now > endDate.getTime()) { return now - endDate.getTime(); } return 0; } catch(Exception e) { return Long.MAX_VALUE; } } SprintService(Project project); }
SprintService implements PersistentStateComponent<Element>, ServerTypeListener, CachingEntityListener { public static long distance(long now, Entity entity) { try { Date startDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("start-date")); if(now < startDate.getTime()) { return startDate.getTime() - now; } Date endDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("end-date")); Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); calendar.add(Calendar.DATE, 1); endDate = calendar.getTime(); if(now > endDate.getTime()) { return now - endDate.getTime(); } return 0; } catch(Exception e) { return Long.MAX_VALUE; } } SprintService(Project project); Element getState(); void loadState(Element state); @Override void connectedTo(ServerType serverType); synchronized Entity getRelease(); synchronized Entity getSprint(); synchronized Entity getTeam(); void addListener(Listener listener); void removeListener(Listener listener); synchronized void selectRelease(final Entity release); synchronized void selectSprint(Entity sprint); synchronized void selectTeam(Entity team); synchronized Entity getCurrentSprint(); synchronized EntityList getTeams(); EntityList getSprints(); EntityList getReleases(); static boolean isSameTense(Entity sprint1, Entity sprint2); static boolean isCurrentSprint(Entity sprint); static long distance(long now, Entity entity); @Override Entity lookup(final EntityRef ref); @Override void entityLoaded(Entity entity, Event event); @Override void entityNotFound(EntityRef ref, boolean removed); }
SprintService implements PersistentStateComponent<Element>, ServerTypeListener, CachingEntityListener { public static long distance(long now, Entity entity) { try { Date startDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("start-date")); if(now < startDate.getTime()) { return startDate.getTime() - now; } Date endDate = ALM_DATE_FORMAT.parse(entity.getPropertyValue("end-date")); Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); calendar.add(Calendar.DATE, 1); endDate = calendar.getTime(); if(now > endDate.getTime()) { return now - endDate.getTime(); } return 0; } catch(Exception e) { return Long.MAX_VALUE; } } SprintService(Project project); Element getState(); void loadState(Element state); @Override void connectedTo(ServerType serverType); synchronized Entity getRelease(); synchronized Entity getSprint(); synchronized Entity getTeam(); void addListener(Listener listener); void removeListener(Listener listener); synchronized void selectRelease(final Entity release); synchronized void selectSprint(Entity sprint); synchronized void selectTeam(Entity team); synchronized Entity getCurrentSprint(); synchronized EntityList getTeams(); EntityList getSprints(); EntityList getReleases(); static boolean isSameTense(Entity sprint1, Entity sprint2); static boolean isCurrentSprint(Entity sprint); static long distance(long now, Entity entity); @Override Entity lookup(final EntityRef ref); @Override void entityLoaded(Entity entity, Event event); @Override void entityNotFound(EntityRef ref, boolean removed);  }