Class DateTimeValue

java.lang.Object
org.assertj.db.type.DateTimeValue
All Implemented Interfaces:
Comparable<DateTimeValue>, DateValueContainer

public class DateTimeValue extends Object implements Comparable<DateTimeValue>, DateValueContainer
This class represents a date/time value in the database.
Author:
Régis Pouiller
  • Constructor Details

    • DateTimeValue

      public DateTimeValue(DateValue date, TimeValue time)
      Constructor.
      Parameters:
      date - The date.
      time - The time.
      Throws:
      NullPointerException - If date or time is null.
    • DateTimeValue

      public DateTimeValue(String dateTime) throws ParseException
      Constructor.
      Parameters:
      dateTime - Time in String format (yyyy-mm-dd, yyyy-mm-ddThh:mm, yyyy-mm-ddThh:mm:ss or yyyy-mm-ddThh:mm:ss.nnnnnnnnn).
      Throws:
      NullPointerException - If dateTime is null.
      ParseException - If date don't respect the yyyy-mm-dd, yyyy-mm-ddThh:mm, yyyy-mm-ddThh:mm:ss or yyyy-mm-ddThh:mm:ss.nnnnnnnnn format.
    • DateTimeValue

      public DateTimeValue(Timestamp timestamp)
      Constructor.
      Parameters:
      timestamp - Timestamp.
      Throws:
      NullPointerException - If dateTime is null.
    • DateTimeValue

      public DateTimeValue(Calendar calendar)
      Constructor.
      Parameters:
      calendar - Calendar.
      Throws:
      NullPointerException - If calendar is null.
    • DateTimeValue

      public DateTimeValue(LocalDateTime localDateTime)
      Constructor.
      Parameters:
      localDateTime - LocalDateTime.
      Throws:
      NullPointerException - If localDateTime is null.
      Since:
      2.0.0
  • Method Details

    • of

      public static DateTimeValue of(DateValue date)
      Makes an instance of date/time value from a date with time at 00:00AM.
      Parameters:
      date - The date.
      Returns:
      An instance of date/time.
    • of

      public static DateTimeValue of(DateValue date, TimeValue time)
      Makes an instance of date/time value from a date and a time.
      Parameters:
      date - The date.
      time - The time.
      Returns:
      An instance of date/time.
    • parse

      public static DateTimeValue parse(String dateTime) throws ParseException
      Makes an instance of date/time value from a String in yyyy-mm-dd, yyyy-mm-ddThh:mm, yyyy-mm-ddThh:mm:ss or yyyy-mm-ddThh:mm:ss.nnnnnnnnn format.
      Parameters:
      dateTime - Date/time in String format (yyyy-mm-dd).
      Returns:
      An instance of date/time value.
      Throws:
      NullPointerException - If dateTime is null.
      ParseException - If date don't respect the yyyy-mm-dd, yyyy-mm-ddThh:mm, yyyy-mm-ddThh:mm:ss or yyyy-mm-ddThh:mm:ss.nnnnnnnnn format.
    • from

      public static DateTimeValue from(Timestamp timestamp)
      Makes an instance of date/time value from a Timestamp.
      Parameters:
      timestamp - Timestamp.
      Returns:
      An instance of date/time value.
      Throws:
      NullPointerException - If timestamp is null.
    • from

      public static DateTimeValue from(Calendar calendar)
      Makes an instance of date/time value from a Calendar.
      Parameters:
      calendar - Calendar.
      Returns:
      An instance of date/time value.
      Throws:
      NullPointerException - If calendar is null.
      Since:
      1.1.0
    • from

      public static DateTimeValue from(LocalDateTime localDateTime)
      Makes an instance of date/time value from a LocalDateTime.
      Parameters:
      localDateTime - LocalDateTime.
      Returns:
      An instance of date/time value.
      Throws:
      NullPointerException - If localDateTime is null.
      Since:
      2.0.0
    • now

      public static DateTimeValue now()
      Makes an instance of the date/time value corresponding to now.
      Returns:
      An instance of date/time value.
      Since:
      1.1.0
    • getDate

      public DateValue getDate()
      Returns the date.
      Specified by:
      getDate in interface DateValueContainer
      Returns:
      The date.
    • isMidnight

      public boolean isMidnight()
      Description copied from interface: DateValueContainer
      Returns if it is midnight.
      Specified by:
      isMidnight in interface DateValueContainer
      Returns:
      true if it is midnight.
    • getTime

      public TimeValue getTime()
      Returns the time.
      Returns:
      The time.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(DateTimeValue other)
      Specified by:
      compareTo in interface Comparable<DateTimeValue>
    • isBefore

      public boolean isBefore(DateTimeValue dateTime)
      Returns if this date/time value is before the date/time value in parameter.
      Parameters:
      dateTime - The date/time value to compare to.
      Returns:
      If this date/time value is before the date/time value in parameter.
    • isAfter

      public boolean isAfter(DateTimeValue dateTime)
      Returns if this date/time value is after the date/time value in parameter.
      Parameters:
      dateTime - The date/time value to compare to.
      Returns:
      If this date/time value is after the date/time value in parameter.
    • move

      public DateTimeValue move(DateValue date)
      Moves the date/time with the value in parameter.
      Parameters:
      date - Value to move the date.
      Returns:
      The date/time moved.
    • move

      public DateTimeValue move(TimeValue time)
      Moves the date/time with the value in parameter.
      Parameters:
      time - Value to move the date.
      Returns:
      The date/time moved.
    • move

      public DateTimeValue move(DateTimeValue dateTime)
      Moves the date/time with the value in parameter.
      Parameters:
      dateTime - Value to move the date.
      Returns:
      The date/time moved.
    • reverse

      public DateTimeValue reverse()
      Returns the reverse of the date/time.
      Returns:
      The reverse.