ChronoContainer

Class storing time units against values, to be applied to a time later on.

This is intended as a way to apply a mixed-unit duration to a time when you don't actually know what time you'll be applying it to. This is more accurate than straight up returning Java java.time.Duration objects, which can only store a count of seconds.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun <T : Temporal> apply(target: T): T

Given a Temporal subclass, apply the values in this container to it and return the result.

Link copied to clipboard

Create a new ChronoContainer using the values from this one.

Link copied to clipboard
fun copyFrom(duration: Duration)

Given a Duration, replace all time-relevant values with values contained within the passed object.

fun copyFrom(period: Period)

Given a Period, replace all date-relevant values with values contained within the passed object.

fun copyFrom(duration: Duration, period: Period)

Given a Duration and Period, replace all values in this container with values contained within the passed objects.

Link copied to clipboard
fun get(unit: ChronoUnit): Long

Get the stored value for a given supported ChronoUnit, additionally returning 0 if no value is found.

Link copied to clipboard

Check whether a given ChronoUnit will be converted in plus, minus and set.

Link copied to clipboard

Check whether this container contains a positive set of values.

Link copied to clipboard

Check whether a given ChronoUnit is fully supported.

Link copied to clipboard
fun minus(value: Long, unit: ChronoUnit)

Given a value and ChronoUnit, subtract it from this container's collection of values.

Link copied to clipboard
fun normalize(dateTime: LocalDateTime = LocalDateTime.now())

Given a LocalDateTime (defaulting to now()), normalize the stored values by applying them to the datetime and calculating their real-world difference. This will replace all stored values with newly-normalized values.

Link copied to clipboard
fun plus(value: Long, unit: ChronoUnit)

Given a value and ChronoUnit, add it to this container's collection of values.

Link copied to clipboard
fun set(value: Long, unit: ChronoUnit)

Given a value and ChronoUnit, replace any stored value for that unit with the given value.

Link copied to clipboard
suspend fun ChronoContainer.toHuman(context: CommandContext, relativeTo: LocalDateTime = LocalDateTime.now()): String?
fun ChronoContainer.toHuman(locale: Locale, relativeTo: LocalDateTime = LocalDateTime.now()): String?

Given a Duration, this function will return a String (or null if it represents less than 1 second).