Skip to content

Feature Request: truncateTo for LocalTime #225

Closed as not planned
Closed as not planned
@Stephen-Hamilton-C

Description

@Stephen-Hamilton-C

When I was learning Kotlin, I made a JVM application that utilized the java.time.LocalTime class a lot, and it was convenient to use the truncateTo() method to only have hours and minutes. I'm now rewriting the application in Kotlin Native to get even more experience with the language, and I'm learning that to shave off seconds, I need to have an extra variable to truncate a LocalTime:

/**
 * The current system time, with seconds and nanoseconds
 */
private val untrimmedNow: LocalTime = Clock.System.now()
        .toLocalDateTime(TimeZone.currentSystemDefault()).time

/**
 * The current system time without seconds.
 */
val NOW: LocalTime = LocalTime(untrimmedNow.hour, untrimmedNow.minute)

While this works, I'd much rather only have to add one more line, something like .truncateTo(DateTimeUnit.SECOND).

Metadata

Metadata

Assignees

No one assigned

    Labels

    formattersRelated to parsing and formatting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions