From 987f987e3fe6fe605e3e6ed5c88b170365da2105 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 24 Oct 2020 03:05:34 -0500 Subject: [PATCH] DST alert changes. --- .../Data Layer/TimezoneDataOperations.swift | 26 +++++++++++++++++++ Clocker/Panel/UI/TimezoneCellView.swift | 2 +- Clocker/Panel/UI/TimezoneDataSource.swift | 13 ++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 8059dfb..9c78c07 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -33,6 +33,32 @@ extension TimezoneDataOperations { return dateFormatter.string(from: newDate) } + func nextDaylightSavingsTransitionIfAvailable(with sliderValue: Int) -> String? { + let currentTimezone = TimeZone(identifier: dataObject.timezone()) + guard let nextDaylightSavingsTransition = currentTimezone?.nextDaylightSavingTimeTransition else { + return nil + } + + guard let newDate = TimezoneDataOperations.gregorianCalendar?.date(byAdding: .minute, + value: sliderValue, + to: Date(), + options: .matchFirst) else { + assertionFailure("Data was unexpectedly nil") + return nil + } + + let calendar = Calendar.autoupdatingCurrent + let numberOfDays = nextDaylightSavingsTransition.days(from: newDate, calendar: calendar) + + // We'd like to show upcoming DST changes within the 7 day range. + // Using 8 as a fail-safe as timezones behind CDT can sometimes be wrongly attributed + if numberOfDays > 8 || numberOfDays <= 0 { + return nil + } + + return "Daylight Savings transition will occur in \(numberOfDays) days!" + } + private func checkForUpcomingEvents() -> (String, String)? { if DataStore.shared().shouldDisplay(.showMeetingInMenubar) { let filteredDates = EventCenter.sharedCenter().eventsForDate diff --git a/Clocker/Panel/UI/TimezoneCellView.swift b/Clocker/Panel/UI/TimezoneCellView.swift index 96013b4..92d2245 100644 --- a/Clocker/Panel/UI/TimezoneCellView.swift +++ b/Clocker/Panel/UI/TimezoneCellView.swift @@ -149,7 +149,7 @@ class TimezoneCellView: NSTableCellView { let timeWidth = timeString.size(withAttributes: [NSAttributedString.Key.font: customTimeFont]).width for constraint in time.constraints { - constraint.constant = constraint.identifier == "height" ? timeHeight : timeWidth + constraint.constant = constraint.identifier == "height" ? timeHeight : timeWidth } } diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index 4fb12dc..0c3e37c 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -58,11 +58,17 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { cellView.rowNumber = row cellView.customName.stringValue = currentModel.formattedTimezoneLabel() cellView.time.stringValue = operation.time(with: sliderValue) - cellView.noteLabel.stringValue = currentModel.note ?? CLEmptyString cellView.noteLabel.toolTip = currentModel.note ?? CLEmptyString cellView.currentLocationIndicator.isHidden = !currentModel.isSystemTimezone cellView.time.setAccessibilityIdentifier("ActualTime") cellView.relativeDate.setAccessibilityIdentifier("RelativeDate") + if let note = currentModel.note, !note.isEmpty { + cellView.noteLabel.stringValue = note + } else if let value = operation.nextDaylightSavingsTransitionIfAvailable(with: sliderValue) { + cellView.noteLabel.stringValue = value + } else { + cellView.noteLabel.stringValue = CLEmptyString + } cellView.layout(with: currentModel) cellView.setAccessibilityIdentifier(currentModel.formattedTimezoneLabel()) @@ -78,6 +84,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber, timezones.count > row, let relativeDisplay = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber { let model = timezones[row] + let operation = TimezoneDataOperations(with: model) let shouldShowSunrise = DataStore.shared().shouldDisplay(.sunrise) var rowHeight: Int = userFontSize == 4 ? 60 : 65 @@ -91,7 +98,9 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { } if let note = model.note, !note.isEmpty { - rowHeight += userFontSize.intValue + 25 + rowHeight += userFontSize.intValue + 15 + } else if operation.nextDaylightSavingsTransitionIfAvailable(with: sliderValue) != nil { + rowHeight += userFontSize.intValue + 15 } if model.isSystemTimezone {