com.h3c.util

## Class TimePeriod

- java.lang.Object
- - com.h3c.util.TimePeriod

- All Implemented Interfaces:
    Serializable

      public final class TimePeriod
      extends Object
      implements Serializable

  Time period.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TimePeriod(Date startTime, Date endTime)` Constructs a new time period.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<TimePeriod>` | `breakDownDaily(TimeZone timeZone)` Breaks the time period down to days.
    `List<TimePeriod>` | `breakDownHourly(TimeZone timeZone)` Breaks the time period down to days.
    `List<TimePeriod>` | `breakDownMonthly(TimeZone timeZone)` Breaks the time period down to months.
    `List<TimePeriod>` | `breakDownWeekly(TimeZone timeZone)` Breaks the time period down to weeks.
    `List<TimePeriod>` | `breakDownYearly(TimeZone timeZone)` Breaks the time period down to years.
    `boolean` | `equals(Object obj)`
    `static TimePeriod` | `getDayPeriod(Date time, TimeZone timeZone)` Gets the one-day period the given point in time belongs to.
    `Date` | `getEndTime()` Gets the end time.
    `static TimePeriod` | `getHourPeriod(Date time, TimeZone timeZone)` Gets the one-hour period the given point in time belongs to.
    `static TimePeriod` | `getMonthPeriod(Date time, TimeZone timeZone)` Gets the one-month period the given point in time belongs to.
    `Date` | `getStartTime()` Gets the start time.
    `static Date[]` | `getWeekDays(Date time, TimeZone timeZone)` Gets the week the given point in time belongs to.
    `static TimePeriod` | `getWeekPeriod(Date time, TimeZone timeZone)` Gets the one-week period the given point in time belongs to.
    `static TimePeriod` | `getYearPeriod(Date time, TimeZone timeZone)` Gets the one-year period the given point in time belongs to.
    `int` | `hashCode()`
    `static boolean` | `isValidPeriod(Date startTime, Date endTime)` Verifies whether the given dates conform a valid time period.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TimePeriod

          public TimePeriod(Date startTime,
                    Date endTime)
                     throws NullPointerException,
                            IllegalArgumentException

      Constructs a new time period.
      Parameters:
        `startTime` - start time
        `endTime` - end time
      Throws:
        `NullPointerException` - if either `startTime` or `endTime` is `null`
        `IllegalArgumentException` - if `startTime` does not happen before `endTime`

  - ### Method Detail

    - #### getStartTime

          public Date getStartTime()

      Gets the start time.
      Returns:
        the start time

    - #### getEndTime

          public Date getEndTime()

      Gets the end time.
      Returns:
        the end time

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### isValidPeriod

          public static boolean isValidPeriod(Date startTime,
                              Date endTime)

      Verifies whether the given dates conform a valid time period.
      Parameters:
        `startTime` - start time
        `endTime` - end time
      Returns:
        `true` if `startTime` and `endTime` conform a valid time period, `false` otherwise

    - #### getHourPeriod

          public static TimePeriod getHourPeriod(Date time,
                                 TimeZone timeZone)

      Gets the one-hour period the given point in time belongs to.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone. See `TimeZone.getDefault()`
      Returns:
        a time period where the start time is the beginning of the day `time` belongs to and the end time is the end of the day

    - #### getDayPeriod

          public static TimePeriod getDayPeriod(Date time,
                                TimeZone timeZone)

      Gets the one-day period the given point in time belongs to.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a time period where the start time is the beginning of the day `time` belongs to and the end time is the end of the day

    - #### getWeekPeriod

          public static TimePeriod getWeekPeriod(Date time,
                                 TimeZone timeZone)

      Gets the one-week period the given point in time belongs to.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a time period where the start time is the beginning of the week `time` belongs to and the end time is the end of the week

    - #### getWeekDays

          public static Date[] getWeekDays(Date time,
                           TimeZone timeZone)

      Gets the week the given point in time belongs to. The week starts at Sunday.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        an array of seven elements containing the starting point of the days of the week (Sunday - Saturday)

    - #### getMonthPeriod

          public static TimePeriod getMonthPeriod(Date time,
                                  TimeZone timeZone)

      Gets the one-month period the given point in time belongs to.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a time period where the start time is the beginning of the month `time` belongs to and the end time is the end of the month

    - #### getYearPeriod

          public static TimePeriod getYearPeriod(Date time,
                                 TimeZone timeZone)

      Gets the one-year period the given point in time belongs to.
      Parameters:
        `time` - reference point in time
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a time period where the start time is the beginning of the year `time` belongs to and the end time is the end of the year

    - #### breakDownHourly

          public List<TimePeriod> breakDownHourly(TimeZone timeZone)

      Breaks the time period down to days.
      Parameters:
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a sorted list of time periods for each day

    - #### breakDownDaily

          public List<TimePeriod> breakDownDaily(TimeZone timeZone)

      Breaks the time period down to days.
      Parameters:
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a sorted list of time periods for each day

    - #### breakDownWeekly

          public List<TimePeriod> breakDownWeekly(TimeZone timeZone)

      Breaks the time period down to weeks.
      Parameters:
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a sorted list of time periods for each week

    - #### breakDownMonthly

          public List<TimePeriod> breakDownMonthly(TimeZone timeZone)

      Breaks the time period down to months.
      Parameters:
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a sorted list of time periods for each month

    - #### breakDownYearly

          public List<TimePeriod> breakDownYearly(TimeZone timeZone)

      Breaks the time period down to years.
      Parameters:
        `timeZone` - time zone; see `TimeZone.getDefault()`
      Returns:
        a sorted list of time periods for each year

Copyright © 2014. All Rights Reserved.