com.jrefinery.data
Class Month

java.lang.Object
  extended by com.jrefinery.data.TimePeriod
      extended by com.jrefinery.data.Month
All Implemented Interfaces:
MonthConstants, java.lang.Comparable

public class Month
extends TimePeriod

Represents a single month.

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


Field Summary
protected  int month
          The month (1-12).
protected  Year year
          The year in which the month falls.
 
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
Month()
          Constructs a new Month, based on the current system time.
Month(java.util.Date time)
          Constructs a Month, based on a date/time and the default time zone.
Month(java.util.Date time, java.util.TimeZone zone)
          Constructs a Month, based on a date/time and a time zone.
Month(int month, int year)
          Constructs a new month instance.
Month(int month, Year year)
          Constructs a new month instance.
 
Method Summary
 int compareTo(java.lang.Object o1)
          Returns an integer indicating the order of this Month object relative to the specified object: negative == before, zero == same, positive == after.
 boolean equals(java.lang.Object obj)
          Tests the equality of this Month object to an arbitrary object.
 long getEnd(java.util.Calendar calendar)
          Returns the last millisecond of the month, evaluated using the supplied calendar (which determines the time zone).
 int getMonth()
          Returns the month.
 long getStart(java.util.Calendar calendar)
          Returns the first millisecond of the month, evaluated using the supplied calendar (which determines the time zone).
 Year getYear()
          Returns the year in which the month falls.
 int getYearValue()
          Returns the year in which the month falls.
 TimePeriod next()
          Returns the month following this one.
static Month parseMonth(java.lang.String s)
          Parses the string argument as a month.
 TimePeriod previous()
          Returns the month preceding this one.
 java.lang.String toString()
          Returns a string representing the month (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

month

protected int month
The month (1-12).


year

protected Year year
The year in which the month falls.

Constructor Detail

Month

public Month()
Constructs a new Month, based on the current system time.


Month

public Month(int month,
             int year)
Constructs a new month instance.

Parameters:
month - The month (in the range 1 to 12).
year - The year.

Month

public Month(int month,
             Year year)
Constructs a new month instance.

Parameters:
month - The month (in the range 1 to 12).
year - The year.

Month

public Month(java.util.Date time)
Constructs a Month, based on a date/time and the default time zone.

Parameters:
time - The date/time.

Month

public Month(java.util.Date time,
             java.util.TimeZone zone)
Constructs a Month, 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 month falls.

Returns:
The year in which the month falls (as a Year object).

getYearValue

public int getYearValue()
Returns the year in which the month falls.

Returns:
The year in which the monht falls (as an int).

getMonth

public int getMonth()
Returns the month. Note that 1=JAN, 2=FEB, ...


previous

public TimePeriod previous()
Returns the month preceding this one.

Specified by:
previous in class TimePeriod
Returns:
The previous time period.

next

public TimePeriod next()
Returns the month following this one.

Specified by:
next in class TimePeriod
Returns:
The next time period.

toString

public java.lang.String toString()
Returns a string representing the month (e.g. "January 2002").

To do: look at internationalisation.

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

equals

public boolean equals(java.lang.Object obj)
Tests the equality of this Month object to an arbitrary object. Returns true if the target is a Month instance representing the same month as this object. In all other cases, returns false.

Overrides:
equals in class java.lang.Object
Parameters:
object - The object.

compareTo

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


getStart

public long getStart(java.util.Calendar calendar)
Returns the first millisecond of the month, evaluated using the supplied calendar (which determines the time zone).

Specified by:
getStart in class TimePeriod
Parameters:
calendar - The calendar.
Returns:
The first millisecond of the month.

getEnd

public long getEnd(java.util.Calendar calendar)
Returns the last millisecond of the month, evaluated using the supplied calendar (which determines the time zone).

Specified by:
getEnd in class TimePeriod
Parameters:
calendar - The calendar.
Returns:
The last millisecond of the month.

parseMonth

public static Month parseMonth(java.lang.String s)
                        throws TimePeriodFormatException
Parses the string argument as a month.

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

Throws:
TimePeriodFormatException


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.