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” or “HH:MM Z” pattern

Methods

compareTo

public int compareTo(Time otherTime)

equals

public boolean equals(Object obj)

getHour

public Integer getHour()

Returns the hour of day for this time instance.

Returns:the hour of day

getMinute

public Integer getMinute()

Returns the minute of hour for this time instance.

Returns:the minute of hour

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

isAfterOrEqual

public boolean isAfterOrEqual(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 or equal to 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

isBeforeOrEqual

public boolean isBeforeOrEqual(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 or equal to other, false otherwise

isBetween

public boolean isBetween(Time start, Time end)

Checks whether this is before the given time.

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

true if this time is between start and end (inclusive), false 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)

Sets the hour of day for this time instance.

Parameters:
  • hour – the hour of day

setMinute

public void setMinute(Integer minute)

Sets the minute of hour for this time instance.

Parameters:
  • minute – the minute of hour

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