calebmanley calebmanley - 1 year ago 96
Swift Question

What does the Quarter Component in Calender.Component do? (Swift)

I am trying to use yearly quarters in my iOS application but have found that the

component does nothing. There is also no documentation I could find on it.

print( .quarter, value: 1, to: Date()))
just prints the current date. I would have expected it to add 3 months on to it?

Answer Source

You'd think that wouldn't you — but no, it appears something is broken.

A quick test in a Playground shows it all works until you use a .quarter:

//: Playground - noun: a place where people can play

import UIKit

let result = .quarter, value: 1, to: Date())

print (result)

let calendar1 = Calendar.current
let now1 = Date()
let newDate1 = .minute, value: 1, to: now1)
let newDate2 = .hour, value: 1, to: now1)
let newDate3 = .day, value: 1, to: now1)
let newDate4 = .month, value: 1, to: now1)
let newDate5 = .month, value: 3, to: now1)
let newDate6 = .quarter, value: 1, to: now1)

Results in:

"Sep 27, 2016, 3:30 PM"

"Optional(2016-09-27 05:30:03 +0000)\n"

gregorian (current)
"Sep 27, 2016, 3:30 PM"
"Sep 27, 2016, 3:31 PM"
"Sep 27, 2016, 4:30 PM"
"Sep 28, 2016, 3:30 PM"
"Oct 27, 2016, 3:30 PM"
"Dec 27, 2016, 3:30 PM"
"Sep 27, 2016, 3:30 PM"

It looks like as it stands in Xcode 8.0 (8A218a) you will have use months and a value of 3 as shown in the newDate5 line above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download