com.jrefinery.data
Class Week

java.lang.Object
  |
  +--com.jrefinery.data.TimePeriod
        |
        +--com.jrefinery.data.Week
All Implemented Interfaces:
java.lang.Comparable, com.jrefinery.date.MonthConstants

public class Week
extends TimePeriod

Represents a week within a particular year.

A year will have 52 or 53 weeks. Sometimes the first week of the year actually starts in the previous year - see the Javadocs for GregorianCalendar for details.

This class is immutable, which is a requirement for all TimePeriod subclasses.

Author:
DG

Field Summary
static int FIRST_WEEK_IN_YEAR
          Constant for the first week in the year.
static int LAST_WEEK_IN_YEAR
          Constant for the last week in the year.
 
Fields inherited from class com.jrefinery.data.TimePeriod
DEFAULT_TIME_ZONE, WORKING_CALENDAR
 
Fields inherited from interface com.jrefinery.date.MonthConstants
APRIL, AUGUST, DECEMBER, FEBRUARY, JANUARY, JULY, JUNE, MARCH, MAY, NOVEMBER, OCTOBER, SEPTEMBER
 
Constructor Summary
Week()
          Constructs a Week, based on the system date/time.
Week(java.util.Date time)
          Constructs a time period representing a week.
Week(java.util.Date time, java.util.TimeZone zone)
          Constructs a Week, based on a date/time and a time zone.
Week(int week, int year)
          Constructs a time period representing the week in the specified year.
Week(int week, Year year)
          Constructs a time period representing the week in the specified year.
 
Method Summary
 int compareTo(java.lang.Object o1)
          Returns an integer indicating the order of this Week object relative to the specified object: negative == before, zero == same, positive == after.
 boolean equals(java.lang.Object obj)
          Tests the equality of this Week object to an arbitrary object.
 long getEnd(java.util.Calendar calendar)
          Returns the last millisecond of the week, evaluated using the supplied calendar (which determines the time zone).
 long getSerialIndex()
          Returns a serial index number for the week.
 long getStart(java.util.Calendar calendar)
          Returns the first millisecond of the week, evaluated using the supplied calendar (which determines the time zone).
 int getWeek()
          Returns the week.
 Year getYear()
          Returns the year in which the week falls.
 int getYearValue()
          Returns the year in which the week falls, as an integer value.
 TimePeriod next()
          Returns the week following this one.
static Week parseWeek(java.lang.String s)
          Parses the string argument as a week.
 TimePeriod previous()
          Returns the week preceding this one.
 java.lang.String toString()
          Returns a string representing the week (e.g.
 
Methods inherited from class com.jrefinery.data.TimePeriod
getEnd, getEnd, getMiddle, getMiddle, getMiddle, getStart, getStart
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIRST_WEEK_IN_YEAR

public static final int FIRST_WEEK_IN_YEAR
Constant for the first week in the year.

LAST_WEEK_IN_YEAR

public static final int LAST_WEEK_IN_YEAR
Constant for the last week in the year.
Constructor Detail

Week

public Week()
Constructs a Week, based on the system date/time.

Week

public Week(int week,
            int year)
Constructs a time period representing the week in the specified year.
Parameters:
week - the week (1 to 53).
year - the year (1900 to 9999).

Week

public Week(int week,
            Year year)
Constructs a time period representing the week in the specified year.
Parameters:
week - the week (1 to 53).
year - the year (1900 to 9999).

Week

public Week(java.util.Date time)
Constructs a time period representing a week.
Parameters:
time - the time.

Week

public Week(java.util.Date time,
            java.util.TimeZone zone)
Constructs a Week, based on a date/time and a time zone.
Parameters:
time - the date/time.
zone - the time zone.
Method Detail

getYear

public Year getYear()
Returns the year in which the week falls.
Returns:
The year.

getYearValue

public int getYearValue()
Returns the year in which the week falls, as an integer value.
Returns:
The year.

getWeek

public int getWeek()
Returns the week.
Returns:
The week.

previous

public TimePeriod previous()
Returns the week preceding this one.
Overrides:
previous in class TimePeriod
Returns:
The preceding week.

next

public TimePeriod next()
Returns the week following this one.
Overrides:
next in class TimePeriod
Returns:
the following week.

getSerialIndex

public long getSerialIndex()
Returns a serial index number for the week.
Overrides:
getSerialIndex in class TimePeriod
Returns:
the serial index number.

getStart

public long getStart(java.util.Calendar calendar)
Returns the first millisecond of the week, evaluated using the supplied calendar (which determines the time zone).
Overrides:
getStart in class TimePeriod
Parameters:
calendar - the calendar.
Returns:
the first millisecond of the week.

getEnd

public long getEnd(java.util.Calendar calendar)
Returns the last millisecond of the week, evaluated using the supplied calendar (which determines the time zone).
Overrides:
getEnd in class TimePeriod
Parameters:
calendar - the calendar.
Returns:
The last millisecond of the week.

toString

public java.lang.String toString()
Returns a string representing the week (e.g. "Week 9, 2002").

To do: look at internationalisation.

Overrides:
toString in class java.lang.Object
Returns:
A string representing the week.

equals

public boolean equals(java.lang.Object obj)
Tests the equality of this Week object to an arbitrary object. Returns true if the target is a Week instance representing the same week as this object. In all other cases, returns false.
Overrides:
equals in class java.lang.Object
Parameters:
obj - The object.
Returns:
true if week and year of this and object are the same.

compareTo

public int compareTo(java.lang.Object o1)
Returns an integer indicating the order of this Week object relative to the specified object: negative == before, zero == same, positive == after.
Parameters:
o1 - the object to compare.
Returns:
negative == before, zero == same, positive == after.

parseWeek

public static Week parseWeek(java.lang.String s)
                      throws TimePeriodFormatException
Parses the string argument as a week.

This method is required to accept the format "YYYY-Wnn". It will also accept "Wnn-YYYY". Anything else, at the moment, is a bonus.

Parameters:
s - string to parse.
Returns:
null if the string is not parseable, the week otherwise.
Throws:
TimePeriodFormatException - if there is a problem parsing the string.