Skip to content

Commit

Permalink
Patch 1.0.2
Browse files Browse the repository at this point in the history
feat:
- MTime initialiser made public
  • Loading branch information
FulcrumOne authored Aug 17, 2024
1 parent 07a27a9 commit 93fe777
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MijickTimer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |s|
s.summary = 'Modern API for Timer'
s.description = 'MijickTimer is a free, open-source library for the Swift language that makes the process of managing timers much easier and clearer.'

s.version = '1.0.1'
s.version = '1.0.2'
s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
s.swift_version = '5.0'
Expand Down
15 changes: 0 additions & 15 deletions Sources/Internal/MTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ public struct MTime: Equatable {
public let seconds: Int
public let milliseconds: Int
}
extension MTime {
init(_ timeInterval: TimeInterval) {
let millisecondsInt = Int(timeInterval * 1000)

let hoursDiv = 1000 * 60 * 60
let minutesDiv = 1000 * 60
let secondsDiv = 1000
let millisecondsDiv = 1

hours = millisecondsInt / hoursDiv
minutes = (millisecondsInt % hoursDiv) / minutesDiv
seconds = (millisecondsInt % hoursDiv % minutesDiv) / secondsDiv
milliseconds = (millisecondsInt % hoursDiv % minutesDiv % secondsDiv) / millisecondsDiv
}
}

// MARK: - Helpers
extension MTime {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/MTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private extension MTimer {
onTimerActivityChange?(isTimerRunning)
}}
func publishRunningTimeChange() { DispatchQueue.main.async { [self] in
onRunningTimeChange?(.init(runningTime))
onRunningTimeChange?(.init(timeInterval: runningTime))
onTimerProgressChange?(calculateTimerProgress())
}}
}
Expand Down
15 changes: 14 additions & 1 deletion Sources/Public/Public+MTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ extension MTime {
let millisecondsInterval = Double(milliseconds) / 1000

let timeInterval = hoursInterval + minutesInterval + secondsInterval + millisecondsInterval
self.init(timeInterval)
self.init(timeInterval: timeInterval)
}
public init(timeInterval: TimeInterval) {
let millisecondsInt = Int(timeInterval * 1000)

let hoursDiv = 1000 * 60 * 60
let minutesDiv = 1000 * 60
let secondsDiv = 1000
let millisecondsDiv = 1

hours = millisecondsInt / hoursDiv
minutes = (millisecondsInt % hoursDiv) / minutesDiv
seconds = (millisecondsInt % hoursDiv % minutesDiv) / secondsDiv
milliseconds = (millisecondsInt % hoursDiv % minutesDiv % secondsDiv) / millisecondsDiv
}
public static var zero: MTime { .init() }
public static var max: MTime { .init(hours: 60 * 60 * 24 * 365 * 100) }
Expand Down

0 comments on commit 93fe777

Please sign in to comment.