Skip to content

//core/io.islandtime.ranges/toZonedDateTimeInterval

toZonedDateTimeInterval

common

fun OffsetDateTimeInterval.toZonedDateTimeInterval(zone: TimeZone, strategy: OffsetConversionStrategy): ZonedDateTimeInterval

Converts this interval to a ZonedDateTimeInterval using the specified strategy to adjust each endpoint to a valid date, time, and offset in zone.

  • [OffsetConversionStrategy.PRESERVE_INSTANT](../io.islandtime/-offset-conversion-strategy/-p-r-e-s-e-r-v-e_-i-n-s-t-a-n-t/index.md) - Preserve the instant captured by the date, time, and offset, ignoring the local time.
  • [OffsetConversionStrategy.PRESERVE_LOCAL_TIME](../io.islandtime/-offset-conversion-strategy/-p-r-e-s-e-r-v-e_-l-o-c-a-l_-t-i-m-e/index.md) - Preserve the local date and time in the new time zone, adjusting the offset if needed.

Alternatively, you can use asZonedDateTimeInterval to convert each endpoint to a ZonedDateTime with an equivalent fixed-offset zone. However, this comes with the caveat that a fixed-offset zone lacks knowledge of any region and will not respond to daylight savings time changes.

See also

asZonedDateTimeInterval

common

fun String.toZonedDateTimeInterval(): ZonedDateTimeInterval

Converts a string to a ZonedDateTimeInterval.

The string is assumed to be an ISO-8601 time interval representation in extended format. The output of ZonedDateTimeInterval.toString can be safely parsed using this method.

Examples:

  • `1990-01-04T03-05[America/New_York]/1991-08-30T15:30:05.123-04:00`
  • `../1991-08-30T15:30:05.123-04:00`
  • `1990-01-04T03-05[Europe/London]/..`
  • `../..`
  • (empty string)

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed time is invalid

common

fun String.toZonedDateTimeInterval(parser: GroupedDateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): ZonedDateTimeInterval

Converts a string to a ZonedDateTimeInterval using a specific parser.

A set of predefined parsers can be found in DateTimeParsers.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed interval is invalid