biweekly.util
Class DateTimeComponents

java.lang.Object
  extended by biweekly.util.DateTimeComponents

public final class DateTimeComponents
extends Object

Contains the raw components of a date-time value.

Examples:

 //July 22, 2013 at 17:25
 DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false);
 
 //parsing a date string (accepts basic and extended formats)
 DateTimeComponents components = DateTimeComponents.parse("20130722T172500");
 
 //converting to date string
 DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false);
 String str = components.toString(true); //"2013-07-22T17:25:00"
 
 //converting to a Date object
 DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false);
 Date date = components.toDate();
 
 

Author:
Michael Angstadt

Constructor Summary
DateTimeComponents(DateTimeComponents original, Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second, Boolean utc)
          Copies an existing DateTimeComponents object.
DateTimeComponents(int year, int month, int date, int hour, int minute, int second, boolean utc)
          Creates a new set of date-time components.
 
Method Summary
 boolean equals(Object obj)
           
 int getDate()
          Gets the date component
 int getHour()
          Gets the hour component
 int getMinute()
          Gets the minute component.
 int getMonth()
          Gets the month component.
 int getSecond()
          Gets the second component.
 int getYear()
          Gets the year component.
 int hashCode()
           
 boolean isUtc()
          Gets whether the time is in UTC or not
static DateTimeComponents parse(String dateString)
          Parses the components out of a date-time string.
 Date toDate()
          Converts the date-time components to a Date object.
 String toString()
          Converts the date-time components to a string using "basic" format.
 String toString(boolean extended)
          Converts the date-time components to a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateTimeComponents

public DateTimeComponents(DateTimeComponents original,
                          Integer year,
                          Integer month,
                          Integer date,
                          Integer hour,
                          Integer minute,
                          Integer second,
                          Boolean utc)
Copies an existing DateTimeComponents object.

Parameters:
original - the object to copy from
year - the new year value or null not to change
month - the new month value or null not to change
date - the new date value or null not to change
hour - the new hour value or null not to change
minute - the new minute value or null not to change
second - the new second value or null not to change
utc - true if the time is in UTC, false if not, or null not to change

DateTimeComponents

public DateTimeComponents(int year,
                          int month,
                          int date,
                          int hour,
                          int minute,
                          int second,
                          boolean utc)
Creates a new set of date-time components.

Parameters:
year - the year (e.g. "2013")
month - the month (e.g. "1" for January)
date - the date of the month (e.g. "15")
hour - the hour (e.g. "13")
minute - the minute
second - the second
utc - true if the time is in UTC, false if not
Method Detail

parse

public static DateTimeComponents parse(String dateString)
Parses the components out of a date-time string.

Parameters:
dateString - the date-time string (basic and extended formats supported, e.g. "20130331T020000" or "2013-03-31T02:00:00")
Returns:
the parsed components
Throws:
IllegalArgumentException - if the date string cannot be parsed

getYear

public int getYear()
Gets the year component.

Returns:
the year

getMonth

public int getMonth()
Gets the month component.

Returns:
the month (e.g. "1" for January)

getDate

public int getDate()
Gets the date component

Returns:
the date

getHour

public int getHour()
Gets the hour component

Returns:
the hour

getMinute

public int getMinute()
Gets the minute component.

Returns:
the minute

getSecond

public int getSecond()
Gets the second component.

Returns:
the second

isUtc

public boolean isUtc()
Gets whether the time is in UTC or not

Returns:
true if the time is in UTC, false if not

toString

public String toString()
Converts the date-time components to a string using "basic" format.

Overrides:
toString in class Object
Returns:
the date string

toString

public String toString(boolean extended)
Converts the date-time components to a string.

Parameters:
extended - true to use extended format, false to use basic
Returns:
the date string

toDate

public Date toDate()
Converts the date-time components to a Date object.

Returns:
the date object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2013 Michael Angstadt. All Rights Reserved.