Time

public class Time implements Comparable<Time>, Serializable

Represents time as number of hours and minutes.

Constructors

Time

public Time()

Constructor.

Time

public Time(int hour, int minute)

Constructor.

Parameters:
  • hour – the hour to be stored, not null
  • minute – the minute to be stored, not null

Time

public Time(LocalTime localTime)

Constructor.

Parameters:
  • localTime – the time to be stored, not null

Time

public Time(String timeStr)

Constructor.

Parameters:
  • timeStr – the time represented as String
Throws:
  • IllegalArgumentException – if timeStr doesn’t match “HH:MM” pattern

Methods

compareTo

public int compareTo(Time otherTime)

equals

public boolean equals(Object obj)

getHour

public Integer getHour()

getMinute

public Integer getMinute()

gt

public boolean gt(Time toCompare)

Checks if given object is before this object or both objects represents the same time.

Parameters:
  • toCompare – the object to be compared with this object
Returns:

false if given Time is after this, true otherwise

hashCode

public int hashCode()

isAfter

public boolean isAfter(Time other)

Checks whether this is after the given time.

Parameters:
  • other – the Time to be compared with this object
Returns:

true if this time is after other, false otherwise

isBefore

public boolean isBefore(Time other)

Checks whether this is before the given time.

Parameters:
  • other – the Time to be compared with this object
Returns:

true if this time is before other, false otherwise

lt

public boolean lt(Time toCompare)

Checks if given object is after this object or both objects represents the same time.

Parameters:
  • toCompare – the object to be compared with this object
Returns:

false if given Time is before this, true otherwise

parseTime

public static Time parseTime(String time, String separator)

Parses given String using the separator.

Parameters:
  • time – the String to be parsed, null returns null
  • separator – the separator used to distinguish minute from hour, not null
Throws:
Returns:

the instance of Time

setHour

public void setHour(Integer hour)

setMinute

public void setMinute(Integer minute)

timeStr

public String timeStr()

Returns String representation of stored time.

Returns:the time stored as a String

toDateTime

public DateTime toDateTime(DateTime dateTime)

Creates DateTime instance with time stored in this object.

Parameters:
  • dateTime – the DateTime to be used as base for the new DateTime
Returns:

the DateTime with stored time

toDateTime

public DateTime toDateTime(LocalDate date)

Creates DateTime instance with time stored in this object.

Parameters:
  • date – the LocalDate to be used as base for the new DateTime
Returns:

the DateTime with stored time

toString

public String toString()

valueOf

public static Time valueOf(String str)

Creates instance of Time for given String.

Parameters:
  • str – the String to be parsed to Time
Returns:

the Time parsed from given String