jellyflood/Shared/Extensions/JellyfinAPI/ServerTicks.swift
Joe Kribs 0025422634
[iOS & tvOS] Upgrade SDK to 10.10 (#1463)
* Buildable!

* Update file names.

* Default sort to sort name NOT name.

* SessionInfoDto vs SessionInfo

* Targetting

* Fix many invalid `ItemSortBy` existing. Will need to revisit later to see which can still be used!

* ExtraTypes Patch.

* Move from Binding to OnChange. Tested and Working.

* Update README.md

Update README to use 10.10.6. Bumped up from 10.8.13

* Update to Main on https://github.com/jellyfin/jellyfin-sdk-swift.git

* Now using https://github.com/jellyfin/jellyfin-sdk-swift.git again!

* Paths.getUserViews() userId moved to parameters

* Fix ViewModels where -Dto suffixes were removed by https://github.com/jellyfin/Swiftfin/pull/1465 auto-merge.

* SupportedCaseIterable

* tvOS supportedCases fixes for build issue.

* cleanup

* update API to 0.5.1 and correct VideoRangeTypes.

* Remove deviceProfile.responseProfiles = videoPlayer.responseProfiles

* Second to last adjustment:
Resolved: // TODO: 10.10 - Filter to only valid SortBy's for each BaseItemKind.
Last outstanding item: // TODO: 10.10 - What should authenticationProviderID & passwordResetProviderID be?

* Trailers itemID must precede userID

* Force User Policy to exist.

---------

Co-authored-by: Ethan Pippin <ethanpippin2343@gmail.com>
2025-04-06 23:42:47 -04:00

89 lines
2.3 KiB
Swift

//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors
//
import Foundation
// TODO: remove and have sdk use strong types instead
typealias ServerTicks = Int
extension ServerTicks {
// MARK: - Conversion Constants
private static let ticksPerSecond = 10_000_000
private static let ticksPerMinute = 600_000_000
private static let ticksPerHour = 36_000_000_000
private static let ticksPerDay = 864_000_000_000
// MARK: - Initializers
init(_ ticks: Int? = nil) {
self = ticks ?? 0
}
init(seconds: Int? = nil) {
self = (seconds ?? 0) * ServerTicks.ticksPerSecond
}
init(minutes: Int? = nil) {
self = (minutes ?? 0) * ServerTicks.ticksPerMinute
}
init(hours: Int? = nil) {
self = (hours ?? 0) * ServerTicks.ticksPerHour
}
init(days: Int? = nil) {
self = (days ?? 0) * ServerTicks.ticksPerDay
}
init(timeInterval: TimeInterval? = nil) {
self = Int((timeInterval ?? 0) * Double(ServerTicks.ticksPerSecond))
}
init(date: Date) {
let components = Calendar.current.dateComponents([.hour, .minute], from: date)
let hour = components.hour ?? 0
let minute = components.minute ?? 0
let totalSeconds = TimeInterval(hour * 3600 + minute * 60)
self = Int(totalSeconds * 10_000_000)
}
// MARK: - Computed Properties
var ticks: Int {
self
}
var seconds: TimeInterval {
TimeInterval(self) / Double(ServerTicks.ticksPerSecond)
}
var minutes: TimeInterval {
TimeInterval(self) / Double(ServerTicks.ticksPerMinute)
}
var hours: TimeInterval {
TimeInterval(self) / Double(ServerTicks.ticksPerHour)
}
var days: TimeInterval {
TimeInterval(self) / Double(ServerTicks.ticksPerDay)
}
var date: Date {
let totalSeconds = TimeInterval(self) / 10_000_000
let hours = Int(totalSeconds) / 3600
let minutes = (Int(totalSeconds) % 3600) / 60
var components = DateComponents()
components.hour = hours
components.minute = minutes
return Calendar.current.date(from: components) ?? Date()
}
}