influxdata / influxdb-client-swift

InfluxDB (v2+) Client Library for Swift
https://influxdata.github.io/influxdb-client-swift/
MIT License
27 stars 8 forks source link

Make OpenISO8601DateFormatter accessible in InfluxDBSwift #62

Closed timbms closed 1 year ago

timbms commented 1 year ago

Proposal: Make OpenISO8601DateFormatter part of InfluxDBSwift

Current behavior: Preparing a flux query frequently requires setting start/stop from Date |> range(start: \(formatter.string(from: startDate)) , stop: \(formatter.string(from: endDate)) ) The formatter needs to adhere to the InfluxDB specs.

Desired behavior: Access OpenISO8601DateFormatter without the need to recreate in program.

Use case: Convenience for API

timbms commented 1 year ago

For my app with a target of iOS version > 15, I switched to the Foundation Formatter API

        let isoFormatStyle: Date.ISO8601FormatStyle = .iso8601
            .day()
            .month()
            .year()
            .time(includingFractionalSeconds: true)
            .timeZone(separator: .omitted)

        let startDateString = startDate.formatted(isoFormatStyle)
        let endDateString = endDate.formatted(isoFormatStyle)

        var query = """
        from(bucket: "\(bucket)")
            |> range(start: \(startDateString), stop: \(endDateString))

Therefore, the issue can be closed.