List of usage examples for org.joda.time Interval toDurationMillis
public long toDurationMillis()
From source file:com.peertopark.java.dates.Dates.java
License:Apache License
public static long getDateInterval(long fromDate, long untilDate) { Interval interval = Intervals.getInterval(fromDate, untilDate); return interval.toDurationMillis(); }
From source file:com.peertopark.java.dates.Intervals.java
License:Apache License
public static Collection<Interval> split(Interval interval, Duration duration) { ArrayList<Interval> intervals = new ArrayList<Interval>(); long startMillis = interval.getStartMillis(); long endMillis = interval.getEndMillis(); long chunks = interval.toDurationMillis() / duration.getMillis(); for (int i = 0; i < chunks; i++) { long temporalEndMillis = startMillis + duration.getMillis(); intervals.add(getInterval(startMillis, temporalEndMillis)); startMillis = temporalEndMillis; }// ww w.ja va2 s. c o m if (startMillis < endMillis) { intervals.add(getInterval(startMillis, endMillis)); } return intervals; }
From source file:com.pokescanner.objects.Pokemons.java
License:Open Source License
public MarkerOptions getMarker(Context context, int scale) { String uri = "p" + getNumber(); int resourceID = context.getResources().getIdentifier(uri, "drawable", context.getPackageName()); Interval interval; //Find our interval interval = new Interval(new Instant(), getDate()); //turn our interval into MM:SS DateTime dt = new DateTime(interval.toDurationMillis()); DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss"); String timeOut = fmt.print(dt); //set our location LatLng position = new LatLng(getLatitude(), getLongitude()); Bitmap out = DrawableUtils.writeTextOnDrawable(resourceID, timeOut, scale, context); String name = getName();/*from w w w. j a v a 2 s .c o m*/ name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); MarkerOptions pokeIcon = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(out)) .position(position).title(name).snippet(timeOut); return pokeIcon; }
From source file:com.stagecents.hxt.domain.DetailHours.java
License:Open Source License
public void update(Interval timeWorked) { this.timeWorked = timeWorked; hours = timeWorked.toDurationMillis() / 1000 / 60 / 60; }
From source file:com.stagecents.pay.domain.InputValue.java
License:Open Source License
public float computeOverlappingHours(Interval arg) { Interval period = effectiveDateRange.getOverlap(arg); return period.toDurationMillis() / 1000 / 60 / 60; }
From source file:com.tkmtwo.timex.DateTimes.java
License:Apache License
/** * Calculate split DateTimes over an Interval. * <p>// www . ja va 2 s .c o m * * This method will start at the beginning of the Interval and * add the specified number of milliseconds for each split. Splits will * continue to be calculated until the end of the Interval is reached * or overshot. * <p> * * A DateTimeDirection will either start at the beginning of the * Interval and work forward, or start at the end and work backward. * <p> * * The end of the Interval may or may not be included in the splits. This * depends on whether duraMillis divides into interval.getMillis() * evenly or not. For example: * <p> * * *<pre> * * DateTimeDirection dtDirection = DateTimeDirection.FORWARD; * Interval interval = new Interval(new DateTime(0L), * new DateTime(240010L)); * long duraLong = 60000L; * * List<DateTime> dts = DateTimes.splits(dtDirection, * interval, * duraLong); * for (int i = 0; i < dts.size(); i++) { * System.out.println(String.format("Split %d is %s which is %8dms.", * i, * dts.get(i).toString(), * dts.get(i).getMillis())); * } * *</pre> * * Will print: * <p> * * <pre> * * Split 0 is 1970-01-01T00:00:00.000Z which is 0ms. * Split 1 is 1970-01-01T00:01:00.000Z which is 60000ms. * Split 2 is 1970-01-01T00:02:00.000Z which is 120000ms. * Split 3 is 1970-01-01T00:03:00.000Z which is 180000ms. * Split 4 is 1970-01-01T00:04:00.000Z which is 240000ms. * * </pre> * * Even though the end of the Interval is 240010L. Splits are calculated * based on the whole increments of duraMillis which will fit in * the Interval. If the direction is reversed with * DateTimeDirection.REVERSE: * <p> * * <pre> * * Split 0 is 1970-01-01T00:04:00.010Z which is 240010ms. * Split 1 is 1970-01-01T00:03:00.010Z which is 180010ms. * Split 2 is 1970-01-01T00:02:00.010Z which is 120010ms. * Split 3 is 1970-01-01T00:01:00.010Z which is 60010ms. * Split 4 is 1970-01-01T00:00:00.010Z which is 10ms. * * </pre> * * Is printed. * * * @param dtDirection a DateTimeDirection value * @param interval an Interval value * @param duraMillis a long value specifying the duration between splits * @return a List<DateTime> value */ public static List<DateTime> splits(DateTimeDirection dtDirection, Interval interval, long duraMillis) { checkNotNull(dtDirection, "Need a direction."); checkNotNull(interval, "Need an interval."); checkArgument(duraMillis != 0L, "DuraMillis can not be zero."); checkArgument(interval.toDurationMillis() > duraMillis, "Interval must be greater than the DuraMillis."); List<DateTime> dts = new ArrayList<DateTime>(); for (DateTime dt = dtDirection.getStart(checkNotNull(interval)); dtDirection.lteq(dt, dtDirection.getEnd(interval)); dt = dtDirection.plus(dt, duraMillis)) { dts.add(dt); } /* START */ //if (!interval.getEnd().isEqual(dts.get(dts.size() - 1))) { if (!dtDirection.getEnd(interval).isEqual(dts.get(dts.size() - 1))) { dts.add(interval.getEnd()); } /* STOP */ return dts; }
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
public void addMinutesToEnd(int minutes) { MutableDateTime d = displayable.getEnd().toMutableDateTime(); d.addMinutes(minutes);/* w w w.j a va 2s.c om*/ DateTime newEnd = d.toDateTime(); try { Interval potential = new Interval(displayable.getStart(), newEnd); if (potential.toDurationMillis() < 1000) { throw new IllegalArgumentException("cant make the event that short!!"); } height = Math.max(45, height + minutes); displayable.setEnd(newEnd); height = Math.max(45, height + minutes); length = potential; reval(); } catch (IllegalArgumentException e) { // if the date time interval is malformed (the user dragged to a bad spot) } }
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
public void addMinutesToStart(int minutes) { MutableDateTime d = displayable.getStart().toMutableDateTime(); d.addMinutes(minutes);//from w w w. j a v a 2 s . c om DateTime newStart = d.toDateTime(); try { Interval potential = new Interval(newStart, displayable.getEnd()); if (potential.toDurationMillis() < 1000) { throw new IllegalArgumentException("cant make the event that short!!"); } height = Math.max(45, height + minutes); displayable.setStart(newStart); height += minutes; length = potential; reval(); } catch (IllegalArgumentException e) { // if the date time interval is malformed (the user dragged to a bad spot) } }
From source file:com.yahoo.bard.webservice.util.SimplifiedIntervalList.java
License:Apache License
/** * Given a sorted linked list of intervals, add the following interval to the end, merging the incoming interval * to any tail intervals which overlap or abut with it. * <p>//from w ww . j av a 2 s .co m * In the case where added intervals are at the end of the list, this is efficient. In the case where they are not, * this degrades to an insertion sort. * * @param interval The interval to be merged and added to this list */ private void appendWithMerge(Interval interval) { // Do not store empty intervals if (interval.toDurationMillis() == 0) { return; } if (isEmpty()) { addLast(interval); return; } final Interval previous = peekLast(); // If this interval does not belong at the end, removeLast until it does if (interval.getStart().isBefore(previous.getStart())) { mergeInner(interval); return; } if (previous.gap(interval) != null) { addLast(interval); return; } removeLast(); Interval newEnd = new Interval(Math.min(previous.getStartMillis(), interval.getStartMillis()), Math.max(previous.getEndMillis(), interval.getEndMillis())); addLast(newEnd); }
From source file:de.kuschku.libquassel.ProtocolHandler.java
License:Open Source License
@Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(@NonNull HeartbeatReply heartbeat) { DateTime dateTime = DateTime.now().toDateTimeISO(); Interval interval = new Interval(heartbeat.dateTime, dateTime); long roundtrip = interval.toDurationMillis(); long lag = (long) (roundtrip * 0.5); client.setLatency(lag);/*from www. jav a 2 s . co m*/ }