Skip to content

Make it easier to get the local Date #6

@dalewking

Description

@dalewking

As we have found out the hard way getting the current local Date with Klock is kind of verbose and if you are not careful you can get the date in UTC which can differ from local Date for part of the day.

One might think that DateTime.now().date would be correct but that is the date in UTC. If you are familiar with DateTime vs. DateTimeTz one might think that you should do DateTime.nowLocal().date or DateTimeTz.now().date but those don't compile because for no discernible reason DateTimeTz does not have a date property like DateTime does. So one starting point is just add that. Without it it requires sticking a .local in there to convert to a DateTime to be able to get the Date

In our project I added some extension properties to get the local date, but it would be nice if Klock did something similar:

val DateTimeTz.date get() = local.date
val Date.Companion.today get() = DateTime.nowLocal().date

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Pending

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions