Package com.mdimension.jchronic.utils

Examples of com.mdimension.jchronic.utils.Span


    super.setUp();
    _now = Time.construct(2006, 8, 16, 14, 0, 0, 0);
  }

  public void testOffset() {
    Span span = new Span(_now, Calendar.SECOND, 60);

    Span offsetSpan;
    offsetSpan = new RepeaterMonth().getOffset(span, 1, Pointer.PointerType.FUTURE);

    assertEquals(Time.construct(2006, 9, 16, 14), offsetSpan.getBeginCalendar());
    assertEquals(Time.construct(2006, 9, 16, 14, 1), offsetSpan.getEndCalendar());

    offsetSpan = new RepeaterMonth().getOffset(span, 1, Pointer.PointerType.PAST);

    assertEquals(Time.construct(2006, 7, 16, 14), offsetSpan.getBeginCalendar());
    assertEquals(Time.construct(2006, 7, 16, 14, 1), offsetSpan.getEndCalendar());
  }
View Full Code Here


    else {
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      _currentYearStart.add(Calendar.YEAR, direction);
    }

    return new Span(_currentYearStart, Calendar.YEAR, 1);
  }
View Full Code Here

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

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

  public void testNext() {
    RepeaterMonthName mays = new RepeaterMonthName(RepeaterMonthName.MonthName.MAY);
    mays.setStart(_now);
   
    Span nextMay = mays.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2007, 5), nextMay.getBeginCalendar());
    assertEquals(Time.construct(2007, 6), nextMay.getEndCalendar());

    Span nextNextMay = mays.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2008, 5), nextNextMay.getBeginCalendar());
    assertEquals(Time.construct(2008, 6), nextNextMay.getEndCalendar());

    RepeaterMonthName decembers = new RepeaterMonthName(RepeaterMonthName.MonthName.DECEMBER);
    decembers.setStart(_now);
   
    Span nextDecember = decembers.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2006, 12), nextDecember.getBeginCalendar());
    assertEquals(Time.construct(2007, 1), nextDecember.getEndCalendar());

    mays = new RepeaterMonthName(RepeaterMonthName.MonthName.MAY);
    mays.setStart(_now);
   
    assertEquals(Time.construct(2006, 5), mays.nextSpan(Pointer.PointerType.PAST).getBeginCalendar());
View Full Code Here

  protected Span _nextSpan(PointerType pointer) {
    if (_currentWeekStart == null) {
      if (pointer == PointerType.FUTURE) {
        RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
        sundayRepeater.setStart((Calendar) getNow().clone());
        Span nextSundaySpan = sundayRepeater.nextSpan(Pointer.PointerType.FUTURE);
        _currentWeekStart = nextSundaySpan.getBeginCalendar();
      }
      else if (pointer == PointerType.PAST) {
        RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
        sundayRepeater.setStart(Time.cloneAndAdd(getNow(), Calendar.DAY_OF_MONTH, 1));
        sundayRepeater.nextSpan(Pointer.PointerType.PAST);
        Span lastSundaySpan = sundayRepeater.nextSpan(Pointer.PointerType.PAST);
        _currentWeekStart = lastSundaySpan.getBeginCalendar();
      }
      else {
        throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
      }
    }
    else {
      int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
      _currentWeekStart.add(Calendar.DAY_OF_MONTH, RepeaterWeek.WEEK_DAYS * direction);
    }

    return new Span(_currentWeekStart, Calendar.DAY_OF_MONTH, RepeaterWeek.WEEK_DAYS);
  }
View Full Code Here

  public void testThis() {
    RepeaterMonthName octobers = new RepeaterMonthName(RepeaterMonthName.MonthName.MAY);
    octobers.setStart(_now);
   
    Span nextMay = octobers.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2007, 5), nextMay.getBeginCalendar());
    assertEquals(Time.construct(2007, 6), nextMay.getEndCalendar());

    Span nextNextMay = octobers.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2008, 5), nextNextMay.getBeginCalendar());
    assertEquals(Time.construct(2008, 6), nextNextMay.getEndCalendar());
  }
View Full Code Here

    return new Span(_currentWeekStart, Calendar.DAY_OF_MONTH, RepeaterWeek.WEEK_DAYS);
  }

  @Override
  protected Span _thisSpan(PointerType pointer) {
    Span thisWeekSpan;
    Calendar thisWeekStart;
    Calendar thisWeekEnd;
    if (pointer == PointerType.FUTURE) {
      thisWeekStart = Time.cloneAndAdd(Time.ymdh(getNow()), Calendar.HOUR, 1);
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart((Calendar) getNow().clone());
      Span thisSundaySpan = sundayRepeater.thisSpan(Pointer.PointerType.FUTURE);
      thisWeekEnd = thisSundaySpan.getBeginCalendar();
      thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
    }
    else if (pointer == PointerType.PAST) {
      thisWeekEnd = Time.ymdh(getNow());
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart((Calendar) getNow().clone());
      Span lastSundaySpan = sundayRepeater.nextSpan(Pointer.PointerType.PAST);
      thisWeekStart = lastSundaySpan.getBeginCalendar();
      thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
    }
    else if (pointer == PointerType.NONE) {
      RepeaterDayName sundayRepeater = new RepeaterDayName(RepeaterDayName.DayName.SUNDAY);
      sundayRepeater.setStart((Calendar) getNow().clone());
      Span lastSundaySpan = sundayRepeater.nextSpan(Pointer.PointerType.PAST);
      thisWeekStart = lastSundaySpan.getBeginCalendar();
      thisWeekEnd = Time.cloneAndAdd(thisWeekStart, Calendar.DAY_OF_MONTH, RepeaterWeek.WEEK_DAYS);
      thisWeekSpan = new Span(thisWeekStart, thisWeekEnd);
    }
    else {
      throw new IllegalArgumentException("Unable to handle pointer " + pointer + ".");
    }
    return thisWeekSpan;
View Full Code Here

    repeater = RepeaterDayName.scan(token);
    assertEquals(RepeaterDayName.DayName.SUNDAY, repeater.getType());
  }

  public void testNextFuture() {
    Span span;
   
    RepeaterDayName mondays = new RepeaterDayName(RepeaterDayName.DayName.MONDAY);
    mondays.setStart(_now);
    span = mondays.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2006, 8, 21), span.getBeginCalendar());
    assertEquals(Time.construct(2006, 8, 22), span.getEndCalendar());

    span = mondays.nextSpan(Pointer.PointerType.FUTURE);
    assertEquals(Time.construct(2006, 8, 28), span.getBeginCalendar());
    assertEquals(Time.construct(2006, 8, 29), span.getEndCalendar());
  }
View Full Code Here

    assertEquals(Time.construct(2006, 8, 28), span.getBeginCalendar());
    assertEquals(Time.construct(2006, 8, 29), span.getEndCalendar());
  }

  public void testNextPast() {
    Span span;
   
    RepeaterDayName mondays = new RepeaterDayName(RepeaterDayName.DayName.MONDAY);
    mondays.setStart(_now);
    span = mondays.nextSpan(Pointer.PointerType.PAST);
    assertEquals(Time.construct(2006, 8, 14), span.getBeginCalendar());
    assertEquals(Time.construct(2006, 8, 15), span.getEndCalendar());

    span = mondays.nextSpan(Pointer.PointerType.PAST);
    assertEquals(Time.construct(2006, 8, 7), span.getBeginCalendar());
    assertEquals(Time.construct(2006, 8, 8), span.getEndCalendar());
  }
View Full Code Here

TOP

Related Classes of com.mdimension.jchronic.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.