Package er.chronic.utils

Examples of er.chronic.utils.Span


    }
    return span;
  }
 
  public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
    Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, Calendar.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 Span(exactTime, exactTime);
//            }
//            Calendar exactTime = Time.cloneAndAdd(dayStart, Calendar.SECOND, tick.intValue() + RepeaterDay.DAY_SECONDS / 2);
//            return new Span(exactTime, exactTime);
//          }
//          else if (dayPortion == RepeaterDayPortion.DayPortion.AM) {
//            if (tick.intValue() == (12 * 60 * 60)) {
//              Calendar exactTime = dayStart;
//              return new Span(exactTime, exactTime);
//            }
//            Calendar exactTime = Time.cloneAndAdd(dayStart, Calendar.SECOND, tick.intValue());
//            return new Span(exactTime, exactTime);
//          }
//        }
//      }
//      /** SUPER HACK MODE FOR TIMES **/

      // DIFF: If you're generating past dates, you want to use the end of the day as the offset so "5pm" ends up on the same day as the date you chose
      if (options.getContext() == PointerType.PAST) {
        options.setNow(outerSpan.getEndCalendar());
      }
      else {
        options.setNow(outerSpan.getBeginCalendar());
      }
      Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
      return time;
    }
    return outerSpan;
  }
View Full Code Here


      return span;
    }
    Repeater<?> head = tags.get(0);
    List<Repeater<?>> rest = (tags.size() > 1) ? tags.subList(1, tags.size()) : new LinkedList<Repeater<?>>();
    head.setStart((pointer == Pointer.PointerType.FUTURE) ? span.getBeginCalendar() : span.getEndCalendar());
    Span h = head.thisSpan(PointerType.NONE);

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

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

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

  public Span handle(List<Token> tokens, Span span, Options options) {
    float distance = tokens.get(0).getTag(Scalar.class).getType().floatValue();
    Repeater<?> repeater = tokens.get(1).getTag(Repeater.class);
    Pointer.PointerType pointer = tokens.get(2).getTag(Pointer.class).getType();
    Span offsetSpan = repeater.getOffset(span, distance, pointer);
    // Addition by Oliver Kohll
    // When not guessing a point time, return a span of the correct length
    if (!options.isGuess()) {
      Calendar beginCalendar = offsetSpan.getBeginCalendar();
      int calendarField = Calendar.SECOND;
      int spanLength = 1;
      switch (repeater.getWidth()) {
      case RepeaterMinute.MINUTE_SECONDS:
        calendarField = Calendar.MINUTE;
        break;
      case RepeaterHour.HOUR_SECONDS:
        calendarField = Calendar.HOUR;
        break;
      case RepeaterDay.DAY_SECONDS: // Also = RepeaterDayName.DAY_SECONDS
        // and RepeaterWeekday.DAY_SECONDS
        calendarField = Calendar.DAY_OF_MONTH;
        break;
      case RepeaterWeekend.WEEKEND_SECONDS:
        calendarField = Calendar.DAY_OF_MONTH;
        spanLength = 2;
        break;
      case RepeaterWeek.WEEK_SECONDS:
        calendarField = Calendar.DAY_OF_MONTH;
        // WEEK_OF_YEAR doesn't seem to be supported by DateUtils.truncate
        // Round to the beginning of the week manually
        int dayOfWeek = beginCalendar.get(Calendar.DAY_OF_WEEK);
        beginCalendar.add(Calendar.DAY_OF_WEEK, -1 * (dayOfWeek - beginCalendar.getFirstDayOfWeek()));
        spanLength = 7;
        break;
      case RepeaterFortnight.FORTNIGHT_SECONDS:
        calendarField = Calendar.DAY_OF_MONTH;
        dayOfWeek = beginCalendar.get(Calendar.DAY_OF_WEEK);
        beginCalendar.add(Calendar.DAY_OF_WEEK, -1 * (dayOfWeek - beginCalendar.getFirstDayOfWeek()));
        spanLength = 14;
        break;
      case RepeaterMonth.MONTH_SECONDS:
        calendarField = Calendar.MONTH;
        break;
      case RepeaterYear.YEAR_SECONDS:
        calendarField = Calendar.YEAR;
      }
      beginCalendar = DateUtils.truncate(beginCalendar, calendarField);
      offsetSpan = new Span(beginCalendar, Time.cloneAndAdd(beginCalendar, calendarField, spanLength));
    }
    return offsetSpan;
  }
View Full Code Here

     * false)); } else if (repeater instanceof RepeaterMinute || repeater
     * instanceof RepeaterSecond) { span = chronic.parse("this second", new
     * Options(chronic.getNow(), false)); } else { throw new
     * IllegalArgumentException("Invalid repeater: " + repeater); }
     */
    Span span = Chronic.parse("this second", new Options(options.getNow(), false));
    return handle(tokens, span, options);
  }
View Full Code Here

      int increment = (tick.isAmbiguous()) ? halfDay : fullDay;
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      _currentTime.add(Calendar.SECOND, direction * increment);
    }

    return new Span(_currentTime, Time.cloneAndAdd(_currentTime, Calendar.SECOND, getWidth()));
  }
View Full Code Here

      }
    }
    else {
      _currentDayStart.add(Calendar.DAY_OF_MONTH, direction * 7);
    }
    return new Span(_currentDayStart, Calendar.DAY_OF_MONTH, 1);
  }
View Full Code Here

    if (options.isDebug()) {
      System.out.println("Chronic.parse: " + tokens);
    }

    Span span;
    if (tokens.size() == 0) {
      span = null;
    }
    else {
      span = Handler.tokensToSpan(tokens, options);
View Full Code Here

      guessValue = span.getBegin() + (span.getWidth() / 2);
    }
    else {
      guessValue = span.getBegin();
    }
    Span guess = new Span(guessValue, guessValue);
    return guess;
  }
View Full Code Here

      parsedTimestamp = new NSTimestamp(parsedDate);
    }
    catch (ParseException e) {
      // If the input doesn't match the pattern, use Chronic to parse the
      // input.
      Span span = Chronic.parse(text, options());
      if (span == null) {
        throw e;
      }
      if (span.isSingularity() || isGuessingEarly()) {
        parsedTimestamp = new NSTimestamp(span.getBeginCalendar().getTime());
      }
      else {
        parsedTimestamp = new NSTimestamp(span.getEndCalendar().getTime());
      }
    }
    return parsedTimestamp;
  }
View Full Code Here

TOP

Related Classes of er.chronic.utils.Span

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.