From fd332ad9f4686492afc17037efbcdfdd12c80614 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 17 Jan 2021 14:23:12 -0500 Subject: [PATCH] [+] Create function date.get() to get any date components from a date --- ProjectClock/Utils.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ProjectClock/Utils.swift b/ProjectClock/Utils.swift index b5b8021..ad91177 100644 --- a/ProjectClock/Utils.swift +++ b/ProjectClock/Utils.swift @@ -45,4 +45,12 @@ extension Date let comp = calendar.dateComponents([.hour, .minute, .second], from: self) return (comp.hour!, comp.minute!, comp.second!) } + + /// Get another component + func get(_ c: Calendar.Component) -> Int + { + let calendar = Calendar.current + let comp = calendar.dateComponents([c], from: self) + return comp.value(for: c)! + } }