Class Time

All Implemented Interfaces:
IElement, ITime

public final class Time extends AbstractElement implements ITime
A Time is not mutable. Technically, a Time is a wrapper around a JDK's ZonedDateTime.
Author:
Silvan Wyss
  • Field Details

    • DEFAULT_YEAR

      public static final int DEFAULT_YEAR
      See Also:
    • DEFAULT_MONTH_OF_YEAR

      public static final int DEFAULT_MONTH_OF_YEAR
      See Also:
    • DEFAULT_DAY_OF_MONTH

      public static final int DEFAULT_DAY_OF_MONTH
      See Also:
    • DEFAULT_HOUR_OF_DAY

      public static final int DEFAULT_HOUR_OF_DAY
      See Also:
    • DEFAULT_MINUTE_OF_HOUR

      public static final int DEFAULT_MINUTE_OF_HOUR
      See Also:
    • DEFAULT_SECOND_OF_MINUTE

      public static final int DEFAULT_SECOND_OF_MINUTE
      See Also:
    • DEFAULT_MILLISECOND_OF_SECOND

      public static final int DEFAULT_MILLISECOND_OF_SECOND
      See Also:
    • DEFAULT_MICROSECOND_OF_MILLISECOND

      public static final int DEFAULT_MICROSECOND_OF_MILLISECOND
      See Also:
  • Method Details

    • forZonedDateTime

      public static Time forZonedDateTime(ZonedDateTime zonedDateTime)
      Parameters:
      zonedDateTime -
      Returns:
      a new Time for the given zonedDateTime.
      Throws:
      RuntimeException - if the given zonedDateTime is null.
    • fromSpecification

      public static Time fromSpecification(INode<?> specification)
      Parameters:
      specification -
      Returns:
      a new Time from the given specification.
      Throws:
      NullPointerException - if the given specification is null.
      RuntimeException - if the given specification does not represent a Time.
    • fromString

      public static Time fromString(String string)
      Parameters:
      string -
      Returns:
      a new Time from the given string.
      Throws:
      RuntimeException - if the given string does not represent a Time.
    • ofNow

      public static Time ofNow()
      Returns:
      a new Time that represents the current time.
    • withYear

      public static Time withYear(int year)
      Parameters:
      year -
      Returns:
      a new Time with the given year.
    • withYearAndMonthOfYear

      public static Time withYearAndMonthOfYear(int year, int monthOfYear)
      Parameters:
      year -
      monthOfYear -
      Returns:
      a new Time with the given year and monthOfYear.
    • withYearAndMonthOfYearAndDayOfMonth

      public static Time withYearAndMonthOfYearAndDayOfMonth(int year, int monthOfYear, int dayOfMonth)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      Returns:
      a new Time with the given year, monthOfYear and dayOfMonth.
    • withYearAndMonthOfYearAndDayOfMonthAndHourOfDay

      public static Time withYearAndMonthOfYearAndDayOfMonthAndHourOfDay(int year, int monthOfYear, int dayOfMonth, int hourOfDay)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      hourOfDay -
      Returns:
      a new Time with the given year, monthOfYear, dayOfMonth and hourOfDay.
    • withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHour

      public static Time withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHour(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      hourOfDay -
      minuteOfHour -
      Returns:
      a new Time with the given year, monthOfYear, dayOfMonth, hourOfDay and minuteOfHour.
    • withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMin

      public static Time withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMin(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      hourOfDay -
      minuteOfHour -
      secondOfMinute -
      Returns:
      a new Time with the given year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour and secondOfMinute.
    • withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMinAndMillisecOfSec

      public static Time withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMinAndMillisecOfSec(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondOfSecond)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      hourOfDay -
      minuteOfHour -
      secondOfMinute -
      millisecondOfSecond -
      Returns:
      a new Time with the given year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute and millisecondOfSecond.
    • withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMinAndMillisecOfSecAndMicrosecOfMillisec

      public static Time withYearAndMonthOfYearAndDayOfMonthAndHourOfDayAndMinOfHourAndSecOfMinAndMillisecOfSecAndMicrosecOfMillisec(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondOfSecond, int microsecondsOfMilliSecond)
      Parameters:
      year -
      monthOfYear -
      dayOfMonth -
      hourOfDay -
      minuteOfHour -
      secondOfMinute -
      millisecondOfSecond -
      microsecondsOfMilliSecond -
      Returns:
      a new Time with the given year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute and millisecondOfSecond.
    • getAttributes

      public IContainer<INode<?>> getAttributes()
      Specified by:
      getAttributes in interface IElement
      Returns:
      the attributes of the current IElement.
    • getDayOfMonth

      public int getDayOfMonth()
      Specified by:
      getDayOfMonth in interface ITime
      Returns:
      the day of the month of the current ITime.
    • getHourOfDay

      public int getHourOfDay()
      Specified by:
      getHourOfDay in interface ITime
      Returns:
      the hour of the day of the current ITime.
    • getMicrosecondOfMillisecond

      public int getMicrosecondOfMillisecond()
      Specified by:
      getMicrosecondOfMillisecond in interface ITime
      Returns:
      the microsecond of the millisecond of the current ITime.
    • getMillisecondOfSecond

      public int getMillisecondOfSecond()
      Specified by:
      getMillisecondOfSecond in interface ITime
      Returns:
      the millisecond of the second of the current ITime.
    • getMinuteOfHour

      public int getMinuteOfHour()
      Specified by:
      getMinuteOfHour in interface ITime
      Returns:
      the minute of the hour of the current ITime.
    • getMonthOfYear

      public Month getMonthOfYear()
      Specified by:
      getMonthOfYear in interface ITime
      Returns:
      the month of the year of the current ITime.
    • getMonthOfYearAsInt

      public int getMonthOfYearAsInt()
      Specified by:
      getMonthOfYearAsInt in interface ITime
      Returns:
      the month of the year of the current ITime as int.
    • getSecondOfMinute

      public int getSecondOfMinute()
      Specified by:
      getSecondOfMinute in interface ITime
      Returns:
      the second of the minute of the current ITime.
    • getWeekday

      public Weekday getWeekday()
      Specified by:
      getWeekday in interface ITime
      Returns:
      the weekday of the current ITime.
    • getWeekOfYear

      public int getWeekOfYear()
      Specified by:
      getWeekOfYear in interface ITime
      Returns:
      the week of the year of the current ITime.
    • getYear

      public int getYear()
      Specified by:
      getYear in interface ITime
      Returns:
      the year of the current ITime.
    • isAfter

      public boolean isAfter(ITime time)
      Specified by:
      isAfter in interface ITime
      Parameters:
      time -
      Returns:
      true if the current ITime is after the given time, false otherwise
    • isBefore

      public boolean isBefore(ITime time)
      Specified by:
      isBefore in interface ITime
      Parameters:
      time -
      Returns:
      true if the current ITime is before the given time, false otherwise
    • isInLeapYear

      public boolean isInLeapYear()
      Specified by:
      isInLeapYear in interface ITime
      Returns:
      true if the current ITime is in a leap year, false otherwise.
    • toSeconds

      public long toSeconds()
      Specified by:
      toSeconds in interface ITime
      Returns:
      the seconds of the current ITime.
    • withAddedOrSubtractedDays

      public Time withAddedOrSubtractedDays(int days)
      Specified by:
      withAddedOrSubtractedDays in interface ITime
      Parameters:
      days -
      Returns:
      a new ITime with the given days added to or subtracted from the current ITime.
    • withAddedOrSubtractedHours

      public Time withAddedOrSubtractedHours(int hours)
      Specified by:
      withAddedOrSubtractedHours in interface ITime
      Parameters:
      hours -
      Returns:
      a new ITime with the given hours added to or subtracted from the current ITime.
    • withAddedOrSubtractedMicroseconds

      public ITime withAddedOrSubtractedMicroseconds(long microseconds)
      Specified by:
      withAddedOrSubtractedMicroseconds in interface ITime
      Parameters:
      microseconds -
      Returns:
      a new ITime with the given microseconds added to or subtracted from the current ITime.
    • withAddedOrSubtractedMilliseconds

      public Time withAddedOrSubtractedMilliseconds(int milliseconds)
      Specified by:
      withAddedOrSubtractedMilliseconds in interface ITime
      Parameters:
      milliseconds -
      Returns:
      a new ITime with the given milliseconds added to or subtracted from to the current ITime.
    • withAddedOrSubtractedMinutes

      public Time withAddedOrSubtractedMinutes(int minutes)
      Specified by:
      withAddedOrSubtractedMinutes in interface ITime
      Parameters:
      minutes -
      Returns:
      a new ITime with the given minutes added to or subtracted from the current ITime.
    • withAddedOrSubtractedSeconds

      public Time withAddedOrSubtractedSeconds(int seconds)
      Specified by:
      withAddedOrSubtractedSeconds in interface ITime
      Parameters:
      seconds -
      Returns:
      a new ITime with the given seconds added to or subtracted from the current ITime.