From ccefb461aa1d62a8e85e509cd47f4713f02d7d9f Mon Sep 17 00:00:00 2001 From: LEO Yoon-Tsaw Date: Sat, 24 Dec 2022 09:48:52 -0500 Subject: [PATCH] Fix various crashing bugs associated with apparent time --- Chinese Time.xcodeproj/project.pbxproj | 8 ++++---- ChineseTime/Model.swift | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Chinese Time.xcodeproj/project.pbxproj b/Chinese Time.xcodeproj/project.pbxproj index ecaa86c..4197e84 100644 --- a/Chinese Time.xcodeproj/project.pbxproj +++ b/Chinese Time.xcodeproj/project.pbxproj @@ -306,7 +306,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 42; + CURRENT_PROJECT_VERSION = 43; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; @@ -318,7 +318,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 3.0; + MARKETING_VERSION = 3.1; PRODUCT_BUNDLE_IDENTIFIER = "Chinese-Time"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -334,7 +334,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 42; + CURRENT_PROJECT_VERSION = 43; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; @@ -346,7 +346,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 3.0; + MARKETING_VERSION = 3.1; PRODUCT_BUNDLE_IDENTIFIER = "Chinese-Time"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/ChineseTime/Model.swift b/ChineseTime/Model.swift index 05bfac5..a731c1d 100644 --- a/ChineseTime/Model.swift +++ b/ChineseTime/Model.swift @@ -24,15 +24,16 @@ extension Calendar { start -= equationOfTime(D: fromJD2000(date: start)) / (2 * CGFloat.pi) * 86400 return start } - var startToday = startOfDay(for: day) + let standardStartOfDay = startOfDay(for: day) + var startToday = standardStartOfDay if let location = location, apparent { startToday = convertToApparent(date: startToday, location: location) if day < startToday { - var startYesterday = self.date(byAdding: .day, value: -1, to: startToday)! + var startYesterday = self.date(byAdding: .day, value: -1, to: standardStartOfDay)! startYesterday = convertToApparent(date: startYesterday, location: location) return startYesterday } else { - var startTomorrow = self.date(byAdding: .day, value: 1, to: startToday)! + var startTomorrow = self.date(byAdding: .day, value: 1, to: standardStartOfDay)! startTomorrow = convertToApparent(date: startTomorrow, location: location) if day >= startTomorrow { return startTomorrow @@ -593,8 +594,8 @@ class ChineseCalendar { Self.apparentTime && _location != nil } var dateString: String { - let chinese_month = _monthNames[_month] - let chinese_day = Self.day_chinese[_day] + let chinese_month = _monthNames[(_month + _day / Self.day_chinese.count) % _monthNames.count] + let chinese_day = Self.day_chinese[_day % Self.day_chinese.count] if chinese_day.count > 1 { return "\(chinese_month)\(chinese_day)" } else {