Skip to content

Instantly share code, notes, and snippets.

View leodabus's full-sized avatar

Leonardo Savio Dabus leodabus

View GitHub Profile
extension BidirectionalCollection where Iterator.Element == String, SubSequence.Iterator.Element == String {
var sentence: String {
guard let last = last else { return "" }
return count <= 2 ? joined(separator: " and ") :
dropLast().joined(separator: ", ") + " and " + last
}
}
extension Date {
var year: Int { return Calendar.autoupdatingCurrent.component(.year, from: self) }
var month: Int { return Calendar.autoupdatingCurrent.component(.month, from: self) }
var day: Int { return Calendar.autoupdatingCurrent.component(.day, from: self) }
var firstDayOfMonth: Date {
return Calendar.autoupdatingCurrent.date(from: DateComponents(year: year, month: month, day: 1))!
}
var lastDayOfMonth: Date {
return Calendar.autoupdatingCurrent.date(from: DateComponents(year: year, month: month+1, day: 0))!
}