Skip to content

Commit 8cfed3b

Browse files
committed
Fix TimePeriodChain extremes after initialization
1 parent 6190d0c commit 8cfed3b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

Sources/SwiftDate/TimePeriod/Groups/TimePeriodChain.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ import Foundation
1818
/// Time period chains do not allow overlaps within their set of time periods.
1919
/// This type of group is ideal for modeling schedules like sequential meetings or appointments.
2020
open class TimePeriodChain: TimePeriodGroup {
21-
21+
22+
// MARK: - Initializers
23+
24+
public override init(_ periods: [TimePeriodProtocol]? = nil) {
25+
super.init(periods)
26+
27+
updateExtremes()
28+
}
29+
2230
// MARK: - Chain Existence Manipulation
2331

2432
/**

SwiftDate.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
3A825B6325FEC54700F21DB2 /* TestTimePeriodChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A825B4925FEC54100F21DB2 /* TestTimePeriodChain.swift */; };
11+
3A825B6425FEC54800F21DB2 /* TestTimePeriodChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A825B4925FEC54100F21DB2 /* TestTimePeriodChain.swift */; };
12+
3A825B6525FEC54800F21DB2 /* TestTimePeriodChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A825B4925FEC54100F21DB2 /* TestTimePeriodChain.swift */; };
1013
52D6D9871BEFF229002C0205 /* SwiftDate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* SwiftDate.framework */; };
1114
6434DD6120C7FAF6007626EF /* DateInRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6434DD6020C7FAF6007626EF /* DateInRegion.swift */; };
1215
6434DD6220C7FAF6007626EF /* DateInRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6434DD6020C7FAF6007626EF /* DateInRegion.swift */; };
@@ -258,6 +261,7 @@
258261
/* End PBXContainerItemProxy section */
259262

260263
/* Begin PBXFileReference section */
264+
3A825B4925FEC54100F21DB2 /* TestTimePeriodChain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTimePeriodChain.swift; sourceTree = "<group>"; };
261265
52D6D97C1BEFF229002C0205 /* SwiftDate.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftDate.framework; sourceTree = BUILT_PRODUCTS_DIR; };
262266
52D6D9861BEFF229002C0205 /* SwiftDate-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftDate-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
263267
52D6D9E21BEFFF6E002C0205 /* SwiftDate.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftDate.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -569,6 +573,7 @@
569573
64BAB12720E6411100FEED79 /* TestSwiftDate.swift */,
570574
647AD65B21F4851F00CF787E /* TestDataStructures.swift */,
571575
A89F3FAE22A00019002D1BD0 /* TestDate.swift */,
576+
3A825B4925FEC54100F21DB2 /* TestTimePeriodChain.swift */,
572577
);
573578
name = Tests;
574579
path = Tests/SwiftDateTests;
@@ -974,6 +979,7 @@
974979
64BAB12420E63A3A00FEED79 /* TestDateInRegion+Langs.swift in Sources */,
975980
647AD65C21F4851F00CF787E /* TestDataStructures.swift in Sources */,
976981
6439232220D912670098EC03 /* TestDateInRegion+Math.swift in Sources */,
982+
3A825B6525FEC54800F21DB2 /* TestTimePeriodChain.swift in Sources */,
977983
64EF3E0F20D65478002793C6 /* TestDateInRegion+Compare.swift in Sources */,
978984
6439232620D91D170098EC03 /* TestFormatters.swift in Sources */,
979985
64EF3E0B20D65329002793C6 /* TestDateInRegion+Create.swift in Sources */,
@@ -1163,6 +1169,7 @@
11631169
buildActionMask = 2147483647;
11641170
files = (
11651171
64BAB12520E63A3A00FEED79 /* TestDateInRegion+Langs.swift in Sources */,
1172+
3A825B6425FEC54800F21DB2 /* TestTimePeriodChain.swift in Sources */,
11661173
647AD65D21F4851F00CF787E /* TestDataStructures.swift in Sources */,
11671174
A89F3FAF22A00019002D1BD0 /* TestDate.swift in Sources */,
11681175
6439232320D912670098EC03 /* TestDateInRegion+Math.swift in Sources */,
@@ -1183,6 +1190,7 @@
11831190
64BAB12620E63A3A00FEED79 /* TestDateInRegion+Langs.swift in Sources */,
11841191
647AD65E21F4851F00CF787E /* TestDataStructures.swift in Sources */,
11851192
6439232420D912670098EC03 /* TestDateInRegion+Math.swift in Sources */,
1193+
3A825B6325FEC54700F21DB2 /* TestTimePeriodChain.swift in Sources */,
11861194
64EF3E1120D65478002793C6 /* TestDateInRegion+Compare.swift in Sources */,
11871195
6439232820D91D170098EC03 /* TestFormatters.swift in Sources */,
11881196
64EF3E0D20D65329002793C6 /* TestDateInRegion+Create.swift in Sources */,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// SwiftDate
3+
// Parse, validate, manipulate, and display dates, time and timezones in Swift
4+
//
5+
// Created by AsioOtus
6+
7+
//
8+
// Copyright © 2019 Daniele Margutti. Licensed under MIT License.
9+
//
10+
11+
import SwiftDate
12+
import XCTest
13+
14+
class TestTimePeriodChain: XCTestCase {
15+
let periods = [
16+
TimePeriod(start: .init(year: 2020, month: 2, day: 1), end: .init(year: 2020, month: 2, day: 28)),
17+
TimePeriod(start: .init(year: 2020, month: 3, day: 1), end: .init(year: 2020, month: 3, day: 31)),
18+
TimePeriod(start: .init(year: 2020, month: 4, day: 1), end: .init(year: 2020, month: 4, day: 30)),
19+
TimePeriod(start: .init(year: 2020, month: 5, day: 1), end: .init(year: 2020, month: 5, day: 31))
20+
]
21+
22+
func testInitialExtremes () {
23+
let chain = TimePeriodChain(periods)
24+
25+
XCTAssert(chain.start == periods.first!.start, "TimePeriodChain initial start not equals to source period start")
26+
XCTAssert(chain.end == periods.last!.end, "TimePeriodChain initial end not equals to source period end")
27+
}
28+
29+
}

0 commit comments

Comments
 (0)