Package org.goda.time

Examples of org.goda.time.MutableInterval


    }

    Repeater<?> head = repeaters.remove(0);
    head.setStart( new DateTime(options.getNow().getMillis()));

    MutableInterval outerMutableInterval;
    Grabber.Relative grabberType = grabber.getType();
    if (grabberType == Grabber.Relative.LAST) {
      outerMutableInterval = head.nextMutableInterval(Pointer.PointerType.PAST);
    }
    else if (grabberType == Grabber.Relative.THIS) {
      if (repeaters.size() > 0) {
        outerMutableInterval = head.thisMutableInterval(PointerType.NONE);
      }
      else {
        outerMutableInterval = head.thisMutableInterval(options.getContext());
      }
    }
    else if (grabberType == Grabber.Relative.NEXT) {
      outerMutableInterval = head.nextMutableInterval(Pointer.PointerType.FUTURE);
    }
    else {
      throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
    }

    if (options.isDebug()) {
      System.out.println("Chronic.getAnchor: outerMutableInterval = " + outerMutableInterval + "; repeaters = " + repeaters);
    }

    MutableInterval anchor = findWithin(repeaters, outerMutableInterval, pointer, options);
    return anchor;
  }
View Full Code Here


    MutableInterval anchor = findWithin(repeaters, outerMutableInterval, pointer, options);
    return anchor;
  }

  public static MutableInterval dayOrTime(DateTime dayStart, List<Token> timeTokens, Options options) {
    MutableInterval outerMutableInterval = new MutableInterval(dayStart, Time.cloneAndAdd(dayStart, Time.DAY_OF_MONTH, 1));
    if (!timeTokens.isEmpty()) {

//      /** SUPER HACK MODE FOR TIMES **/
//      Tag<?> dayPortionTag = null;
//      Tag<?> timeTag = null;
//      for (Token token : timeTokens) {
//        Tag<?> tempDayPortionTag = token.getTag(RepeaterDayPortion.class);
//        if (tempDayPortionTag != null) {
//          dayPortionTag = tempDayPortionTag;
//        }
//
//        Tag<?> tempTimeTag = token.getTag(RepeaterTime.class);
//        if (tempTimeTag != null) {
//          timeTag = tempTimeTag;
//        }
//      }
//     
//      if (timeTag != null && dayPortionTag != null) {
//        Tick tick = (Tick)timeTag.getType();
//        RepeaterDayPortion.DayPortion dayPortion = (RepeaterDayPortion.DayPortion)dayPortionTag.getType();
//        if (tick.intValue() <= (RepeaterDay.DAY_SECONDS / 2)) {
//          if (dayPortion == RepeaterDayPortion.DayPortion.PM) {
//            if (tick.intValue() == (12 * 60 * 60)) {
//              Calendar exactTime = Time.cloneAndAdd(dayStart, Calendar.SECOND, tick.intValue());
//              return new MutableInterval(exactTime, exactTime);
//            }
//            Calendar exactTime = Time.cloneAndAdd(dayStart, Calendar.SECOND, tick.intValue() + RepeaterDay.DAY_SECONDS / 2);
//            return new MutableInterval(exactTime, exactTime);
//          }
//          else if (dayPortion == RepeaterDayPortion.DayPortion.AM) {
//            if (tick.intValue() == (12 * 60 * 60)) {
//              Calendar exactTime = dayStart;
//              return new MutableInterval(exactTime, exactTime);
//            }
//            Calendar exactTime = Time.cloneAndAdd(dayStart, Calendar.SECOND, tick.intValue());
//            return new MutableInterval(exactTime, exactTime);
//          }
//        }
//      }
//      /** SUPER HACK MODE FOR TIMES **/

      options.setNow(outerMutableInterval.getStart());
      MutableInterval time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
      return time;
    }
    return outerMutableInterval;
  }
View Full Code Here

      return mutableInterval;
    }
    Repeater<?> head = tags.get(0);
    List<Repeater<?>> rest = (tags.size() > 1) ? CollectionUtils.subList(tags,1, tags.size()) : new LinkedList<Repeater<?>>();
    head.setStart((pointer == Pointer.PointerType.FUTURE) ? mutableInterval.getStart() : mutableInterval.getEnd());
    MutableInterval h = head.thisMutableInterval(PointerType.NONE);

    if (mutableInterval.contains(h.getStart()) || mutableInterval.contains(h.getEnd())) {
      return findWithin(rest, h, pointer, options);
    }
    return null;
  }
View Full Code Here

    else {
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      _currentYearStart = _currentYearStart.plusYears( direction);
    }

    return new MutableInterval(_currentYearStart, _currentYearStart.plusYears(1));
  }
View Full Code Here

      yearEnd = Time.cloneAndAdd(Time.yJan1(getNow()), Time.YEAR, 1);
    }
    else {
      throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
    }
    return new MutableInterval(yearStart, yearEnd);
  }
