Package org.joda.time

Examples of org.joda.time.Interval


      if (end == null || segment.getInterval().getEnd().isAfter(end)) {
        end = segment.getInterval().getEnd();
      }
    }

    return new Interval(start, end);
  }
View Full Code Here


      final String dataSource,
      final String version,
      final List<DataSegment> segments
  )
  {
    final Interval mergedInterval = computeMergedInterval(segments);
    final Set<String> mergedDimensions = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
    final Set<String> mergedMetrics = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);

    for (DataSegment segment : segments) {
      mergedDimensions.addAll(segment.getDimensions());
View Full Code Here

    for (DataSegment segment : segments.keySet()) {
      timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(segment));
    }

    final List<SegmentToMergeHolder> segmentsToMerge = Lists.transform(
        timeline.lookup(new Interval("1000-01-01/3000-01-01")),
        new Function<TimelineObjectHolder<String, DataSegment>, SegmentToMergeHolder>()
        {
          @Override
          public SegmentToMergeHolder apply(TimelineObjectHolder<String, DataSegment> input)
          {
View Full Code Here

    seAsset.put("caption", "");
    seObject.put("asset", seAsset);

    // add aggregated events as well
    this.eventAggregations.add(se);
    Interval eventinterval = new Interval(this.simTime.getMillis(), se.getEndTime());

    long durationvalue = eventinterval.toDurationMillis();
    if(intervalUnit.equals("seconds")) {
      durationvalue = durationvalue / 1000;
    } else if(intervalUnit.equals("minutes")) {
      durationvalue = durationvalue / (1000*60);
    } else if(intervalUnit.equals("hours")) {
View Full Code Here

        })).size() > 0;
    }

    public Trade tradeAt(final DateTime date) {
        for (Trade trade : trades) {
            Interval interval = new Interval(trade.getOpen(), trade.getClose());
            if (interval.contains(date)) {
                return trade;
            }
        }

        return null;
View Full Code Here

        this.conditions = conditions;
    }

    public boolean includesDate(DateTime time) {
        if (isClosed()) {
            return new Interval(open, close).contains(time);
        } else {
            return open.compareTo(time) <= 0;
        }
    }
View Full Code Here

   * @return
   */
  public Duration calculateElapsedTime(DateTime lastCalculated, DateTime now,
      int slaWorkingHours) {
    DateMidnight dateBeingProcessed = new DateMidnight(lastCalculated);
    Interval processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    Duration duration = new Duration(null);
    while (processingInterval.contains(now)
        || processingInterval.isBefore(now)) {
      Interval workingHours = getWorkingIntervalForDate(
          dateBeingProcessed, slaWorkingHours);

      // process the day
      // if the last calculated date is within the current 24hours being
      // processed.
      if (processingInterval.contains(lastCalculated)) {
        // set start to last calc'd or start or working period if after
        // last calced
        if (workingHours.getStart().isAfter(lastCalculated)) {
          // leave start of working hours as is
        } else if (workingHours.contains(lastCalculated)) {
          workingHours = workingHours.withStart(lastCalculated);
        } else if (workingHours.getEnd().isBefore(lastCalculated)) {
          workingHours = new Interval(lastCalculated, lastCalculated); // zero
          // time
          // duration
        }
      }
      if (processingInterval.contains(now)) {
        // set end to now if now in working period
        if (workingHours.getStart().isAfter(now)) {
          workingHours = new Interval(now, now); // zero time duration
        } else if (workingHours.contains(now)) {
          workingHours = workingHours.withEnd(now);
        } else if (workingHours.getEnd().isBefore(now)) {
          // leave end of working hours as is
        }
      }
      duration = duration.plus(workingHours.toDuration());
      dateBeingProcessed = dateBeingProcessed.plusDays(1);
      processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    }
    System.out.println(duration.toPeriod());
    return duration;
View Full Code Here

   * @param start
   * @return
   */
  private Interval getEntireDayIntervalForDate(DateMidnight start) {
    final DateMidnight end = start.plusDays(1);
    Interval interval = new Interval(start, end);
    return interval;
  }
View Full Code Here

   * @param slaWorkingHours
   * @return
   */
  private Interval getWorkingIntervalForDate(DateMidnight start,
      int slaWorkingHours) {
    Interval interval;
    // sla running all the time.
    if (slaWorkingHours == SLAWorkingHours.TWENTYFOUR_SEVEN_365) {
      interval = getEntireDayIntervalForDate(start);
    }
    // sla running only in office hours
    else if (slaWorkingHours == SLAWorkingHours.OFFICE_HOURS_9_TO_5_30) {
      final int dayOfWeek = start.getDayOfWeek();
      // if sat/sun/bank hol
      if (dayOfWeek == DateTimeConstants.SATURDAY
          || dayOfWeek == DateTimeConstants.SUNDAY
          || bankHolidays.contains(start)) // bank holiday or weekend
      {
        interval = new Interval(start, start); // 0 duration interval
      }
      // else it is a working day 9-5.30 office hours
      else {
        DateTime startOfficeHours = new DateTime(start.getYear(), start
            .getMonthOfYear(), start.getDayOfMonth(), 9, 0, 0, 0);
        DateTime endOfficeHours = new DateTime(start.getYear(), start
            .getMonthOfYear(), start.getDayOfMonth(), 17, 30, 0, 0);
        interval = new Interval(startOfficeHours, endOfficeHours);
      }
    } else // unknown SLA working hours
    {
      // TODO log warning that SLA time isn't running
      interval = new Interval(start, start); // 0 duration interval
    }
    return interval;
  }
View Full Code Here

      String segmentIdentifier,
      SegmentDescriptor descriptor,
      byte[] queryCacheKey
  )
  {
    final Interval segmentQueryInterval = descriptor.getInterval();
    final byte[] versionBytes = descriptor.getVersion().getBytes(Charsets.UTF_8);

    return new Cache.NamedKey(
        segmentIdentifier, ByteBuffer
        .allocate(16 + versionBytes.length + 4 + queryCacheKey.length)
        .putLong(segmentQueryInterval.getStartMillis())
        .putLong(segmentQueryInterval.getEndMillis())
        .put(versionBytes)
        .putInt(descriptor.getPartitionNumber())
        .put(queryCacheKey).array()
    );
  }
View Full Code Here

TOP

Related Classes of org.joda.time.Interval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.