From 5267bdf54701f0079c6744f4ba0ec52d27b81501 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 28 Dec 2020 08:53:58 -0600 Subject: [PATCH] Nuking CLTimezoneData. --- Clocker/Clocker-Bridging-Header.h | 1 - Clocker/Clocker.xcodeproj/project.pbxproj | 6 - Clocker/ClockerUITests/ClockerUITests.m | 1 - .../ClockerUITests/FloatingWindowTests.swift | 3 - Clocker/ClockerUITests/PreferencesTest.swift | 3 +- .../ClockerUnitTests/ClockerUnitTests.swift | 2 +- Clocker/Panel/Data Layer/CLTimezoneData.h | 64 ---- Clocker/Panel/Data Layer/CLTimezoneData.m | 334 ------------------ Clocker/Panel/Data Layer/TimezoneData.swift | 53 +-- .../Data Layer/TimezoneDataOperations.swift | 10 +- Clocker/Panel/ParentPanelController.swift | 2 +- Clocker/Panel/UI/TimezoneDataSource.swift | 2 +- .../Appearance/AppearanceViewController.swift | 2 +- 13 files changed, 11 insertions(+), 472 deletions(-) delete mode 100644 Clocker/Panel/Data Layer/CLTimezoneData.h delete mode 100644 Clocker/Panel/Data Layer/CLTimezoneData.m diff --git a/Clocker/Clocker-Bridging-Header.h b/Clocker/Clocker-Bridging-Header.h index cae9662..2074ef5 100644 --- a/Clocker/Clocker-Bridging-Header.h +++ b/Clocker/Clocker-Bridging-Header.h @@ -5,7 +5,6 @@ // Created by Banthia, Abhishek on 12/22/17. // -#import "CLTimezoneData.h" #import "iVersion.h" #import #import diff --git a/Clocker/Clocker.xcodeproj/project.pbxproj b/Clocker/Clocker.xcodeproj/project.pbxproj index adfe96b..1d17a7a 100755 --- a/Clocker/Clocker.xcodeproj/project.pbxproj +++ b/Clocker/Clocker.xcodeproj/project.pbxproj @@ -77,7 +77,6 @@ 35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */; }; 35C36F792259E1D0002FA5C6 /* String + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F762259E1CF002FA5C6 /* String + Additions.swift */; }; 35C36F912259EAF4002FA5C6 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */; }; - 35C36F942259EB87002FA5C6 /* CLTimezoneData.m in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F932259EB87002FA5C6 /* CLTimezoneData.m */; }; 35C36F972259EBB1002FA5C6 /* AppFeedbackWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */; }; 35C36F982259EBB1002FA5C6 /* AppFeedbackWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */; }; 35C36FA02259ED6D002FA5C6 /* CalendarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */; }; @@ -299,8 +298,6 @@ 35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Foundation + Additions.swift"; sourceTree = ""; }; 35C36F762259E1CF002FA5C6 /* String + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String + Additions.swift"; sourceTree = ""; }; 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = ""; }; - 35C36F922259EB87002FA5C6 /* CLTimezoneData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLTimezoneData.h; sourceTree = ""; }; - 35C36F932259EB87002FA5C6 /* CLTimezoneData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLTimezoneData.m; sourceTree = ""; }; 35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AppFeedbackWindow.xib; sourceTree = ""; }; 35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppFeedbackWindowController.swift; sourceTree = ""; }; 35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarHandler.swift; sourceTree = ""; }; @@ -588,8 +585,6 @@ 35C36F512259DC85002FA5C6 /* Data Layer */ = { isa = PBXGroup; children = ( - 35C36F922259EB87002FA5C6 /* CLTimezoneData.h */, - 35C36F932259EB87002FA5C6 /* CLTimezoneData.m */, 35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */, 35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */, ); @@ -1231,7 +1226,6 @@ 35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */, 35C36F16225961DA002FA5C6 /* Date+Inits.swift in Sources */, 35C36F4F2259D981002FA5C6 /* AppDefaults.swift in Sources */, - 35C36F942259EB87002FA5C6 /* CLTimezoneData.m in Sources */, 35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */, 3508CC942599FFEC000E3530 /* MenubarHandler.swift in Sources */, 35C36F14225961DA002FA5C6 /* Integer+DateTools.swift in Sources */, diff --git a/Clocker/ClockerUITests/ClockerUITests.m b/Clocker/ClockerUITests/ClockerUITests.m index c708edd..b0604bc 100644 --- a/Clocker/ClockerUITests/ClockerUITests.m +++ b/Clocker/ClockerUITests/ClockerUITests.m @@ -1,7 +1,6 @@ // Copyright © 2015 Abhishek Banthia #import -#import "CLTimezoneData.h" #import "CommonStrings.h" @interface ClockerUITests : XCTestCase diff --git a/Clocker/ClockerUITests/FloatingWindowTests.swift b/Clocker/ClockerUITests/FloatingWindowTests.swift index 368ca43..53e8b8b 100644 --- a/Clocker/ClockerUITests/FloatingWindowTests.swift +++ b/Clocker/ClockerUITests/FloatingWindowTests.swift @@ -25,11 +25,8 @@ class FloatingWindowTests: XCTestCase { } addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in - Logger.info("Interruption Handler called") - Logger.info(alert.description) let alertButton = alert.buttons["OK"] if alertButton.exists { - Logger.info("Okay button found") alertButton.tap() return true } diff --git a/Clocker/ClockerUITests/PreferencesTest.swift b/Clocker/ClockerUITests/PreferencesTest.swift index e8d7faa..5c0f1f0 100644 --- a/Clocker/ClockerUITests/PreferencesTest.swift +++ b/Clocker/ClockerUITests/PreferencesTest.swift @@ -392,8 +392,7 @@ extension XCTestCase { let isHittable = NSPredicate(format: "exists == true", "") let addExpectation = expectation(for: isHittable, evaluatedWith: results.firstMatch) { () -> Bool in - Logger.info("Handler called") - return true + true } waiter.wait(for: [addExpectation], timeout: 5) diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index 539812f..b3d021d 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -156,7 +156,7 @@ class ClockerUnitTests: XCTestCase { let dataObject = TimezoneData(with: mumbai) let operations = TimezoneDataOperations(with: dataObject) - XCTAssertNotNil(operations.date(with: 0, displayType: .menuDisplay)) + XCTAssertNotNil(operations.date(with: 0, displayType: .menu)) } func testTimezoneFormat() { diff --git a/Clocker/Panel/Data Layer/CLTimezoneData.h b/Clocker/Panel/Data Layer/CLTimezoneData.h deleted file mode 100644 index dc35d19..0000000 --- a/Clocker/Panel/Data Layer/CLTimezoneData.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright © 2015 Abhishek Banthia - -#import - -typedef NS_ENUM(NSUInteger, CLDateDisplayType) { - CLPanelDisplay, - CLMenuDisplay -}; - -typedef NS_ENUM(NSUInteger, CLSelection) { - CLCitySelection, - CLTimezoneSelection -}; - -typedef NS_ENUM(NSUInteger, CLTimezoneOverride) { - CL12HourFormat, - CL24HourFormat, - CLGlobalFormat -}; - - - -@interface CLTimezoneData : NSObject - -@property (copy, nonatomic, readonly) NSString *customLabel; -@property (copy, nonatomic, readonly) NSString *formattedAddress; -@property (copy, nonatomic, readonly) NSString *place_id; -@property (copy, nonatomic, readonly) NSString *timezoneID; -@property (copy, nonatomic, readonly) NSNumber *latitude; -@property (copy, nonatomic, readonly) NSNumber *longitude; -@property (copy, nonatomic, readonly) NSString *note; -@property (strong, nonatomic, readonly) NSDate *nextUpdate; -@property (strong, nonatomic, readonly) NSNumber *isFavourite; -@property (strong, nonatomic, readonly) NSDate *sunriseTime; -@property (strong, nonatomic, readonly) NSDate *sunsetTime; -@property (assign, nonatomic, readonly) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset -@property (assign, nonatomic,readonly) CLSelection selectionType; -@property (assign, nonatomic, readonly) BOOL isSystemTimezone; //Used for figuring out if we want to show a home indicator -@property (assign, nonatomic, readonly) CLTimezoneOverride overrideFormat; - -+ (instancetype)getCustomObject:(NSData *)encodedData; -- (instancetype)initWithTimezoneInfo:(NSDictionary *)dictionary; - -- (void)setLabelForTimezone:(NSString *)customLabel; -- (void)setIDForTimezone:(NSString *)uniqueID; -- (void)setFormattedAddressForTimezone:(NSString *)address; -- (void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue; -- (void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate; -- (void)setSunsetTimeForTimezone:(NSDate *)sunsetTime; -- (void)setSunriseTimeForTimezone:(NSDate *)sunriseTime; -- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset; -- (void)setLatitudeForTimezone:(NSString *)latitude; -- (void)setLongitudeForTimezone:(NSString *)longitude; -- (void)setLocationIndicator:(BOOL)isCurrentLocation; -- (void)setShouldOverrideGlobalTimeFormat:(NSNumber *)shouldOverride; -- (void)setNoteForTimezone:(NSString *)note; - -- (NSString *)timezoneFormat; -- (NSString *)getFormattedTimezoneLabel; -- (NSString *)getTimezone; - -- (BOOL)isEmpty; - -@end diff --git a/Clocker/Panel/Data Layer/CLTimezoneData.m b/Clocker/Panel/Data Layer/CLTimezoneData.m deleted file mode 100644 index f8dab3c..0000000 --- a/Clocker/Panel/Data Layer/CLTimezoneData.m +++ /dev/null @@ -1,334 +0,0 @@ -// Copyright © 2015 Abhishek Banthia - -#import "CLTimezoneData.h" -#import "CommonStrings.h" -#include -#include -#import "Clocker-Swift.h" - -@interface CLTimezoneData () - -@property (copy, nonatomic) NSString *customLabel; -@property (copy, nonatomic) NSString *formattedAddress; -@property (copy, nonatomic) NSString *place_id; -@property (copy, nonatomic) NSString *timezoneID; -@property (copy, nonatomic) NSNumber *latitude; -@property (copy, nonatomic) NSNumber *longitude; -@property (copy, nonatomic) NSString *note; -@property (strong, nonatomic) NSDate *nextUpdate; -@property (strong, nonatomic) NSNumber *isFavourite; -@property (strong, nonatomic) NSDate *sunriseTime; -@property (strong, nonatomic) NSDate *sunsetTime; -@property (assign, nonatomic) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset -@property (assign, nonatomic) CLSelection selectionType; -@property (assign, nonatomic) BOOL isSystemTimezone; -@property (assign, nonatomic) CLTimezoneOverride overrideFormat; -@end - -@implementation CLTimezoneData - --(instancetype)initWithTimezoneInfo:(NSDictionary *)dictionary -{ - self = [super init]; - - if (self) - { - self.customLabel = dictionary[CLCustomLabel]; - self.timezoneID = dictionary[CLTimezoneID]; - self.latitude = dictionary[@"latitude"]; - self.longitude = dictionary[@"longitude"]; - self.place_id = dictionary[CLPlaceIdentifier]; - self.formattedAddress = dictionary[CLTimezoneName]; - self.isFavourite = @(NSOffState); - self.selectionType = CLCitySelection; - self.note = dictionary[@"note"]; - self.isSystemTimezone = NO; - self.overrideFormat = CLGlobalFormat; - } - - return self; -} - --(instancetype)init -{ - self = [super init]; - - if (self) - { - self.selectionType = CLTimezoneSelection; - self.isFavourite = @(NSOffState); - self.note = CLEmptyString; - self.isSystemTimezone = NO; - self.overrideFormat = CLGlobalFormat; - } - - return self; -} - -+ (instancetype)getCustomObject:(NSData *)encodedData -{ - - if (encodedData) - { - if ([encodedData isKindOfClass:[NSDictionary class]]) - { - CLTimezoneData *newObject = [[self alloc] initWithTimezoneInfo:(NSDictionary *)encodedData]; - return newObject; - } - - - CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData]; - return object; - - } - - return nil; -} - -- (void)encodeWithCoder:(NSCoder *)coder -{ - [coder encodeObject:self.place_id forKey:@"place_id"]; - [coder encodeObject:self.formattedAddress forKey:@"formattedAddress"]; - [coder encodeObject:self.customLabel forKey:@"customLabel"]; - [coder encodeObject:self.timezoneID forKey:@"timezoneID"]; - [coder encodeObject:self.nextUpdate forKey:@"nextUpdate"]; - [coder encodeObject:self.latitude forKey:@"latitude"]; - [coder encodeObject:self.longitude forKey:@"longitude"]; - [coder encodeObject:self.isFavourite forKey:@"isFavourite"]; - [coder encodeObject:self.sunriseTime forKey:@"sunriseTime"]; - [coder encodeObject:self.sunsetTime forKey:@"sunsetTime"]; - [coder encodeInteger:self.selectionType forKey:@"selectionType"]; - [coder encodeObject:self.note forKey:@"note"]; - [coder encodeBool:self.isSystemTimezone forKey:@"isSystemTimezone"]; - [coder encodeInteger:self.overrideFormat forKey:@"overrideFormat"]; -} - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super init]; - - if (self) - { - self.place_id = [coder decodeObjectForKey:@"place_id"]; - self.formattedAddress = [coder decodeObjectForKey:@"formattedAddress"]; - self.customLabel = [coder decodeObjectForKey:@"customLabel"]; - self.timezoneID = [coder decodeObjectForKey:@"timezoneID"]; - self.nextUpdate = [coder decodeObjectForKey:@"nextUpdate"]; - self.latitude = [coder decodeObjectForKey:@"latitude"]; - self.note = [coder decodeObjectForKey:@"note"]; - self.longitude = [coder decodeObjectForKey:@"longitude"]; - self.isFavourite = [coder decodeObjectForKey:@"isFavourite"]; - self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"]; - self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"]; - self.selectionType = [coder decodeIntegerForKey:@"selectionType"]; - self.isSystemTimezone = NO; - self.overrideFormat = [coder decodeIntegerForKey:@"overrideFormat"]; - } - - return self; -} - --(NSString *)description -{ - return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@\nSunrise Time: %@\nSunset Time: %@\nSelection Type: %zd\nNote: %@\nSystemTimezone: %hhd\nOverride: %zd", self.timezoneID, - self.formattedAddress, - self.customLabel, - self.latitude, - self.longitude, - self.place_id, - self.isFavourite, - self.sunriseTime, - self.sunsetTime, - self.selectionType, - self.note, - self.isSystemTimezone, - self.overrideFormat]; -} - -- (NSString *)getFormattedTimezoneLabel -{ - if (self.customLabel.length > 0) - { - return self.customLabel; - } - - if ([self.formattedAddress length] > 0) - { - return self.formattedAddress; - } - else if (self.timezoneID) - { - NSString *timezoneID = self.timezoneID; - - NSRange range = [timezoneID rangeOfString:@"/"]; - if (range.location != NSNotFound) - { - timezoneID = [timezoneID substringWithRange:NSMakeRange(range.location+1, timezoneID.length-1 - range.location)]; - } - - return timezoneID; - } - else - { - return @"Error"; - } - -} - -- (void)setLabelForTimezone:(NSString *)customLabel -{ - self.customLabel = customLabel.length > 0 ? customLabel : CLEmptyString; -} - -- (void)setIDForTimezone:(NSString *)uniqueID -{ - self.timezoneID = uniqueID; -} - -- (void)setLocationIndicator:(BOOL)isCurrentLocation { - self.isSystemTimezone = isCurrentLocation; -} - --(void)setFormattedAddressForTimezone:(NSString *)address -{ - self.formattedAddress = address; -} - --(void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue -{ - self.isFavourite = favouriteValue; -} - --(void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate -{ - self.nextUpdate = nextUpdate; -} - --(void)setSunsetTimeForTimezone:(NSDate *)sunsetTime -{ - self.sunsetTime = sunsetTime; -} - --(void)setSunriseTimeForTimezone:(NSDate *)sunriseTime -{ - self.sunriseTime = sunriseTime; -} - --(void)setShouldOverrideGlobalTimeFormat:(NSNumber *)shouldOverride -{ - if ([shouldOverride isEqualToNumber:@(0)]) { - NSLog(@"Updated to 12 Hour Format"); - self.overrideFormat = CL12HourFormat; - } else if ([shouldOverride isEqualToNumber:@(1)]) { - NSLog(@"Updated to 24 Hour Format"); - self.overrideFormat = CL24HourFormat; - } else { - NSLog(@"Updated to Global Hour Format"); - self.overrideFormat = CLGlobalFormat; - } -} - -- (NSString *)timezoneFormat { - - NSString *dateFormat = nil; - - NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey]; - NSNumber *showSeconds = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowSecondsInMenubar]; - - if([showSeconds isEqualToNumber:@(0)]) - { - if (self.overrideFormat == CLGlobalFormat) { - dateFormat = [is24HourFormatSelected isEqualToNumber:@(0)] ? @"h:mm:ss a" : @"H:mm:ss"; - } else if (self.overrideFormat == CL12HourFormat) { - dateFormat = @"h:mm:ss a"; - - } else if (self.overrideFormat == CL24HourFormat) { - dateFormat = @"H:mm:ss"; - } else { - assert("Something's wrong here."); - } - } - else - { - if (self.overrideFormat == CLGlobalFormat) { - dateFormat = [is24HourFormatSelected isEqualToNumber:@(0)] ? @"h:mm a" : @"H:mm"; - } else if (self.overrideFormat == CL12HourFormat) { - dateFormat = @"h:mm a"; - } else if (self.overrideFormat == CL24HourFormat) { - dateFormat = @"H:mm"; - } else { - assert("Something's wrong here."); - } - } - - return dateFormat; -} - -- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset -{ - self.sunriseOrSunset = sunriseOrSunset; -} - -- (void)setLatitudeForTimezone:(NSNumber *)latitude -{ - self.latitude = latitude; -} - -- (void)setLongitudeForTimezone:(NSNumber *)longitude -{ - self.longitude = longitude; -} - -- (void)setNoteForTimezone:(NSString *)note -{ - self.note = note; -} - -- (NSString *)getTimezone { - - if (self.isSystemTimezone == YES) { - [NSTimeZone resetSystemTimeZone]; - [self setTimezoneID:[[NSTimeZone systemTimeZone] name]]; - [self setFormattedAddress:[[NSTimeZone systemTimeZone] name]]; - return [[NSTimeZone systemTimeZone] name]; - } else { - return self.timezoneID; - } - -} - -- (BOOL)isEmpty -{ - if ([self checkPropertyForNil:self.timezoneID] || [self checkPropertyForNil:self.place_id] || - [self checkPropertyForNil:self.formattedAddress] || [self checkPropertyForNil:self.latitude] || [self checkPropertyForNil:self.longitude]) { - - return YES; - } - - return NO; -} - -- (BOOL)checkPropertyForNil:(id)property -{ - if (property == nil || property == [NSNull null]) { - return YES; - } - - return NO; -} - -- (BOOL)isEqual:(id)object { - - if (![self isKindOfClass:[self class]] || ![object isKindOfClass:[self class]]) { - return NO; - } - - CLTimezoneData *comparisonObject = (CLTimezoneData *)object; - return [self.place_id isEqualToString:comparisonObject.place_id]; -} - -- (NSUInteger)hash{ - return self.place_id.hash ^ self.timezoneID.hash; -} - -@end diff --git a/Clocker/Panel/Data Layer/TimezoneData.swift b/Clocker/Panel/Data Layer/TimezoneData.swift index 90bfc4d..7bc6a2a 100644 --- a/Clocker/Panel/Data Layer/TimezoneData.swift +++ b/Clocker/Panel/Data Layer/TimezoneData.swift @@ -80,31 +80,6 @@ class TimezoneData: NSObject, NSCoding { placeID = UUID().uuidString } - init(with originalTimezone: CLTimezoneData) { - customLabel = originalTimezone.customLabel - formattedAddress = originalTimezone.formattedAddress - placeID = originalTimezone.place_id - timezoneID = originalTimezone.timezoneID - - if originalTimezone.latitude != nil { - latitude = originalTimezone.latitude.doubleValue - } - - if originalTimezone.longitude != nil { - longitude = originalTimezone.longitude.doubleValue - } - - note = originalTimezone.note - nextUpdate = originalTimezone.nextUpdate - sunriseTime = originalTimezone.sunriseTime - sunsetTime = originalTimezone.sunsetTime - isFavourite = originalTimezone.isFavourite.intValue - isSunriseOrSunset = originalTimezone.sunriseOrSunset - selectionType = originalTimezone.selectionType == CLSelection.citySelection ? .city : .timezone - isSystemTimezone = originalTimezone.isSystemTimezone - overrideFormat = .globalFormat - } - init(with dictionary: [String: Any]) { if let label = dictionary[CLCustomLabel] as? String { customLabel = label @@ -196,32 +171,11 @@ class TimezoneData: NSObject, NSCoding { if let timezoneObject = NSKeyedUnarchiver.unarchiveObject(with: dataObject) as? TimezoneData { return timezoneObject - } else if let originalTimezoneObject = NSKeyedUnarchiver.unarchiveObject(with: dataObject) as? CLTimezoneData { - logOldModelUsage() - return TimezoneData(with: originalTimezoneObject) } return nil } - private class func logOldModelUsage() { - guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String, - let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else { - return - } - - let operatingSystem = ProcessInfo.processInfo.operatingSystemVersion - let osVersion = "\(operatingSystem.majorVersion).\(operatingSystem.minorVersion).\(operatingSystem.patchVersion)" - let versionInfo = "Clocker \(shortVersion) (\(appVersion))" - - let feedbackInfo = [ - AppFeedbackConstants.CLOperatingSystemVersion: osVersion, - AppFeedbackConstants.CLClockerVersion: versionInfo, - ] - - Logger.log(object: feedbackInfo, for: "CLTimezoneData is still being used!") - } - /// Converts the Obj-C model objects into Swift class func convert() { if let timezones = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data], !timezones.isEmpty { @@ -243,12 +197,7 @@ class TimezoneData: NSObject, NSCoding { for timezone in timezones { // Get the old (aka CLTimezoneData) model object let old = NSKeyedUnarchiver.unarchiveObject(with: timezone) - if let oldModel = old as? CLTimezoneData { - // Convert it to new model and add it - Logger.info("We're still using old Objective-C models") - let newTimezone = TimezoneData(with: oldModel) - newModels.append(newTimezone) - } else if let newModel = old as? TimezoneData { + if let newModel = old as? Clocker.TimezoneData { if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil { print("Resetting Global Format") newModel.setShouldOverrideGlobalTimeFormat(0) diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index dc38056..2571f9a 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -100,7 +100,7 @@ extension TimezoneDataOperations { let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar) if shouldDayBeShown, shouldLabelBeShownAlongWithTime { - let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) + let substring = date(with: 0, displayType: .menu) subtitle.append(substring) } @@ -120,7 +120,7 @@ extension TimezoneDataOperations { let shouldLabelsNotBeShownAlongWithTime = DataStore.shared().shouldDisplay(.placeInMenubar) if shouldDayBeShown, shouldLabelsNotBeShownAlongWithTime { - let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) + let substring = date(with: 0, displayType: .menu) subtitle.append(substring) } @@ -162,7 +162,7 @@ extension TimezoneDataOperations { } if shouldDayBeShown { - var substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) + var substring = date(with: 0, displayType: .menu) if substring.count > 3 { let endIndex = substring.index(substring.startIndex, offsetBy: 2) @@ -214,7 +214,7 @@ extension TimezoneDataOperations { to: Date()) ?? Date() } - func date(with sliderValue: Int, displayType: CLDateDisplayType) -> String { + func date(with sliderValue: Int, displayType: TimezoneData.DateDisplayType) -> String { guard let relativeDayPreference = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber else { assertionFailure("Data was unexpectedly nil") return CLEmptyString @@ -229,7 +229,7 @@ extension TimezoneDataOperations { let convertedDate = timezoneDate(with: sliderValue, currentCalendar) - if displayType == CLDateDisplayType.panelDisplay { + if displayType == .panel { // Yesterday, tomorrow, etc if relativeDayPreference.intValue == 0 { let localFormatter = DateFormatterManager.localizedSimpleFormatter("EEEE") diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index bd47bfa..05f183e 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -563,7 +563,7 @@ class ParentPanelController: NSWindowController { cellView.time.stringValue = dataOperation.time(with: futureSliderValue) cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue) cellView.sunriseSetTime.lineBreakMode = .byClipping - cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panelDisplay) + cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panel) cellView.currentLocationIndicator.isHidden = !model.isSystemTimezone cellView.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() if let note = model.note, !note.isEmpty { diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index 7686e39..4eb7a60 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -54,7 +54,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: sliderValue) cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() - cellView.relativeDate.stringValue = operation.date(with: sliderValue, displayType: .panelDisplay) + cellView.relativeDate.stringValue = operation.date(with: sliderValue, displayType: .panel) cellView.rowNumber = row cellView.customName.stringValue = currentModel.formattedTimezoneLabel() cellView.time.stringValue = operation.time(with: sliderValue) diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 07da3be..7f1ea02 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -371,7 +371,7 @@ extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate { cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: 0) cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() - cellView.relativeDate.stringValue = operation.date(with: 0, displayType: .panelDisplay) + cellView.relativeDate.stringValue = operation.date(with: 0, displayType: .panel) cellView.rowNumber = row cellView.customName.stringValue = currentModel.formattedTimezoneLabel() cellView.time.stringValue = operation.time(with: 0)