CoatyTimeInterval

public class CoatyTimeInterval : Codable

Defines a time interval using the number of milliseconds since the epoc in UTC instead of ISO 8601 standard time intervals. This is used for consistency within the system.

A valid interval can have four formats:

  • start and end timestamps
  • start timestamp and duration
  • duration and end timestamp
  • duration only

Four different initializers, one for each format case ensure that this object always has a correct format.

The ISO 8601 standard string can be created using the function toLocalTimeIntervalIsoString which is a part of this class.

Initializers.

    1. format case: start and end given

    Declaration

    Swift

    public init(start: Int, end: Int)
    1. format case: start and duration

    Declaration

    Swift

    public init(start: Int, duration: Int)
    1. format case: duration and end

    Declaration

    Swift

    public init(duration: Int, end: Int)
    1. format case: duration

    Declaration

    Swift

    public init(duration: Int)

Public functions.

  • Returns a string in ISO 8601 format for a time interval including timezone offset information.

    Declaration

    Swift

    public func toLocalIntervalIsoString(includeMillis: Bool? = false) -> String

    Parameters

    interval

    a TimeInterval object

    includeMillis

    whether to include milliseconds in the string (defaults to false)

  • Returns a string in ISO 8601 format for a duration.

    Declaration

    Swift

    public static func toDurationIsoString(duration: Int) throws -> String

    Parameters

    duration

    a duration given in milliseconds

  • Returns a string in ISO 8601 format including timezone offset information.

    Declaration

    Swift

    public static func toLocalIsoString(date: Date, includeMilis: Bool? = false) -> String

    Parameters

    date

    a Date object

    includeMillis

    whether to include milliseconds in the string (defaults to false) NOTE: This code has not been verified to always yield the correct representation of the date. Use with caution.