Class Month

    • Constructor Detail

      • Month

        public Month​(int month,
                     int year)
        Constructs a new month instance. The time zone and locale are determined by the calendar returned by RegularTimePeriod.getCalendarInstance().
        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. The time zone and locale are determined by the calendar returned by RegularTimePeriod.getCalendarInstance().
        Parameters:
        month - the month (in the range 1 to 12).
        year - the year.
      • Month

        public Month​(Date time,
                     TimeZone zone,
                     Locale locale)
        Creates a new Month instance, based on the specified time, zone and locale.
        Parameters:
        time - the current time.
        zone - the time zone.
        locale - the locale.
        Since:
        1.0.12
      • Month

        public Month​(Date time,
                     Calendar calendar)
        Constructs a new instance, based on a particular date/time. The time zone and locale are determined by the calendar parameter.
        Parameters:
        time - the date/time (null not permitted).
        calendar - the calendar to use for calculations (null not permitted).
    • 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 month falls (as an int).
      • getMonth

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

        public void peg​(Calendar calendar)
        Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).
        Specified by:
        peg in class RegularTimePeriod
        Parameters:
        calendar - the calendar (null not permitted).
        Since:
        1.0.3
      • toString

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

        To do: look at internationalisation.

        Overrides:
        toString in class RegularTimePeriod
        Returns:
        A string representing the month.
      • equals

        public boolean equals​(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 Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        true if month and year of this and object are the same.
      • hashCode

        public int hashCode()
        Returns a hash code for this object instance. The approach described by Joshua Bloch in "Effective Java" has been used here:

        http://developer.java.sun.com/developer/Books/effectivejava /Chapter3.pdf

        Overrides:
        hashCode in class Object
        Returns:
        A hash code.
      • compareTo

        public int compareTo​(Object o1)
        Returns an integer indicating the order of this Month object relative to the specified object: negative == before, zero == same, positive == after.
        Specified by:
        compareTo in interface Comparable
        Parameters:
        o1 - the object to compare.
        Returns:
        negative == before, zero == same, positive == after.
      • parseMonth

        public static Month parseMonth​(String s)
        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.
        Parameters:
        s - the string to parse (null permitted).
        Returns:
        null if the string is not parseable, the month otherwise.