Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 2.0.0 #10

Merged
merged 46 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ef29db6
1
jay-jay-lama Nov 22, 2024
b68abb6
1
jay-jay-lama Nov 22, 2024
89f44a8
1
jay-jay-lama Nov 23, 2024
305a70e
1
jay-jay-lama Nov 23, 2024
cddf0db
Renames
jay-jay-lama Nov 23, 2024
4fe63eb
1
jay-jay-lama Nov 23, 2024
d8c9224
1
jay-jay-lama Nov 23, 2024
eddd62a
1
jay-jay-lama Nov 23, 2024
11e7129
1
jay-jay-lama Nov 23, 2024
3b613c1
1
jay-jay-lama Nov 23, 2024
dfe6f38
1
jay-jay-lama Nov 23, 2024
d08a1b8
1
jay-jay-lama Nov 23, 2024
63992a8
1
jay-jay-lama Nov 23, 2024
b3b9001
1
jay-jay-lama Nov 23, 2024
6b5f0d4
1
jay-jay-lama Nov 23, 2024
552a0f8
1
jay-jay-lama Nov 23, 2024
7a67e98
1
jay-jay-lama Nov 23, 2024
82e33e6
1
jay-jay-lama Nov 23, 2024
fcd8bd7
1
jay-jay-lama Nov 23, 2024
7b0d426
1
jay-jay-lama Nov 23, 2024
af9afad
1
jay-jay-lama Nov 23, 2024
383c2e9
1
jay-jay-lama Nov 23, 2024
5a6624d
1
jay-jay-lama Nov 24, 2024
0eaa34f
1
jay-jay-lama Nov 25, 2024
f564d37
1
jay-jay-lama Nov 25, 2024
4b11347
1
jay-jay-lama Nov 25, 2024
cb58f85
1
jay-jay-lama Nov 28, 2024
e4580d2
Adding some constraints on status change
jay-jay-lama Dec 3, 2024
d426078
1
jay-jay-lama Dec 4, 2024
2a224d8
README Updated
jay-jay-lama Dec 10, 2024
369af69
Update LICENSE
jay-jay-lama Dec 10, 2024
e0ab640
Update LICENSE
jay-jay-lama Dec 10, 2024
062e3c4
1
jay-jay-lama Dec 10, 2024
bcbaa5d
Update README.md
jay-jay-lama Dec 10, 2024
eb3378e
Added visionOS support
jay-jay-lama Dec 11, 2024
3039bff
1
jay-jay-lama Dec 11, 2024
4fcd6ed
1
jay-jay-lama Dec 11, 2024
53ce14e
Update README.md
jay-jay-lama Dec 11, 2024
4ad854e
Update README.md
jay-jay-lama Dec 12, 2024
9d819c2
Update README.md
jay-jay-lama Dec 12, 2024
0dc8adf
Update README.md
jay-jay-lama Dec 12, 2024
86264cb
Issue templates updated
jay-jay-lama Dec 12, 2024
c76296a
Update README.md
jay-jay-lama Dec 12, 2024
d612e61
Update README.md
jay-jay-lama Dec 12, 2024
1d4ab0d
Pod update
jay-jay-lama Dec 12, 2024
7340eda
Merge branch 'patch-2.0.0' of github.com:Mijick/Timer into patch-2.0.0
jay-jay-lama Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1
  • Loading branch information
jay-jay-lama committed Dec 4, 2024
commit d426078f5a3f59084ae833f46cda879c22c18049
4 changes: 2 additions & 2 deletions Sources/Internal/Helpers/MTimerValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class MTimerValidator {
static func checkRequirementsForStartingTimer(_ startTime: TimeInterval, _ endTime: TimeInterval, _ state: MTimerStateManager, _ status: MTimerStatus) throws {
if startTime < 0 || endTime < 0 { throw MTimerError.timeCannotBeLessThanZero }
if startTime == endTime { throw MTimerError.startTimeCannotBeTheSameAsEndTime }
if status == .inProgress && state.backgroundTransitionDate == nil { throw MTimerError.timerIsAlreadyRunning }
if status == .running && state.backgroundTransitionDate == nil { throw MTimerError.timerIsAlreadyRunning }
}
static func checkRequirementsForResumingTimer(_ callbacks: MTimerCallbacks) throws {
if callbacks.onRunningTimeChange == nil { throw MTimerError.cannotResumeNotInitialisedTimer }
}
static func isCanBeSkipped(_ timerStatus: MTimerStatus) throws {
if timerStatus == .inProgress || timerStatus == .paused { return }
if timerStatus == .running || timerStatus == .paused { return }
throw MTimerError.timerIsNotStarted
}
}
6 changes: 3 additions & 3 deletions Sources/Internal/MTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ extension MTimer {
resetTimerPublishers()
}
func startTimer() {
handleTimer(status: .inProgress)
handleTimer(status: .running)
}
}

