Timestamp

class Timestamp(value: String = "1970-01-01 00:00:00.000") : State(source)

A textual representation of a moment in time, with additional support handling invalid user inputs and for the special timestamp NOW. Allowing invalid user inputs to be stored in a Timestamp ensures that com.fwdekker.randomness.ui.JDateTimeField does not reset the input field after an invalid input has been written.

A Timestamp is similar in function to LocalDateTime: Both represent the notation of time rather than the moment in time itself, and neither supports timezones. The most important differences with LocalDateTime are that the Timestamp's value is not guaranteed to be valid, and that the Timestamp's value may be the special value NOW. Call doValidate to determine if (and why) the value is (in)valid.

The canonical format for the value is defined by FORMAT. However, values are interpreted quite liberally, so a value that deviates from FORMAT may still be valid. For example, a value of 5819 is equivalent to a value of 5819-01-01 00:00:00.000. This liberal interpretation is performed by DateParserUtils. The constructor of Timestamp proactively reformats the value into the FORMAT. Therefore, a Timestamp contains a valid value if and only if value matches the FORMAT after the constructor completes. The only exception is for the case-sensitive special value, which always refers to the current moment in time, is never re-formatted, and is always valid.

To represent a Timestamp which is guaranteed to be valid, use LocalDateTime instead.

Note that this class is not a data class. This is because the value field must be re-formatted in the constructor, but the field must also remain immutable. This requirement cannot be fulfilled with a data class.

Constructors

Link copied to clipboard
constructor(value: String = "1970-01-01 00:00:00.000")

Types

Link copied to clipboard
object Companion

Holds constants.

Properties

Link copied to clipboard
private val _epochMilli: Long?

The cached value of epochMilli, or null if value is invalid or if value is NOW.

Link copied to clipboard
val epochMilli: Long?

The epoch millisecond representation of value, or null if value is invalid.

Link copied to clipboard
open override val validators: List<Validator<*>>

Lists the Validators relevant to this State.

Link copied to clipboard
val value: String

The textual representation of the timestamp.

Functions

Link copied to clipboard
open override fun deepCopy(retainUuid: Boolean): Timestamp

Returns a deep copy, retaining the uuid if and only if retainUuid is true.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Returns true if and only if this and other refer to the exact same moment in time.

Link copied to clipboard
open override fun hashCode(): Int

Returns the hash code of this timestamp.

Link copied to clipboard
fun isBefore(that: Timestamp): Boolean

Returns true if this occurs before that, and returns false otherwise.

Link copied to clipboard
open override fun toString(): String

Returns the string representation of this timestamp, exactly like a data class would.