Package er.chronic.utils

Examples of er.chronic.utils.Span


  protected Span _nextSpan(PointerType pointer) {
    if (_currentWeekStart == null) {
      if (pointer == Pointer.PointerType.FUTURE) {
        RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
        saturdayRepeater.setStart((Calendar) getNow().clone());
        Span nextSaturdaySpan = saturdayRepeater.nextSpan(Pointer.PointerType.FUTURE);
        _currentWeekStart = nextSaturdaySpan.getBeginCalendar();
      }
      else if (pointer == Pointer.PointerType.PAST) {
        RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
        saturdayRepeater.setStart(Time.cloneAndAdd(getNow(), Calendar.SECOND, RepeaterDay.DAY_SECONDS));
        Span lastSaturdaySpan = saturdayRepeater.nextSpan(Pointer.PointerType.PAST);
        _currentWeekStart = lastSaturdaySpan.getBeginCalendar();
      }
    }
    else {
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      _currentWeekStart = Time.cloneAndAdd(_currentWeekStart, Calendar.SECOND, direction * RepeaterWeek.WEEK_SECONDS);
    }
    return new Span(_currentWeekStart, Time.cloneAndAdd(_currentWeekStart, Calendar.SECOND, RepeaterWeekend.WEEKEND_SECONDS));
  }
View Full Code Here


    return new Span(_currentWeekStart, Time.cloneAndAdd(_currentWeekStart, Calendar.SECOND, RepeaterWeekend.WEEKEND_SECONDS));
  }

  @Override
  protected Span _thisSpan(PointerType pointer) {
    Span thisSpan;
    if (pointer == Pointer.PointerType.FUTURE || pointer == Pointer.PointerType.NONE) {
      RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
      saturdayRepeater.setStart((Calendar) getNow().clone());
      Span thisSaturdaySpan = saturdayRepeater.nextSpan(Pointer.PointerType.FUTURE);
      thisSpan = new Span(thisSaturdaySpan.getBeginCalendar(), Time.cloneAndAdd(thisSaturdaySpan.getBeginCalendar(), Calendar.SECOND, RepeaterWeekend.WEEKEND_SECONDS));
    }
    else if (pointer == Pointer.PointerType.PAST) {
      RepeaterDayName saturdayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SATURDAY);
      saturdayRepeater.setStart((Calendar) getNow().clone());
      Span lastSaturdaySpan = saturdayRepeater.nextSpan(Pointer.PointerType.PAST);
      thisSpan = new Span(lastSaturdaySpan.getBeginCalendar(), Time.cloneAndAdd(lastSaturdaySpan.getBeginCalendar(), Calendar.SECOND, RepeaterWeekend.WEEKEND_SECONDS));
    }
    else {
      throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
    }
    return thisSpan;
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;
            }
            else {
                if (span.isSingularity() || isGuessingEarly()) {
                    parsedTimestamp = new NSTimestamp(span.getBeginCalendar().getTime());
                }
                else {
                    parsedTimestamp = new NSTimestamp(span.getEndCalendar().getTime());
                }
            }
        }
       
        return parsedTimestamp;
View Full Code Here

      assertEquals(Time.construct(2006, 8, 16, 0, 15), parse_now("8/16/2006 at 12:15a"));
      assertEquals(Time.construct(2006, 8, 16, 18, 30), parse_now("8/16/2006 at 6:30p"));
    }

    public void test_days_in_november() {
      Span t1 = Chronic.parse("1st thursday in november", new Options(Time.construct(2007)));
      assertEquals(Time.construct(2007, 11, 1, 12), t1);

      t1 = Chronic.parse("1st friday in november", new Options(Time.construct(2007)));
      assertEquals(Time.construct(2007, 11, 2, 12), t1);
View Full Code Here

      // t1 = Chronic.parse("1st monday in november", :now => Time.local(2007))
      // assertEquals(Time.construct(2007, 11, 5, 11), t);1
    }

    public void test_parse_this_past() {
      Span t = parse_now("this past tuesday");
      assertEquals(Time.construct(2006,8,15, 12), t);

      t = parse_now("this past day");
      assertEquals(Time.construct(2006,8,15, 12), t);
View Full Code Here

      t = parse_now("this past hour");
      assertEquals(Time.construct(2006,8,16, 13, 30), t);
    }

    public void test_parse_noon() {
      Span t = parse_now("noon");
      assertEquals(Time.construct(2006,8,16, 12), t);

      t = parse_now("tomorrow at noon");
      assertEquals(Time.construct(2006,8,17, 12), t);
    }
View Full Code Here

      t = parse_now("tomorrow at noon");
      assertEquals(Time.construct(2006,8,17, 12), t);
    }

    public void test_parse_before_now() {
      Span t = parse_now("3 hours before now");
      assertEquals(Time.construct(2006,8,16, 11), t);

      t = parse_now("3 days before now");
      assertEquals(Time.construct(2006,8,13, 14), t);
View Full Code Here

      t = parse_now("30 minutes before now");
      assertEquals(Time.construct(2006,8,16, 13,30), t);
    }

    public void test_now() {
      Span t = parse_now("now");
      assertEquals(Time.construct(2006,8,16,14), t);

      t = parse_now("1 hour from now");
      assertEquals(Time.construct(2006,8,16,15), t);
View Full Code Here

      t = parse_now("1 hour before now");
      assertEquals(Time.construct(2006,8,16,13), t);
    }

    public void test_this_last() {
      Span t = parse_now("this last day");
      assertEquals(Time.construct(2006, 8, 15, 12), t);

      t = parse_now("this last hour");
      assertEquals(Time.construct(2006, 8, 16, 13, 30), t);
    }
View Full Code Here

      t = parse_now("this last hour");
      assertEquals(Time.construct(2006, 8, 16, 13, 30), t);
    }

    public void test_hr_and_hrs() {
      Span t = parse_now("in 3 hr");
      assertEquals(Time.construct(2006, 8,16,17), t);

      t = parse_now("in 3 hrs");
      assertEquals(Time.construct(2006, 8,16,17), t);
    }
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.