From 4ccc884e1bab88a55be3359b4e9560c15c047e2a Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Wed, 14 Oct 2020 17:44:04 +0300 Subject: [PATCH] Fixed problem with wrong dates --- AutoCat.xcodeproj/project.pbxproj | 4 +-- .../xcschemes/xcschememanagement.plist | 26 +++++++++---------- AutoCat/AppDelegate.swift | 17 +++++++++++- AutoCat/Utils/Api.swift | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 7870af1..e75ddc0 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -728,7 +728,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 45; + CURRENT_PROJECT_VERSION = 46; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -750,7 +750,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 45; + CURRENT_PROJECT_VERSION = 46; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist index 398782d..547fcf4 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -14,42 +14,42 @@ isShown orderHint - 8 + 12 DifferenceKit (Playground) 2.xcscheme isShown orderHint - 9 + 13 DifferenceKit (Playground).xcscheme isShown orderHint - 7 + 11 Eureka (Playground) 1.xcscheme isShown orderHint - 5 + 2 Eureka (Playground) 2.xcscheme isShown orderHint - 6 + 3 Eureka (Playground).xcscheme isShown orderHint - 4 + 1 GettingStarted (Playground) 1.xcscheme @@ -91,42 +91,42 @@ isShown orderHint - 13 + 7 Rx (Playground) 1.xcscheme isShown orderHint - 2 + 5 Rx (Playground) 2.xcscheme isShown orderHint - 3 + 6 Rx (Playground).xcscheme isShown orderHint - 1 + 4 SwiftDate (Playground) 1.xcscheme isShown orderHint - 11 + 9 SwiftDate (Playground) 2.xcscheme isShown orderHint - 12 + 10 SwiftDate (Playground) 3.xcscheme @@ -154,7 +154,7 @@ isShown orderHint - 10 + 8 SuppressBuildableAutocreation diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index 6ff3536..b266146 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( - schemaVersion: 19, + schemaVersion: 20, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 3 { var numbers: [String] = [] @@ -65,6 +65,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } } } + + if oldSchemaVersion == 19 { + migration.enumerateObjects(ofType: "Vehicle") { old, new in + guard let addedDate = old?["addedDate"] as? TimeInterval else { return } + guard let updatedDate = old?["updatedDate"] as? TimeInterval else { return } + + if addedDate > TimeInterval(Int32.max) { + new!["addedDate"] = addedDate/1000 + } + + if updatedDate > TimeInterval(Int32.max) { + new!["updatedDate"] = updatedDate/1000 + } + } + } }) Realm.Configuration.defaultConfiguration = config diff --git a/AutoCat/Utils/Api.swift b/AutoCat/Utils/Api.swift index 6b7a098..1a4b824 100644 --- a/AutoCat/Utils/Api.swift +++ b/AutoCat/Utils/Api.swift @@ -231,7 +231,7 @@ class Api { public static func add(event: VehicleEvent, to number: String) -> Single { let body = ["number": AnyEncodable(number), "event": AnyEncodable(event)] return self.makeBodyRequest(api: "events", body: body).map { (vehicle: Vehicle) -> Vehicle in - vehicle.addedDate = Date().timeIntervalSince1970*1000 + vehicle.addedDate = Date().timeIntervalSince1970 return vehicle } }