Skip to content

Instantly share code, notes, and snippets.

View kezipe's full-sized avatar

Kevin Peng kezipe

  • Toronto, Canada
View GitHub Profile
@kezipe
kezipe / CZ007.swift
Last active February 24, 2020 20:18
guard let hyphen = chineseDate.firstIndex(of: "-") else {
fatalError("\(chineseDate) is not correctly formatted, use DateFormatter.Style.full")
}
let startIndex = chineseDate.index(after: hyphen)
let endIndex = chineseDate.index(chineseDate.endIndex, offsetBy: -2)
let branch = chineseDate[startIndex ... endIndex]
print(branch)
let dict = [
"zi": "rat",
"chou": "ox",
"yin": "tiger",
"mao": "rabbit",
"chen": "dragon",
"si": "snake",
"wu": "horse",
"wei": "goat",
"shen": "monkey",
@kezipe
kezipe / CZ004.swift
Last active February 24, 2020 20:06
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, yyyy"
formatter.calendar = .init(identifier: .chinese)
formatter.dateStyle = .full
print(formatter.string(from: normalDate))
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, yyyy"
print(formatter.string(from: normalDate))
let calendar = Calendar(identifier: .gregorian)
let normalDate = calendar.date(from: normalCalendarDateComponents)!
What Swift gives us What it says in Chinese Associated Zodiac
zi rat
chou ox
yin tiger
mao rabbit
chen dragon
si snake
wu horse
wei goat
shen monkey
var normalCalendarDateComponents = DateComponents()
normalCalendarDateComponents.year = 2020
normalCalendarDateComponents.month = 5
normalCalendarDateComponents.day = 1