Skip to content

Commit

Permalink
Resolve requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
warriorzz committed Sep 3, 2021
1 parent 92a92aa commit fadc944
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions common/src/main/kotlin/DiscordTimestamp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ data class DiscordTimestamp(
operator fun plus(value: Long): DiscordTimestamp = DiscordTimestamp(time + value, style)
operator fun minus(value: Long): DiscordTimestamp = DiscordTimestamp(time - value, style)

override fun compareTo(other: DiscordTimestamp): Int = when {
time > other.time -> 1
time < other.time -> -1
else -> 0
}
override fun compareTo(other: DiscordTimestamp): Int = time.compareTo(other.time)

override fun toString() = value
}

fun LocalDateTime.toDiscordTimestamp(style: DiscordTimestampStyle? = null) =
DiscordTimestamp(toInstant(TimeZone.UTC).toEpochMilliseconds(), style ?: DiscordTimestampStyle.ShortDateTime)
fun LocalDateTime.toDiscordTimestamp(style: DiscordTimestampStyle = DiscordTimestampStyle.ShortDateTime) =
toInstant(TimeZone.UTC).toDiscordTimestamp(style)

fun Instant.toDiscordTimestamp(style: DiscordTimestampStyle? = null) =
DiscordTimestamp(toEpochMilliseconds(), style ?: DiscordTimestampStyle.ShortDateTime)
fun Instant.toDiscordTimestamp(style: DiscordTimestampStyle = DiscordTimestampStyle.ShortDateTime) =
DiscordTimestamp(toEpochMilliseconds(), style)

/**
* The class representing the [style of a timestamp](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles)
Expand Down

0 comments on commit fadc944

Please sign in to comment.