Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Challenge complete #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

let brandonShegaClockEntry = CodeChallengeEntry<ClockChallenge>(name: "brandonshega") { input in
let df = DateFormatter()
df.dateFormat = "HH:MM:SS"
guard let date = df.date(from: input) else { return (0, 0, 0) }
let dateComps = Calendar.current.dateComponents([.hour, .minute, .second], from: date)
return dateComps.handsInAngles
}

extension DateComponents {
var hoursToAngle: Int {
guard let hour = hour else { return 0 }
return hour * 30
}

var minutesOrSecondsToAngle: Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name will pollute the global name space. Everything that isn't your actual entry should be marked filePrivate. Please update accordingly.

guard let minute = minute else { return 0 }
return minute * 6
}

var handsInAngles: (Int, Int, Int) {
return (hoursToAngle, minutesOrSecondsToAngle, minutesOrSecondsToAngle)
}
}