Browse Source

DST alert changes.

pull/92/head
Abhishek 4 years ago
parent
commit
987f987e3f
  1. 26
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  2. 2
      Clocker/Panel/UI/TimezoneCellView.swift
  3. 13
      Clocker/Panel/UI/TimezoneDataSource.swift

26
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

2
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
}
}

13
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 {

Loading…
Cancel
Save