Record Class CardDateTime

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.CardDateTime
Record Components:
date - the packed date, bytes 0 and 1
time - the time of day, bytes 2 to 4, whole seconds
All Implemented Interfaces:
Encodable, Comparable<CardDateTime>

public record CardDateTime(CardDate date, LocalTime time) extends Record implements Comparable<CardDateTime>, Encodable
A CardDate followed by a time of day, five bytes in total: the packed date, then hour, minute and second as plain binary.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Bytes a date and time take.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Checks that both fields are present and that the time has no fraction of a second.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    Returns the value of the date record component.
    decode(byte[] bytes)
    Decodes the five bytes of a packed date and time.
    byte[]
    Encodes this date and time into five bytes.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    of(int year, int month, int day, int hour, int minute, int second)
    Builds a date and time from its fields.
    Returns the value of the time record component.
    The date and time in YYYY-MM-DD HH:MM:SS form, with the seconds always written.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static CardDateTime of(int year, int month, int day, int hour, int minute, int second)
      Builds a date and time from its fields.
      Parameters:
      year - 2000 to 2127
      month - 1 to 12
      day - 1 to 31
      hour - 0 to 23
      minute - 0 to 59
      second - 0 to 59
      Returns:
      the date and time
      Throws:
      IllegalArgumentException - if a field is outside its range
    • decode

      public static CardDateTime decode(byte[] bytes)
      Decodes the five bytes of a packed date and time.
      Parameters:
      bytes - the five bytes
      Returns:
      the date and time they hold
      Throws:
      CardFormatException - if the input is not five bytes or a field is outside its range
    • encode

      public byte[] encode()
      Encodes this date and time into five bytes.
      Specified by:
      encode in interface Encodable
      Returns:
      the five bytes
    • compareTo

      public int compareTo(CardDateTime other)
      Specified by:
      compareTo in interface Comparable<CardDateTime>
    • toString

      public String toString()
      The date and time in YYYY-MM-DD HH:MM:SS form, with the seconds always written.
      Specified by:
      toString in class Record
      Returns:
      the printed date and time
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • date

      public CardDate date()
      Returns the value of the date record component.
      Returns:
      the value of the date record component
    • time

      public LocalTime time()
      Returns the value of the time record component.
      Returns:
      the value of the time record component