org.jfree.data.time.Week Java Examples

The following examples show how to use org.jfree.data.time.Week. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimeSeriesCollectorFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #2
Source File: ChartConstants.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #3
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Week w = new Week(52, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(1009756799999L, w.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        w.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #4
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Week w = new Week(52, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(1009756799999L, w.getLastMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        w.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #5
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithTimeZone() {
    Week w = new Week(2, 1950);
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.US);
    try {
        TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
        Calendar c = new GregorianCalendar(zone);
        assertEquals(-629913600001L, w.getLastMillisecond(c));
    }
    finally {
        Locale.setDefault(saved);
    }

    // try null calendar
    boolean pass = false;
    try {
        w.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #6
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Week w = new Week(1, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, w.getFirstMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        w.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #7
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test case for bug 1498805.
 */
public void testBug1498805() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    try {
        TimeZone zone = TimeZone.getTimeZone("GMT");
        GregorianCalendar gc = new GregorianCalendar(zone);
        gc.set(2005, Calendar.JANUARY, 1, 12, 0, 0);
        Week w = new Week(gc.getTime(), zone, Locale.getDefault());
        assertEquals(53, w.getWeek());
        assertEquals(new Year(2004), w.getYear());
    }
    finally {
        Locale.setDefault(saved);
    }
}
 
Example #8
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Week w = new Week(1, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, w.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        w.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #9
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithTimeZone() {
    Week w = new Week(47, 1950);
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.US);
    try {
        TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
        Calendar c = new GregorianCalendar(zone);
        assertEquals(-603302400000L, w.getFirstMillisecond(c));
    }
    finally {
        Locale.setDefault(saved);
    }

    // try null calendar
    boolean pass = false;
    try {
        w.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #10
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Common test setup.
 */
protected void setUp() {
    this.w1Y1900 = new Week(1, 1900);
    this.w2Y1900 = new Week(2, 1900);
    this.w51Y9999 = new Week(51, 9999);
    this.w52Y9999 = new Week(52, 9999);
}
 
Example #11
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getEnd() method.
 */
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 8, 23, 59, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Week w = new Week(1, 2006);
    assertEquals(cal.getTime(), w.getEnd());
    Locale.setDefault(saved);
}
 
Example #12
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Common test setup.
 */
protected void setUp() {
    this.w1Y1900 = new Week(1, 1900);
    this.w2Y1900 = new Week(2, 1900);
    this.w51Y9999 = new Week(51, 9999);
    this.w52Y9999 = new Week(52, 9999);
}
 
Example #13
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    Week w1 = new Week(2, 2003);
    Week w2 = new Week(2, 2003);
    assertTrue(w1.equals(w2));
    int h1 = w1.hashCode();
    int h2 = w2.hashCode();
    assertEquals(h1, h2);
}
 
Example #14
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond() method.
 */
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Week w = new Week(3, 1970);
    assertEquals(946800000L, w.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #15
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getLastMillisecond() method.
 */
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Week w = new Week(31, 1970);
    assertEquals(18485999999L, w.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #16
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getStart() method.
 */
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Week w = new Week(3, 2006);
    assertEquals(cal.getTime(), w.getStart());
    Locale.setDefault(saved);        
}
 
Example #17
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getEnd() method.
 */
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 8, 23, 59, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Week w = new Week(1, 2006);
    assertEquals(cal.getTime(), w.getEnd());
    Locale.setDefault(saved);                
}
 
Example #18
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getLastMillisecond() method.
 */
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Week w = new Week(31, 1970);
    assertEquals(18485999999L, w.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #19
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getStart() method.
 */
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Week w = new Week(3, 2006);
    assertEquals(cal.getTime(), w.getStart());
    Locale.setDefault(saved);
}
 
Example #20
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond() method.
 */
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Week w = new Week(3, 1970);
    assertEquals(946800000L, w.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #21
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashcode() {
    Week w1 = new Week(2, 2003);
    Week w2 = new Week(2, 2003);
    assertTrue(w1.equals(w2));
    int h1 = w1.hashCode();
    int h2 = w2.hashCode();
    assertEquals(h1, h2);
}
 
Example #22
Source File: WeekTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test case for bug 1448828.
 */
public void testBug1448828() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    try {
        Week w = new Week(new Date(1136109830000l),
                TimeZone.getTimeZone("GMT"), Locale.getDefault());
        assertEquals(2005, w.getYearValue());
        assertEquals(52, w.getWeek());
    }
    finally {
        Locale.setDefault(saved);
    }
}
 
Example #23
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Request the week before week 1, 1900: it should be <code>null</code>.
 */
public void testW1Y1900Previous() {
    Week previous = (Week) this.w1Y1900.previous();
    assertNull(previous);
}
 
Example #24
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Request the week after week 1, 1900: it should be week 2, 1900.
 */
public void testW1Y1900Next() {
    Week next = (Week) this.w1Y1900.next();
    assertEquals(this.w2Y1900, next);
}
 
Example #25
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Request the week before w52, 9999: it should be week 51, 9999.
 */
public void testW52Y9999Previous() {
    Week previous = (Week) this.w52Y9999.previous();
    assertEquals(this.w51Y9999, previous);
}
 
Example #26
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Request the week after w52, 9999: it should be <code>null</code>.
 */
public void testW52Y9999Next() {
    Week next = (Week) this.w52Y9999.next();
    assertNull(next);
}
 
Example #27
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The {@link Week} class is immutable, so should not be {@link Cloneable}.
 */
public void testNotCloneable() {
    Week w = new Week(1, 1999);
    assertFalse(w instanceof Cloneable);
}
 
Example #28
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The first week in 2005 should span the range:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104710400000 | 1105315199999 |  3-Jan-2005 | 9-Jan-2005
 * Europe/Paris     | 1104706800000 | 1105311599999 |  3-Jan-2005 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 *
 * In London and Paris, Monday is the first day of the week, while in the
 * US it is Sunday.
 *
 * Previously, we were using these values, but see Java Bug ID 4960215:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104105600000 | 1104710399999 | 27-Dec-2004 | 2-Jan-2005
 * Europe/Paris     | 1104102000000 | 1104706799999 | 27-Dec-2004 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 */
public void testWeek12005() {
    Week w1 = new Week(1, 2005);
    Calendar c1 = Calendar.getInstance(
            TimeZone.getTimeZone("Europe/London"), Locale.UK);
    c1.setMinimalDaysInFirstWeek(4);  // see Java Bug ID 4960215
    assertEquals(1104710400000L, w1.getFirstMillisecond(c1));
    assertEquals(1105315199999L, w1.getLastMillisecond(c1));
    Calendar c2 = Calendar.getInstance(
            TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE);
    c2.setMinimalDaysInFirstWeek(4);  // see Java Bug ID 4960215
    assertEquals(1104706800000L, w1.getFirstMillisecond(c2));
    assertEquals(1105311599999L, w1.getLastMillisecond(c2));
    Calendar c3 = Calendar.getInstance(
            TimeZone.getTimeZone("America/New_York"), Locale.US);
    assertEquals(1104037200000L, w1.getFirstMillisecond(c3));
    assertEquals(1104641999999L, w1.getLastMillisecond(c3));
}
 
Example #29
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The first week in 2005 should span the range:
 * 
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104710400000 | 1105315199999 |  3-Jan-2005 | 9-Jan-2005
 * Europe/Paris     | 1104706800000 | 1105311599999 |  3-Jan-2005 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 * 
 * In London and Paris, Monday is the first day of the week, while in the 
 * US it is Sunday.
 * 
 * Previously, we were using these values, but see Java Bug ID 4960215:
 * 
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104105600000 | 1104710399999 | 27-Dec-2004 | 2-Jan-2005
 * Europe/Paris     | 1104102000000 | 1104706799999 | 27-Dec-2004 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 */
public void testWeek12005() {
    Week w1 = new Week(1, 2005);
    Calendar c1 = Calendar.getInstance(
            TimeZone.getTimeZone("Europe/London"), Locale.UK);
    c1.setMinimalDaysInFirstWeek(4);  // see Java Bug ID 4960215
    assertEquals(1104710400000L, w1.getFirstMillisecond(c1));
    assertEquals(1105315199999L, w1.getLastMillisecond(c1));
    Calendar c2 = Calendar.getInstance(
            TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE);
    c2.setMinimalDaysInFirstWeek(4);  // see Java Bug ID 4960215
    assertEquals(1104706800000L, w1.getFirstMillisecond(c2));
    assertEquals(1105311599999L, w1.getLastMillisecond(c2));
    Calendar c3 = Calendar.getInstance(
            TimeZone.getTimeZone("America/New_York"), Locale.US);
    assertEquals(1104037200000L, w1.getFirstMillisecond(c3));
    assertEquals(1104641999999L, w1.getLastMillisecond(c3));   
}
 
Example #30
Source File: WeekTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The {@link Week} class is immutable, so should not be {@link Cloneable}.
 */
public void testNotCloneable() {
    Week w = new Week(1, 1999);
    assertFalse(w instanceof Cloneable);
}