You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

4 years ago
// Copyright © 2015 Abhishek Banthia
import Cocoa
class HourMarkerViewItem: NSCollectionViewItem {
4 years ago
static let reuseIdentifier = NSUserInterfaceItemIdentifier("HourMarkerViewItem")
4 years ago
@IBOutlet var hourLabel: NSTextField!
4 years ago
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)
4 years ago
}
}
4 years ago
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
}
4 years ago
}