View Full Code Here

  @Override
  public MutableInterval getOffset(MutableInterval span, double amount, Pointer.PointerType pointer) {
    int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
    DateTime newBegin = Time.cloneAndAdd(span.getStart(), Time.YEAR, (int)(amount * direction));
    DateTime newEnd = Time.cloneAndAdd(span.getEnd(), Time.YEAR, (int)(amount * direction));
    return new MutableInterval(newBegin, newEnd);
  }
View Full Code Here

  public MutableInterval handle(List<Token> tokens, Options options) {
    int month = tokens.get(0).getTag(RepeaterMonthName.class).getType().ordinal();
    int day = ((Number)tokens.get(1).getTag(ScalarDay.class).getType()).intValue();
    int year = ((Number)tokens.get(2).getTag(ScalarYear.class).getType()).intValue();

    MutableInterval MutableInterval;
    try {
      List<Token> timeTokens = CollectionUtils.subList(tokens,3, tokens.size());
      DateTime dayStart = Time.construct(year, month, day);
      MutableInterval = Handler.dayOrTime(dayStart, timeTokens, options);
    }
View Full Code Here

    }
    else {
      throw new IllegalArgumentException("Invalid repeater: " + repeater);
    }
    */
    MutableInterval MutableInterval = Chronic.parse("this second", new Options(options.getNow(), false));
    return handle(tokens, MutableInterval, options);
  }
View Full Code Here

  protected MutableInterval _nextMutableInterval(PointerType pointer) {
    if (_currentWeekStart == null) {
      if (pointer == PointerType.FUTURE) {
        RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
        sundayRepeater.setStart( new DateTime(getNow()));
        MutableInterval nextSundayMutableInterval = sundayRepeater.nextMutableInterval(Pointer.PointerType.FUTURE);
        _currentWeekStart = nextSundayMutableInterval.getStart();
      }
      else if (pointer == PointerType.PAST) {
        RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
        sundayRepeater.setStart(Time.cloneAndAdd(getNow(), Time.DAY_OF_MONTH, 1));
        sundayRepeater.nextMutableInterval(Pointer.PointerType.PAST);
        MutableInterval lastSundayMutableInterval = sundayRepeater.nextMutableInterval(Pointer.PointerType.PAST);
        _currentWeekStart = lastSundayMutableInterval.getStart();
      }
      else {
        throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
      }
    }
    else {
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      int days =RepeaterWeek.WEEK_DAYS * direction;
      _currentWeekStart = _currentWeekStart.plusDays(days);
    }

    return new MutableInterval(_currentWeekStart, _currentWeekStart.plusDays(RepeaterWeek.WEEK_DAYS));
  }
View Full Code Here

    return new MutableInterval(_currentWeekStart, _currentWeekStart.plusDays(RepeaterWeek.WEEK_DAYS));
  }

  @Override
  protected MutableInterval _thisMutableInterval(PointerType pointer) {
    MutableInterval thisWeekMutableInterval;
    DateTime thisWeekStart;
    DateTime thisWeekEnd;
    if (pointer == PointerType.FUTURE) {
      thisWeekStart = Time.cloneAndAdd(Time.ymdh(getNow()), Time.HOUR, 1);
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart( new DateTime( getNow()));
      MutableInterval thisSundayMutableInterval = sundayRepeater.thisMutableInterval(Pointer.PointerType.FUTURE);
      thisWeekEnd = thisSundayMutableInterval.getStart();
      thisWeekMutableInterval = new MutableInterval(thisWeekStart, thisWeekEnd);
    }
    else if (pointer == PointerType.PAST) {
      thisWeekEnd = Time.ymdh(getNow());
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart( new DateTime(getNow()));
      MutableInterval lastSundayMutableInterval = sundayRepeater.nextMutableInterval(Pointer.PointerType.PAST);
      thisWeekStart = lastSundayMutableInterval.getStart();
      thisWeekMutableInterval = new MutableInterval(thisWeekStart, thisWeekEnd);
    }
    else if (pointer == PointerType.NONE) {
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart(new DateTime(getNow()));
      MutableInterval lastSundayMutableInterval = sundayRepeater.nextMutableInterval(Pointer.PointerType.PAST);
      thisWeekStart = lastSundayMutableInterval.getStart();
      thisWeekEnd = Time.cloneAndAdd(thisWeekStart, Time.DAY_OF_MONTH, RepeaterWeek.WEEK_DAYS);
      thisWeekMutableInterval = new MutableInterval(thisWeekStart, thisWeekEnd);
    }
    else {
      throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
    }
    return thisWeekMutableInterval;
View Full Code Here

TOP

Related Classes of org.goda.time.MutableInterval

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.