Skip to content

Commit a2f2bf4

Browse files
committed
Fixed adding()/subtracting(). Removed time value category methods: timecode(at:base:limit:) and timecode(using:)
1 parent fc4a1c8 commit a2f2bf4

File tree

56 files changed

+694
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+694
-1040
lines changed

Sources/TimecodeKit/API Evolution/API-2.0.0.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -423,28 +423,6 @@ extension Timecode {
423423
}
424424

425425
extension Timecode.Components {
426-
@available(*, deprecated, renamed: "timecode(at:base:limit:)")
427-
public func toTimecode(
428-
at rate: TimecodeFrameRate,
429-
limit: Timecode.UpperLimit = .max24Hours,
430-
base: Timecode.SubFramesBase = .default(),
431-
format: Timecode.StringFormat = .default()
432-
) throws -> Timecode {
433-
let properties = Timecode.Properties(rate: rate, base: base, limit: limit)
434-
return try timecode(using: properties)
435-
}
436-
437-
@available(*, deprecated, message: "Renamed to timecode(at:base:limit: by: .allowingInvalid)")
438-
public func toTimecode(
439-
rawValuesAt rate: TimecodeFrameRate,
440-
limit: Timecode.UpperLimit = .max24Hours,
441-
base: Timecode.SubFramesBase = .default(),
442-
format: Timecode.StringFormat = .default()
443-
) -> Timecode {
444-
let properties = Timecode.Properties(rate: rate, base: base, limit: limit)
445-
return timecode(using: properties, by: .allowingInvalid)
446-
}
447-
448426
@available(*, deprecated, renamed: "invalidComponents(at:base:limit:)")
449427
public func invalidComponents(
450428
at rate: TimecodeFrameRate,

Sources/TimecodeKit/Documentation.docc/TimecodeKit-2-Migration-Guide.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,18 @@ For value type reference, see the [Time Value Types](#Time-Value-Types) section
150150

151151
For timecode validation rules reference, see the [Timecode Validation](#Timecode-Validation) section above.
152152

153-
## Functional Shorthand
153+
## Removal Functional Shorthand
154154

155-
The time value category method `toTimecode(...)` has been renamed to `timecode(...)`.
155+
For technical reasons and to avoid ambiguity for time value types that are common types (such as TimeInterval aka Double),
156+
the `toTimecode(...)` category methods have been removed.
156157

157158
For example:
158159

159160
```swift
160161
// 1.x API
161162
try "01:00:00:00".toTimecode(at: ._24)
162163
// 2.x API
163-
try "01:00:00:00".timecode(at: .fps24)
164+
// (removed)
164165
```
165166

166167
## Enum Case Respellings

Sources/TimecodeKit/Timecode/Math/Timecode Math Internal.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,11 @@ extension Timecode {
571571
func _offset(to other: Components) -> TimecodeInterval {
572572
if components == other {
573573
return TimecodeInterval(
574-
Timecode.Components.zero.timecode(
574+
Timecode(
575+
.zero,
575576
at: frameRate,
576577
base: subFramesBase,
577-
limit: upperLimit,
578-
by: .allowingInvalid
578+
limit: upperLimit
579579
),
580580
.plus
581581
)
@@ -595,7 +595,8 @@ extension Timecode {
595595
from: otherTimecode.components
596596
)
597597

598-
let deltaTC = diff.timecode(
598+
let deltaTC = Timecode(
599+
.components(diff),
599600
using: properties,
600601
by: .allowingInvalid
601602
)
@@ -610,7 +611,8 @@ extension Timecode {
610611
from: components
611612
)
612613

613-
let deltaTC = diff.timecode(
614+
let deltaTC = Timecode(
615+
.components(diff),
614616
using: properties,
615617
by: .allowingInvalid
616618
)

Sources/TimecodeKit/Timecode/Math/Timecode Math Public.swift

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,79 +174,79 @@ extension Timecode {
174174
/// Add a duration to the current timecode and return a new instance.
175175
///
176176
/// - Throws: ``ValidationError``
177-
public mutating func adding(_ other: TimecodeSourceValue) throws -> Timecode {
177+
public func adding(_ other: TimecodeSourceValue) throws -> Timecode {
178178
let otherTC = try Timecode(other, using: properties)
179179
return try adding(otherTC)
180180
}
181181

182182
/// Add a duration to the current timecode and return a new instance.
183183
///
184184
/// - Throws: ``ValidationError``
185-
public mutating func adding(_ other: FormattedTimecodeSourceValue) throws -> Timecode {
185+
public func adding(_ other: FormattedTimecodeSourceValue) throws -> Timecode {
186186
let otherTC = try Timecode(other, using: properties)
187187
return try adding(otherTC)
188188
}
189189

190190
/// Add a duration to the current timecode and return a new instance.
191191
///
192192
/// - Throws: ``ValidationError``
193-
public mutating func adding(_ other: RichTimecodeSourceValue) throws -> Timecode {
193+
public func adding(_ other: RichTimecodeSourceValue) throws -> Timecode {
194194
let otherTC = try Timecode(other)
195195
return try adding(otherTC)
196196
}
197197

198198
/// Add a duration to the current timecode and return a new instance.
199199
///
200200
/// - Throws: ``ValidationError``
201-
public mutating func adding(_ other: GuaranteedTimecodeSourceValue) throws -> Timecode {
201+
public func adding(_ other: GuaranteedTimecodeSourceValue) throws -> Timecode {
202202
let otherTC = Timecode(other, using: properties)
203203
return try adding(otherTC)
204204
}
205205

206206
/// Add a duration to the current timecode and return a new instance.
207207
///
208208
/// - Throws: ``ValidationError``
209-
public mutating func adding(_ other: GuaranteedRichTimecodeSourceValue) throws -> Timecode {
209+
public func adding(_ other: GuaranteedRichTimecodeSourceValue) throws -> Timecode {
210210
let otherTC = Timecode(other)
211211
return try adding(otherTC)
212212
}
213213

214214
/// Add a duration to the current timecode and return a new instance.
215215
///
216216
/// - Throws: ``ValidationError``
217-
public mutating func adding(_ other: TimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
217+
public func adding(_ other: TimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
218218
let otherTC = try Timecode(other, using: properties)
219219
return try adding(otherTC, by: validation)
220220
}
221221

222222
/// Add a duration to the current timecode and return a new instance.
223223
///
224224
/// - Throws: ``ValidationError``
225-
public mutating func adding(_ other: FormattedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
225+
public func adding(_ other: FormattedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
226226
let otherTC = try Timecode(other, using: properties)
227227
return try adding(otherTC, by: validation)
228228
}
229229

230230
/// Add a duration to the current timecode and return a new instance.
231231
///
232232
/// - Throws: ``ValidationError``
233-
public mutating func adding(_ other: RichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
233+
public func adding(_ other: RichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
234234
let otherTC = try Timecode(other)
235235
return try adding(otherTC, by: validation)
236236
}
237237

238238
/// Add a duration to the current timecode and return a new instance.
239239
///
240240
/// - Throws: ``ValidationError``
241-
public mutating func adding(_ other: GuaranteedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
241+
public func adding(_ other: GuaranteedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
242242
let otherTC = Timecode(other, using: properties)
243243
return try adding(otherTC, by: validation)
244244
}
245245

246246
/// Add a duration to the current timecode and return a new instance.
247247
///
248248
/// - Throws: ``ValidationError``
249-
public mutating func adding(_ other: GuaranteedRichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
249+
public func adding(_ other: GuaranteedRichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
250250
let otherTC = Timecode(other)
251251
return try adding(otherTC, by: validation)
252252
}
@@ -440,79 +440,79 @@ extension Timecode {
440440
/// Subtract a duration from the current timecode and return a new instance.
441441
///
442442
/// - Throws: ``ValidationError``
443-
public mutating func subtracting(_ other: TimecodeSourceValue) throws -> Timecode {
443+
public func subtracting(_ other: TimecodeSourceValue) throws -> Timecode {
444444
let otherTC = try Timecode(other, using: properties)
445445
return try subtracting(otherTC)
446446
}
447447

448448
/// Subtract a duration from the current timecode and return a new instance.
449449
///
450450
/// - Throws: ``ValidationError``
451-
public mutating func subtracting(_ other: FormattedTimecodeSourceValue) throws -> Timecode {
451+
public func subtracting(_ other: FormattedTimecodeSourceValue) throws -> Timecode {
452452
let otherTC = try Timecode(other, using: properties)
453453
return try subtracting(otherTC)
454454
}
455455

456456
/// Subtract a duration from the current timecode and return a new instance.
457457
///
458458
/// - Throws: ``ValidationError``
459-
public mutating func subtracting(_ other: RichTimecodeSourceValue) throws -> Timecode {
459+
public func subtracting(_ other: RichTimecodeSourceValue) throws -> Timecode {
460460
let otherTC = try Timecode(other)
461461
return try subtracting(otherTC)
462462
}
463463

464464
/// Subtract a duration from the current timecode and return a new instance.
465465
///
466466
/// - Throws: ``ValidationError``
467-
public mutating func subtracting(_ other: GuaranteedTimecodeSourceValue) throws -> Timecode {
467+
public func subtracting(_ other: GuaranteedTimecodeSourceValue) throws -> Timecode {
468468
let otherTC = Timecode(other, using: properties)
469469
return try subtracting(otherTC)
470470
}
471471

472472
/// Subtract a duration from the current timecode and return a new instance.
473473
///
474474
/// - Throws: ``ValidationError``
475-
public mutating func subtracting(_ other: GuaranteedRichTimecodeSourceValue) throws -> Timecode {
475+
public func subtracting(_ other: GuaranteedRichTimecodeSourceValue) throws -> Timecode {
476476
let otherTC = Timecode(other)
477477
return try subtracting(otherTC)
478478
}
479479

480480
/// Subtract a duration from the current timecode and return a new instance.
481481
///
482482
/// - Throws: ``ValidationError``
483-
public mutating func subtracting(_ other: TimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
483+
public func subtracting(_ other: TimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
484484
let otherTC = try Timecode(other, using: properties)
485485
return try subtracting(otherTC, by: validation)
486486
}
487487

488488
/// Subtract a duration from the current timecode and return a new instance.
489489
///
490490
/// - Throws: ``ValidationError``
491-
public mutating func subtracting(_ other: FormattedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
491+
public func subtracting(_ other: FormattedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
492492
let otherTC = try Timecode(other, using: properties)
493493
return try subtracting(otherTC, by: validation)
494494
}
495495

496496
/// Subtract a duration from the current timecode and return a new instance.
497497
///
498498
/// - Throws: ``ValidationError``
499-
public mutating func subtracting(_ other: RichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
499+
public func subtracting(_ other: RichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
500500
let otherTC = try Timecode(other)
501501
return try subtracting(otherTC, by: validation)
502502
}
503503

504504
/// Subtract a duration from the current timecode and return a new instance.
505505
///
506506
/// - Throws: ``ValidationError``
507-
public mutating func subtracting(_ other: GuaranteedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
507+
public func subtracting(_ other: GuaranteedTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
508508
let otherTC = Timecode(other, using: properties)
509509
return try subtracting(otherTC, by: validation)
510510
}
511511

512512
/// Subtract a duration from the current timecode and return a new instance.
513513
///
514514
/// - Throws: ``ValidationError``
515-
public mutating func subtracting(_ other: GuaranteedRichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
515+
public func subtracting(_ other: GuaranteedRichTimecodeSourceValue, by validation: ValidationRule) throws -> Timecode {
516516
let otherTC = Timecode(other)
517517
return try subtracting(otherTC, by: validation)
518518
}
@@ -664,13 +664,13 @@ extension Timecode {
664664
// MARK: - Offset / TimecodeInterval
665665

666666
/// Offsets the current timecode by a delta amount.
667-
/// Wraps around the clock if needed, as set by the `upperLimit` property.
667+
/// Wraps around the clock if needed, as set by the ``upperLimit`` property.
668668
public mutating func offset(by interval: TimecodeInterval) {
669669
self = interval.timecode(offsetting: self)
670670
}
671671

672672
/// Returns the timecode offset by a delta amount.
673-
/// Wraps around the clock if needed, as set by the `upperLimit` property.
673+
/// Wraps around the clock if needed, as set by the ``upperLimit`` property.
674674
public func offsetting(by interval: TimecodeInterval) -> Timecode {
675675
interval.timecode(offsetting: self)
676676
}
@@ -682,24 +682,21 @@ extension Timecode {
682682
} else {
683683
guard let otherConverted = try? other.converted(to: frameRate) else {
684684
assertionFailure("Could not convert other Timecode to self Timecode frameRate.")
685-
return .init(
686-
Timecode.Components.zero
687-
.timecode(using: properties, by: .allowingInvalid)
688-
)
685+
return .init(Timecode(.zero, using: properties))
689686
}
690687

691688
return _offset(to: otherConverted.components)
692689
}
693690
}
694691

695-
/// Constructs a new `TimecodeInterval` instance from `self`.
692+
/// Constructs a new ``TimecodeInterval`` instance from `self`.
696693
public func asInterval(_ sign: FloatingPointSign = .plus) -> TimecodeInterval {
697694
TimecodeInterval(self, sign)
698695
}
699696

700697
// MARK: - Convenience Attributes
701698

702-
/// Returns `true` if timecode including subframes is zero (00:00:00:00.00).
699+
/// Returns `true` if timecode (including subframes) is zero (00:00:00:00.00).
703700
public var isZero: Bool {
704701
frameCount.isZero
705702
}

0 commit comments

Comments
 (0)