org.jcoderz.commons.types
Class YearMonth

java.lang.Object
  extended by org.jcoderz.commons.types.YearMonth
All Implemented Interfaces:
Serializable

public final class YearMonth
extends Object
implements Serializable

Encapsulates the Year Month type. Instances of this class are immutable. Years before 1 are not fully supported and might result in wrong string representations. Not parseable time zones might be ignored.

Author:
Andreas Mandel
See Also:
Serialized Form

Field Summary
static int MINIMUM_NUMBER_OF_YEAR_DIGITS
          Minimum length for the year.
static int MONTH_LENGTH
          Fixed length for the month.
static String TYPE_NAME
          The name of this type.
 
Method Summary
 boolean equals(Object o)
          
static YearMonth fromString(String str)
          Parses a valid XML representation of the gYearMonth type.
 int getMonth()
          Returns the month counting from 1 (January) to 12 (December).
 int getYear()
           
 int hashCode()
          
 boolean isWithin(Date date)
          Returns true if the given date is within this year/month.
 Date toEndDate()
          Returns the valid date that represents the end of the month year type.
 Period toPeriod()
          Returns this as period from start date to end date of this YearMonth.
 Date toStartDate()
          Returns the valid date that represents the beginning of the month year type.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_NAME

public static final String TYPE_NAME
The name of this type.

See Also:
Constant Field Values

MINIMUM_NUMBER_OF_YEAR_DIGITS

public static final int MINIMUM_NUMBER_OF_YEAR_DIGITS
Minimum length for the year.

See Also:
Constant Field Values

MONTH_LENGTH

public static final int MONTH_LENGTH
Fixed length for the month.

See Also:
Constant Field Values
Method Detail

fromString

public static YearMonth fromString(String str)
Parses a valid XML representation of the gYearMonth type. The format is CCYY-MM.

Parameters:
str - the string representing the year month.
Returns:
a YearMonth object representing the given year month.

toStartDate

public Date toStartDate()
Returns the valid date that represents the beginning of the month year type. The date in time is the first second in the month year.

Returns:
a date denoting the first second in the month year.

toEndDate

public Date toEndDate()
Returns the valid date that represents the end of the month year type. The date in time is the first second in the month year.

Returns:
a date denoting the first second in the month year.

toPeriod

public Period toPeriod()
Returns this as period from start date to end date of this YearMonth.

Returns:
a period representing the time period of this year month.

getMonth

public int getMonth()
Returns the month counting from 1 (January) to 12 (December).

Returns:
The month counting from 1 (January) to 12 (December).

getYear

public int getYear()
Returns:
Returns the year.

isWithin

public boolean isWithin(Date date)
Returns true if the given date is within this year/month.

Parameters:
date - the point in time to check.
Returns:
true if the given date is within this year/month.

toString

public String toString()

Overrides:
toString in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object o)

Overrides:
equals in class Object


Copyright 2007 The jCoderZ Project.