Timestamp

一个 时间戳

通常情况下,secondmillisecond 得到-1的值,那么就说明此时间戳并不是一个真正的时间戳, 而是一个不被支持的默认值。 通过 Timestamp 你可以直接通过 isSupport 对支持情况进行判断。

简单包装器

Timestamp 是一种简单包装器类型,因此建议那些对外公开的 Timestamp 属性使用 即用即造 的形式,即不会急切的初始化属性, 而是每次获取时临时创建。

例如:

val container = ...

// 下面会产生3个 Timestamp 对象
useTimestamp(container.timestamp)
useTimestamp(container.timestamp)
useTimestamp(container.timestamp)

也因此,大多数通过属性获取 Timestamp 的情况下建议通过局部变量保存以复用。

val container = ...
val timestamp = container.timestamp

// 重复利用
useTimestamp(timestamp)
useTimestamp(timestamp)
useTimestamp(timestamp)

属性委托

面向公开属性的场景 Timestamp 提供了一些更简便的属性委托API来简化代码。 有关它们的说明参考 TimestampDelegate.getValue

Author

ForteScarlet

See also

Inheritors

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard

一个代表"不支持"的时间戳类型.

Properties

Link copied to clipboard

将当前时间戳实例转化为 Instant。 如果 Timestamp 满足 isSupport != true,则会得到 Instant.EPOCH

Link copied to clipboard
abstract val millisecond: Long

此时间戳对应的毫秒值。

Link copied to clipboard
abstract val second: Long

此时间戳对应的秒。

Functions

Link copied to clipboard
abstract operator fun compareTo(other: Timestamp): Int
Link copied to clipboard

是否不支持的 timestamp。等同于 isSupport != true。

Link copied to clipboard
abstract fun isSupport(): Boolean

此时间戳是否是一个被支持的真实时间戳。 如果得到false,则代表此时间戳本质上不存在, 且上述 secondmillisecond 最终结果应为-1。