java.lang.Object
java.lang.Record
dev.hloth.zgztransport.CardDateTime
- Record Components:
date- the packed date, bytes 0 and 1time- 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 -
Constructor Summary
ConstructorsConstructorDescriptionCardDateTime(CardDate date, LocalTime time) Checks that both fields are present and that the time has no fraction of a second. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(CardDateTime other) date()Returns the value of thedaterecord component.static CardDateTimedecode(byte[] bytes) Decodes the five bytes of a packed date and time.byte[]encode()Encodes this date and time into five bytes.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static CardDateTimeof(int year, int month, int day, int hour, int minute, int second) Builds a date and time from its fields.time()Returns the value of thetimerecord component.toString()The date and time inYYYY-MM-DD HH:MM:SSform, with the seconds always written.
-
Field Details
-
BYTES
public static final int BYTESBytes a date and time take.- See Also:
-
-
Constructor Details
-
CardDateTime
Checks that both fields are present and that the time has no fraction of a second.- Throws:
IllegalArgumentException- if the time carries nanoseconds, which the card cannot holdNullPointerException- if a field is null
-
-
Method Details
-
of
Builds a date and time from its fields.- Parameters:
year-2000to2127month-1to12day-1to31hour-0to23minute-0to59second-0to59- Returns:
- the date and time
- Throws:
IllegalArgumentException- if a field is outside its range
-
decode
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. -
compareTo
- Specified by:
compareToin interfaceComparable<CardDateTime>
-
toString
The date and time inYYYY-MM-DD HH:MM:SSform, with the seconds always written. -
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. -
equals
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 withObjects::equals(Object,Object). -
date
Returns the value of thedaterecord component.- Returns:
- the value of the
daterecord component
-
time
Returns the value of thetimerecord component.- Returns:
- the value of the
timerecord component
-