Skip to content

Commit

Permalink
Fix a bug in calculating monthLength with apparent Time
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Apr 19, 2023
1 parent dffc9b4 commit 97e1785
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Chinese Time.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 51;
CURRENT_PROJECT_VERSION = 52;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -323,7 +323,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 3.3;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = "Chinese-Time";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -339,7 +339,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 51;
CURRENT_PROJECT_VERSION = 52;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -351,7 +351,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 3.3;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = "Chinese-Time";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
14 changes: 8 additions & 6 deletions ChineseTime/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private func fromJD2000(date: Date) -> CGFloat {
return offset
}

private func intraday_solar_times(chineseCalendar: ChineseCalendar, location: NSPoint) -> [Date?] {
private func intraday_solar_times(chineseCalendar: ChineseCalendar, location: CGPoint) -> [Date?] {
let calendar = chineseCalendar.calendar
func timeOfDate(date: Date, hour: Int) -> Date {
var dateComponents = calendar.dateComponents([.year, .month, .day], from: date)
Expand Down Expand Up @@ -277,7 +277,7 @@ private func intraday_solar_times(chineseCalendar: ChineseCalendar, location: NS
return results
}

private func intraday_lunar_times(chineseCalendar: ChineseCalendar, location: NSPoint) -> [Date?] {
private func intraday_lunar_times(chineseCalendar: ChineseCalendar, location: CGPoint) -> [Date?] {

func riseAndSet(meridianTime: Date, latitude: CGFloat, light: Bool) -> ([Date?], CGFloat) {
let offsetMeridian = lunarTimeOffset(latitude: location.x / 180 * CGFloat.pi, jdTime: fromJD2000(date: meridianTime), light: light)
Expand Down Expand Up @@ -416,7 +416,7 @@ class ChineseCalendar {
private var _month: Int
private var _precise_month: Int
private var _day: Int
private var _location: NSPoint?
private var _location: CGPoint?
private var _sunTimes: [Date?] = []
private var _moonTimes: [Date?] = []
private var _startHour = Date()
Expand Down Expand Up @@ -445,7 +445,7 @@ class ChineseCalendar {
var minorTicks = [CGFloat]()
}

init(time: Date, timezone: TimeZone, location: NSPoint?) {
init(time: Date, timezone: TimeZone, location: CGPoint?) {
self._time = time
var calendar = Calendar(identifier: .iso8601)
calendar.timeZone = timezone
Expand Down Expand Up @@ -581,7 +581,7 @@ class ChineseCalendar {
}

// If return true, update succeed, otherwise fail
func update(time: Date, timezone: TimeZone, location: NSPoint?) -> Bool {
func update(time: Date, timezone: TimeZone, location: CGPoint?) -> Bool {
if timezone != self._calendar.timeZone {
return false
}
Expand Down Expand Up @@ -914,7 +914,9 @@ class ChineseCalendar {
}
var monthLengthInWholeDays: Int {
let month = Self.globalMonth ? _precise_month : _month
return Int(round(_calendar.startOfDay(for: _moonEclipses[month]).distance(to: _calendar.startOfDay(for: _moonEclipses[month+1])) / 86400))
let monthStartDate = _calendar.startOfDay(for: _moonEclipses[month], apparent: Self.apparentTime, location: _location)
let monthEndDate = _calendar.startOfDay(for: _moonEclipses[month+1], apparent: Self.apparentTime, location: _location)
return Int(round(monthStartDate.distance(to: monthEndDate) / 86400))
}
var startHour: Date {
_startHour
Expand Down

0 comments on commit 97e1785

Please sign in to comment.