@@ -109,149 +109,150 @@ class TestCalendar : TestCalendarSuper {
109
109
110
110
func test_properties( ) {
111
111
// Mainly we want to just make sure these go through to the NSCalendar implementation at this point.
112
-
113
- var c = Calendar ( identifier: . gregorian)
114
- // Use english localization
115
- c. locale = Locale ( identifier: " en_US " )
116
-
117
- expectEqual ( " AM " , c. amSymbol)
118
- expectEqual ( " PM " , c. pmSymbol)
119
- expectEqual ( [ " 1st quarter " , " 2nd quarter " , " 3rd quarter " , " 4th quarter " ] , c. quarterSymbols)
120
- expectEqual ( [ " 1st quarter " , " 2nd quarter " , " 3rd quarter " , " 4th quarter " ] , c. standaloneQuarterSymbols)
121
- expectEqual ( [ " BC " , " AD " ] , c. eraSymbols)
122
- expectEqual ( [ " Before Christ " , " Anno Domini " ] , c. longEraSymbols)
123
- expectEqual ( [ " J " , " F " , " M " , " A " , " M " , " J " , " J " , " A " , " S " , " O " , " N " , " D " ] , c. veryShortMonthSymbols)
124
- expectEqual ( [ " J " , " F " , " M " , " A " , " M " , " J " , " J " , " A " , " S " , " O " , " N " , " D " ] , c. veryShortStandaloneMonthSymbols)
125
- expectEqual ( [ " Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " , " Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec " ] , c. shortMonthSymbols)
126
- expectEqual ( [ " Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " , " Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec " ] , c. shortStandaloneMonthSymbols)
127
- expectEqual ( [ " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " ] , c. monthSymbols)
128
- expectEqual ( [ " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " ] , c. standaloneMonthSymbols)
129
- expectEqual ( [ " Q1 " , " Q2 " , " Q3 " , " Q4 " ] , c. shortQuarterSymbols)
130
- expectEqual ( [ " Q1 " , " Q2 " , " Q3 " , " Q4 " ] , c. shortStandaloneQuarterSymbols)
131
- expectEqual ( [ " S " , " M " , " T " , " W " , " T " , " F " , " S " ] , c. veryShortStandaloneWeekdaySymbols)
132
- expectEqual ( [ " S " , " M " , " T " , " W " , " T " , " F " , " S " ] , c. veryShortWeekdaySymbols)
133
- expectEqual ( [ " Sun " , " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " ] , c. shortStandaloneWeekdaySymbols)
134
- expectEqual ( [ " Sun " , " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " ] , c. shortWeekdaySymbols)
135
- expectEqual ( [ " Sunday " , " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " ] , c. standaloneWeekdaySymbols)
136
- expectEqual ( [ " Sunday " , " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " ] , c. weekdaySymbols)
137
-
138
- // The idea behind these tests is not to test calendrical math, but to simply verify that we are getting some kind of result from calling through to the underlying Foundation and ICU logic. If we move that logic into this struct in the future, then we will need to expand the test cases.
139
-
140
- // This is a very special Date in my life: the exact moment when I wrote these test cases and therefore knew all of the answers.
141
- let d = Date ( timeIntervalSince1970: 1468705593.2533731 )
142
- let earlierD = c. date ( byAdding: DateComponents ( day: - 10 ) , to: d) !
112
+ if #available( iOS 8 . 0 , OSX 10 . 7 , * ) {
113
+ var c = Calendar ( identifier: . gregorian)
114
+ // Use english localization
115
+ c. locale = Locale ( identifier: " en_US " )
143
116
144
- expectEqual ( 1 ..< 29 , c. minimumRange ( of: . day) )
145
- expectEqual ( 1 ..< 54 , c. maximumRange ( of: . weekOfYear) )
146
- expectEqual ( 0 ..< 60 , c. range ( of: . second, in: . minute, for: d) )
147
-
148
- var d1 = Date ( )
149
- var ti : TimeInterval = 0
150
-
151
- expectTrue ( c. dateInterval ( of: . day, start: & d1, interval: & ti, for: d) )
152
- expectEqual ( Date ( timeIntervalSince1970: 1468652400.0 ) , d1)
153
- expectEqual ( 86400 , ti)
154
-
155
- if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
156
- let dateInterval = c. dateInterval ( of: . day, for: d)
157
- expectEqual ( DateInterval ( start: d1, duration: ti) , dateInterval)
158
- }
159
-
160
- expectEqual ( 15 , c. ordinality ( of: . hour, in: . day, for: d) )
161
-
162
- expectEqual ( Date ( timeIntervalSince1970: 1468791993.2533731 ) , c. date ( byAdding: . day, value: 1 , to: d) )
163
- expectEqual ( Date ( timeIntervalSince1970: 1468791993.2533731 ) , c. date ( byAdding: DateComponents ( day: 1 ) , to: d) )
164
-
165
- expectEqual ( Date ( timeIntervalSince1970: 946627200.0 ) , c. date ( from: DateComponents ( year: 1999 , month: 12 , day: 31 ) ) )
166
-
167
- let comps = c. dateComponents ( [ . year, . month, . day] , from: Date ( timeIntervalSince1970: 946627200.0 ) )
168
- expectEqual ( 1999 , comps. year)
169
- expectEqual ( 12 , comps. month)
170
- expectEqual ( 31 , comps. day)
171
-
172
- expectEqual ( 10 , c. dateComponents ( [ . day] , from: d, to: c. date ( byAdding: DateComponents ( day: 10 ) , to: d) !) . day)
173
-
174
- expectEqual ( 30 , c. dateComponents ( [ . day] , from: DateComponents ( year: 1999 , month: 12 , day: 1 ) , to: DateComponents ( year: 1999 , month: 12 , day: 31 ) ) . day)
175
-
176
- expectEqual ( 2016 , c. component ( . year, from: d) )
177
-
178
- expectEqual ( Date ( timeIntervalSince1970: 1468652400.0 ) , c. startOfDay ( for: d) )
179
-
180
- expectEqual ( . orderedSame, c. compare ( d, to: d + 10 , toGranularity: . minute) )
181
-
182
- expectFalse ( c. isDate ( d, equalTo: d + 10 , toGranularity: . second) )
183
- expectTrue ( c. isDate ( d, equalTo: d + 10 , toGranularity: . day) )
184
-
185
- expectFalse ( c. isDate ( earlierD, inSameDayAs: d) )
186
- expectTrue ( c. isDate ( d, inSameDayAs: d) )
187
-
188
- expectFalse ( c. isDateInToday ( earlierD) )
189
- expectFalse ( c. isDateInYesterday ( earlierD) )
190
- expectFalse ( c. isDateInTomorrow ( earlierD) )
191
-
192
- expectTrue ( c. isDateInWeekend ( d) ) // 😢
193
-
194
- expectTrue ( c. dateIntervalOfWeekend ( containing: d, start: & d1, interval: & ti) )
195
-
196
- if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
197
- let thisWeekend = DateInterval ( start: Date ( timeIntervalSince1970: 1468652400.0 ) , duration: 172800.0 )
117
+ expectEqual ( " AM " , c. amSymbol)
118
+ expectEqual ( " PM " , c. pmSymbol)
119
+ expectEqual ( [ " 1st quarter " , " 2nd quarter " , " 3rd quarter " , " 4th quarter " ] , c. quarterSymbols)
120
+ expectEqual ( [ " 1st quarter " , " 2nd quarter " , " 3rd quarter " , " 4th quarter " ] , c. standaloneQuarterSymbols)
121
+ expectEqual ( [ " BC " , " AD " ] , c. eraSymbols)
122
+ expectEqual ( [ " Before Christ " , " Anno Domini " ] , c. longEraSymbols)
123
+ expectEqual ( [ " J " , " F " , " M " , " A " , " M " , " J " , " J " , " A " , " S " , " O " , " N " , " D " ] , c. veryShortMonthSymbols)
124
+ expectEqual ( [ " J " , " F " , " M " , " A " , " M " , " J " , " J " , " A " , " S " , " O " , " N " , " D " ] , c. veryShortStandaloneMonthSymbols)
125
+ expectEqual ( [ " Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " , " Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec " ] , c. shortMonthSymbols)
126
+ expectEqual ( [ " Jan " , " Feb " , " Mar " , " Apr " , " May " , " Jun " , " Jul " , " Aug " , " Sep " , " Oct " , " Nov " , " Dec " ] , c. shortStandaloneMonthSymbols)
127
+ expectEqual ( [ " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " ] , c. monthSymbols)
128
+ expectEqual ( [ " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " ] , c. standaloneMonthSymbols)
129
+ expectEqual ( [ " Q1 " , " Q2 " , " Q3 " , " Q4 " ] , c. shortQuarterSymbols)
130
+ expectEqual ( [ " Q1 " , " Q2 " , " Q3 " , " Q4 " ] , c. shortStandaloneQuarterSymbols)
131
+ expectEqual ( [ " S " , " M " , " T " , " W " , " T " , " F " , " S " ] , c. veryShortStandaloneWeekdaySymbols)
132
+ expectEqual ( [ " S " , " M " , " T " , " W " , " T " , " F " , " S " ] , c. veryShortWeekdaySymbols)
133
+ expectEqual ( [ " Sun " , " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " ] , c. shortStandaloneWeekdaySymbols)
134
+ expectEqual ( [ " Sun " , " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " ] , c. shortWeekdaySymbols)
135
+ expectEqual ( [ " Sunday " , " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " ] , c. standaloneWeekdaySymbols)
136
+ expectEqual ( [ " Sunday " , " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " ] , c. weekdaySymbols)
137
+
138
+ // The idea behind these tests is not to test calendrical math, but to simply verify that we are getting some kind of result from calling through to the underlying Foundation and ICU logic. If we move that logic into this struct in the future, then we will need to expand the test cases.
139
+
140
+ // This is a very special Date in my life: the exact moment when I wrote these test cases and therefore knew all of the answers.
141
+ let d = Date ( timeIntervalSince1970: 1468705593.2533731 )
142
+ let earlierD = c. date ( byAdding: DateComponents ( day: - 10 ) , to: d) !
143
+
144
+ expectEqual ( 1 ..< 29 , c. minimumRange ( of: . day) )
145
+ expectEqual ( 1 ..< 54 , c. maximumRange ( of: . weekOfYear) )
146
+ expectEqual ( 0 ..< 60 , c. range ( of: . second, in: . minute, for: d) )
147
+
148
+ var d1 = Date ( )
149
+ var ti : TimeInterval = 0
150
+
151
+ expectTrue ( c. dateInterval ( of: . day, start: & d1, interval: & ti, for: d) )
152
+ expectEqual ( Date ( timeIntervalSince1970: 1468652400.0 ) , d1)
153
+ expectEqual ( 86400 , ti)
154
+
155
+ if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
156
+ let dateInterval = c. dateInterval ( of: . day, for: d)
157
+ expectEqual ( DateInterval ( start: d1, duration: ti) , dateInterval)
158
+ }
159
+
160
+ expectEqual ( 15 , c. ordinality ( of: . hour, in: . day, for: d) )
161
+
162
+ expectEqual ( Date ( timeIntervalSince1970: 1468791993.2533731 ) , c. date ( byAdding: . day, value: 1 , to: d) )
163
+ expectEqual ( Date ( timeIntervalSince1970: 1468791993.2533731 ) , c. date ( byAdding: DateComponents ( day: 1 ) , to: d) )
164
+
165
+ expectEqual ( Date ( timeIntervalSince1970: 946627200.0 ) , c. date ( from: DateComponents ( year: 1999 , month: 12 , day: 31 ) ) )
166
+
167
+ let comps = c. dateComponents ( [ . year, . month, . day] , from: Date ( timeIntervalSince1970: 946627200.0 ) )
168
+ expectEqual ( 1999 , comps. year)
169
+ expectEqual ( 12 , comps. month)
170
+ expectEqual ( 31 , comps. day)
171
+
172
+ expectEqual ( 10 , c. dateComponents ( [ . day] , from: d, to: c. date ( byAdding: DateComponents ( day: 10 ) , to: d) !) . day)
173
+
174
+ expectEqual ( 30 , c. dateComponents ( [ . day] , from: DateComponents ( year: 1999 , month: 12 , day: 1 ) , to: DateComponents ( year: 1999 , month: 12 , day: 31 ) ) . day)
175
+
176
+ expectEqual ( 2016 , c. component ( . year, from: d) )
177
+
178
+ expectEqual ( Date ( timeIntervalSince1970: 1468652400.0 ) , c. startOfDay ( for: d) )
179
+
180
+ expectEqual ( . orderedSame, c. compare ( d, to: d + 10 , toGranularity: . minute) )
181
+
182
+ expectFalse ( c. isDate ( d, equalTo: d + 10 , toGranularity: . second) )
183
+ expectTrue ( c. isDate ( d, equalTo: d + 10 , toGranularity: . day) )
184
+
185
+ expectFalse ( c. isDate ( earlierD, inSameDayAs: d) )
186
+ expectTrue ( c. isDate ( d, inSameDayAs: d) )
187
+
188
+ expectFalse ( c. isDateInToday ( earlierD) )
189
+ expectFalse ( c. isDateInYesterday ( earlierD) )
190
+ expectFalse ( c. isDateInTomorrow ( earlierD) )
191
+
192
+ expectTrue ( c. isDateInWeekend ( d) ) // 😢
193
+
194
+ expectTrue ( c. dateIntervalOfWeekend ( containing: d, start: & d1, interval: & ti) )
195
+
196
+ if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
197
+ let thisWeekend = DateInterval ( start: Date ( timeIntervalSince1970: 1468652400.0 ) , duration: 172800.0 )
198
+
199
+ expectEqual ( thisWeekend, DateInterval ( start: d1, duration: ti) )
200
+ expectEqual ( thisWeekend, c. dateIntervalOfWeekend ( containing: d) )
201
+ }
198
202
199
- expectEqual ( thisWeekend, DateInterval ( start: d1, duration: ti) )
200
- expectEqual ( thisWeekend, c. dateIntervalOfWeekend ( containing: d) )
201
- }
202
-
203
203
204
- expectTrue ( c. nextWeekend ( startingAfter: d, start: & d1, interval: & ti) )
205
-
206
- if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
207
- let nextWeekend = DateInterval ( start: Date ( timeIntervalSince1970: 1469257200.0 ) , duration: 172800.0 )
208
-
209
- expectEqual ( nextWeekend, DateInterval ( start: d1, duration: ti) )
210
- expectEqual ( nextWeekend, c. nextWeekend ( startingAfter: d) )
211
- }
212
-
213
- // Enumeration
214
-
215
- var count = 0
216
- var exactCount = 0
217
-
218
- // Find the days numbered '31' after 'd', allowing the algorithm to move to the next day if required
219
- c. enumerateDates ( startingAfter: d, matching: DateComponents ( day: 31 ) , matchingPolicy: . nextTime) { result, exact, stop in
220
- // Just stop some arbitrary time in the future
221
- if result > d + 86400 * 365 { stop = true }
222
- count += 1
223
- if exact { exactCount += 1 }
224
- }
225
-
226
- /*
227
- Optional(2016-07-31 07:00:00 +0000)
228
- Optional(2016-08-31 07:00:00 +0000)
229
- Optional(2016-10-01 07:00:00 +0000)
230
- Optional(2016-10-31 07:00:00 +0000)
231
- Optional(2016-12-01 08:00:00 +0000)
232
- Optional(2016-12-31 08:00:00 +0000)
233
- Optional(2017-01-31 08:00:00 +0000)
234
- Optional(2017-03-01 08:00:00 +0000)
235
- Optional(2017-03-31 07:00:00 +0000)
236
- Optional(2017-05-01 07:00:00 +0000)
237
- Optional(2017-05-31 07:00:00 +0000)
238
- Optional(2017-07-01 07:00:00 +0000)
239
- Optional(2017-07-31 07:00:00 +0000)
240
- */
204
+ expectTrue ( c. nextWeekend ( startingAfter: d, start: & d1, interval: & ti) )
205
+
206
+ if #available( iOS 10 . 10 , OSX 10 . 12 , tvOS 10 . 0 , watchOS 3 . 0 , * ) {
207
+ let nextWeekend = DateInterval ( start: Date ( timeIntervalSince1970: 1469257200.0 ) , duration: 172800.0 )
208
+
209
+ expectEqual ( nextWeekend, DateInterval ( start: d1, duration: ti) )
210
+ expectEqual ( nextWeekend, c. nextWeekend ( startingAfter: d) )
211
+ }
212
+
213
+ // Enumeration
214
+
215
+ var count = 0
216
+ var exactCount = 0
217
+
218
+ // Find the days numbered '31' after 'd', allowing the algorithm to move to the next day if required
219
+ c. enumerateDates ( startingAfter: d, matching: DateComponents ( day: 31 ) , matchingPolicy: . nextTime) { result, exact, stop in
220
+ // Just stop some arbitrary time in the future
221
+ if result > d + 86400 * 365 { stop = true }
222
+ count += 1
223
+ if exact { exactCount += 1 }
224
+ }
225
+
226
+ /*
227
+ Optional(2016-07-31 07:00:00 +0000)
228
+ Optional(2016-08-31 07:00:00 +0000)
229
+ Optional(2016-10-01 07:00:00 +0000)
230
+ Optional(2016-10-31 07:00:00 +0000)
231
+ Optional(2016-12-01 08:00:00 +0000)
232
+ Optional(2016-12-31 08:00:00 +0000)
233
+ Optional(2017-01-31 08:00:00 +0000)
234
+ Optional(2017-03-01 08:00:00 +0000)
235
+ Optional(2017-03-31 07:00:00 +0000)
236
+ Optional(2017-05-01 07:00:00 +0000)
237
+ Optional(2017-05-31 07:00:00 +0000)
238
+ Optional(2017-07-01 07:00:00 +0000)
239
+ Optional(2017-07-31 07:00:00 +0000)
240
+ */
241
241
242
- expectEqual ( count, 13 )
243
- expectEqual ( exactCount, 8 )
244
-
245
-
246
- expectEqual ( Date ( timeIntervalSince1970: 1469948400.0 ) , c. nextDate ( after: d, matching: DateComponents ( day: 31 ) , matchingPolicy: . nextTime) )
247
-
248
-
249
- expectEqual ( Date ( timeIntervalSince1970: 1468742400.0 ) , c. date ( bySetting: . hour, value: 1 , of: d) )
250
-
251
- expectEqual ( Date ( timeIntervalSince1970: 1468656123.0 ) , c. date ( bySettingHour: 1 , minute: 2 , second: 3 , of: d, matchingPolicy: . nextTime) )
252
-
253
- expectTrue ( c. date ( d, matchesComponents: DateComponents ( month: 7 ) ) )
254
- expectFalse ( c. date ( d, matchesComponents: DateComponents ( month: 7 , day: 31 ) ) )
242
+ expectEqual ( count, 13 )
243
+ expectEqual ( exactCount, 8 )
244
+
245
+
246
+ expectEqual ( Date ( timeIntervalSince1970: 1469948400.0 ) , c. nextDate ( after: d, matching: DateComponents ( day: 31 ) , matchingPolicy: . nextTime) )
247
+
248
+
249
+ expectEqual ( Date ( timeIntervalSince1970: 1468742400.0 ) , c. date ( bySetting: . hour, value: 1 , of: d) )
250
+
251
+ expectEqual ( Date ( timeIntervalSince1970: 1468656123.0 ) , c. date ( bySettingHour: 1 , minute: 2 , second: 3 , of: d, matchingPolicy: . nextTime) )
252
+
253
+ expectTrue ( c. date ( d, matchesComponents: DateComponents ( month: 7 ) ) )
254
+ expectFalse ( c. date ( d, matchesComponents: DateComponents ( month: 7 , day: 31 ) ) )
255
+ }
255
256
}
256
257
}
257
258
0 commit comments