Skip to content

Add unambiguous LocalDateTime.toInstant #461

@simonolander

Description

@simonolander

As the documentation states, the function LocalDateTime.toInstant(timeZone: TimeZone) can be ambiguous.

Returns an instant that corresponds to this civil date/time value in the specified timeZone.

Note that the conversion is not always well-defined. There can be the following possible situations:

  • There's only one instant that has this date/time value in the timeZone. In this case, the conversion is unambiguous.
  • There's no instant that has this date/time value in the timeZone. Such a situation appears when the time zone experiences a transition from a lesser to a greater offset. In this case, the conversion is performed with the lesser (earlier) offset, as if the time gap didn't occur yet.
  • There are two possible instants that can have this date/time components in the timeZone. In this case, the earlier instant is returned.

I would be greatly helped by a function that returns all the instants that correspond to the LocalDateTime in the specified time zone. For example something with the following signature:

fun LocalDateTime.toInstants(timeZone: TimeZone): List<Instant>

If there is no such instant, the resulting list would be empty.

Would you consider adding this to the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions