Skip to content

Commit

Permalink
Fix various crashing bugs associated with apparent time
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Dec 24, 2022
1 parent 3c564bc commit ccefb46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Chinese Time.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions ChineseTime/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ccefb46

Please sign in to comment.