From 8563c790fda28ab71dadf941b66d0af69e3162e7 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 24 Oct 2020 03:06:26 -0500 Subject: [PATCH] Playing! --- Clocker/Panel/UI/HourMarkerViewItem.swift | 31 +++++++++++++++++++---- Clocker/Panel/UI/HourMarkerViewItem.xib | 4 +-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Clocker/Panel/UI/HourMarkerViewItem.swift b/Clocker/Panel/UI/HourMarkerViewItem.swift index 8e8df43..bd60c52 100644 --- a/Clocker/Panel/UI/HourMarkerViewItem.swift +++ b/Clocker/Panel/UI/HourMarkerViewItem.swift @@ -3,13 +3,34 @@ import Cocoa class HourMarkerViewItem: NSCollectionViewItem { + static let reuseIdentifier = NSUserInterfaceItemIdentifier("HourMarkerViewItem") + @IBOutlet var hourLabel: NSTextField! - func setup(with indexPath: IndexPath) { - hourLabel.stringValue = "\(indexPath.item):00" - if indexPath.item == 2 { - highlightState = .forSelection - isSelected = true + func setup(with hour: Int) { + var dateComponents = DateComponents() + dateComponents.hour = hour + + if let newDate = Calendar.autoupdatingCurrent.date(byAdding: dateComponents, to: Date().nextHour) { + let dateFormatter = DateFormatterManager.dateFormatterWithFormat(with: .none, + format: "HH:mm", + timezoneIdentifier: TimeZone.current.identifier, + locale: Locale.autoupdatingCurrent) + + hourLabel.stringValue = dateFormatter.string(from: newDate) } } + + override var acceptsFirstResponder: Bool { + return false + } +} + +extension Date { + public var nextHour: Date { + let calendar = Calendar.current + let minutes = calendar.component(.minute, from: self) + let components = DateComponents(hour: 1, minute: -minutes) + return calendar.date(byAdding: components, to: self) ?? self + } } diff --git a/Clocker/Panel/UI/HourMarkerViewItem.xib b/Clocker/Panel/UI/HourMarkerViewItem.xib index 2c1f173..0944c07 100644 --- a/Clocker/Panel/UI/HourMarkerViewItem.xib +++ b/Clocker/Panel/UI/HourMarkerViewItem.xib @@ -1,8 +1,8 @@ - + - +