// MARK: - Timer State Control
extension MTimer {
func pauseTimer() { handleTimer(status: .paused) }
func cancelTimer() { handleTimer(status: .cancelled) }
func cancelTimer() { handleTimer(status: .notStarted) }
func finishTimer() { handleTimer(status: .finished) }
}

Expand All @@ -79,7 +79,7 @@ extension MTimer {

// MARK: - Handling Timer
private extension MTimer {
func handleTimer(status: MTimerStatus) { if status != .inProgress || configuration.canTimerBeStarted {
func handleTimer(status: MTimerStatus) { if status != .running || configuration.canTimerBeStarted {
timerStatus = status
updateInternalTimer(isTimerRunning)
updateObservers(isTimerRunning)
Expand Down
16 changes: 4 additions & 12 deletions Sources/Public/Enumerations/Public+MTimerStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ public enum MTimerStatus {
/// - ``MTimer/start()``
/// - ``MTimer/start(from:to:)-1mvp1``
/// - ``MTimer/resume()``
case inProgress

/// Timer was stopped/cancelled
///
/// ## Triggered by methods
/// - ``MTimer/cancel()``
case cancelled
case running

/// Timer is in a pause
///
Expand All @@ -38,10 +32,8 @@ public enum MTimerStatus {
case finished
}


extension MTimerStatus {
var isTimerRunning: Bool { self == .inProgress }
var isNeededReset: Bool { self == .notStarted || self == .finished || self == .cancelled }
var isSkippable: Bool { self == .inProgress || self == .paused }
var isCancellable: Bool { self == .inProgress || self == .paused }
var isTimerRunning: Bool { self == .running }
var isNeededReset: Bool { self == .notStarted || self == .finished }
var isSkippable: Bool { self == .running || self == .paused }
}
3 changes: 1 addition & 2 deletions Sources/Public/Public+MTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public extension MTimer {
public extension MTimer {
/// Pause the timer.
func pause() {
guard timerStatus == .inProgress else { return }
guard timerStatus == .running else { return }
pauseTimer()
}
}
Expand All @@ -114,7 +114,6 @@ public extension MTimer {
public extension MTimer {
/// Stops the timer and resets its current time to the initial value.
func cancel() {
guard timerStatus.isCancellable else { return }
resetRunningTime()
cancelTimer()
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/MTimerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension MTimerTests {
wait(for: defaultWaitingTime)

XCTAssertGreaterThan(currentTime, 0)
XCTAssertEqual(.inProgress, timer.timerStatus)
XCTAssertEqual(.running, timer.timerStatus)
}
func testTimerIsCancellable() {
try! defaultTimer.start()
Expand All @@ -40,7 +40,7 @@ extension MTimerTests {
wait(for: defaultWaitingTime)

XCTAssertEqual(timeAfterStop, currentTime)
XCTAssertEqual(.cancelled, timer.timerStatus)
XCTAssertEqual(.notStarted, timer.timerStatus)
}
func testTimerIsResetable() {
let startTime: TimeInterval = 3
Expand Down Expand Up @@ -81,7 +81,7 @@ extension MTimerTests {
wait(for: defaultWaitingTime)

XCTAssertNotEqual(timeAfterStop, currentTime)
XCTAssertEqual(.inProgress, timer.timerStatus)
XCTAssertEqual(.running, timer.timerStatus)
}
}

Expand All @@ -108,7 +108,7 @@ extension MTimerTests {
XCTAssertLessThan(currentTime, 3)
}
func testTimerPublishesStatuses() {
var statuses: [MTimerStatus: Bool] = [.inProgress: false, .cancelled: false]
var statuses: [MTimerStatus: Bool] = [.running: false, .notStarted: false]

try! defaultTimer
.onTimerStatusChange { statuses[$0] = true }
Expand Down