-
-
Notifications
You must be signed in to change notification settings - Fork 551
feat: introduce lunar calendar support #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,31 @@ extension Date { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct LunarDateStyle: FormatStyle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func format(_ value: Date) -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let formatter = DateFormatter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.calendar = Foundation.Calendar(identifier: .chinese) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.locale = Locale(identifier: "zh_CN") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.dateStyle = .long | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formatter.timeStyle = .none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let fullDate = formatter.string(from: value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let yearRange = fullDate.range(of: "年") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let extracted = String(fullDate[yearRange.upperBound...]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return extracted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fullDate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid recreating this every time. I added a suggestion below that makes the formatter static and also should handle the formatting in a cleaner way.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension Date.FormatStyle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func lunar() -> LunarDateStyle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LunarDateStyle() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension NSSize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var s: String { "\(width.i)×\(height.i)" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,38 @@ enum OSDControlSource: String, CaseIterable, Identifiable, Defaults.Serializable | |
| } | ||
| } | ||
|
|
||
| enum CalendarSubtitleDisplayMode: String, CaseIterable, Identifiable, Defaults.Serializable { | ||
| case alwaysDefault | ||
| case alwaysAlternate | ||
| case tapToSwitch | ||
|
|
||
| var id: String { self.rawValue } | ||
|
|
||
| var localizedString: String { | ||
| switch self { | ||
| case .alwaysDefault: | ||
| return NSLocalizedString("Always default", comment: "") | ||
| case .alwaysAlternate: | ||
| return NSLocalizedString("Always alternate", comment: "") | ||
| case .tapToSwitch: | ||
| return NSLocalizedString("Tap to switch", comment: "") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| enum AlternativeCalendarType: String, CaseIterable, Identifiable, Defaults.Serializable { | ||
| case lunar = "Lunar" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change 'lunar' to 'Chinese.' The Chinese calendar is actually lunisolar, and 'lunar' is too ambiguous since several other calendars use the lunar or lunisolar system. |
||
|
|
||
| var id: String { self.rawValue } | ||
|
|
||
| var localizedString: String { | ||
| switch self { | ||
| case .lunar: | ||
| return NSLocalizedString("Lunar", comment: "") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Defaults.Keys { | ||
| // MARK: General | ||
| static let menubarIcon = Key<Bool>("menubarIcon", default: true) | ||
|
|
@@ -242,6 +274,10 @@ extension Defaults.Keys { | |
| static let showFullEventTitles = Key<Bool>("showFullEventTitles", default: false) | ||
| static let autoScrollToNextEvent = Key<Bool>("autoScrollToNextEvent", default: true) | ||
|
|
||
| static let calendarSubtitleDisplayMode = Key<CalendarSubtitleDisplayMode>("calendarSubtitleDisplayMode", default: .alwaysDefault) | ||
| static let alternativeCalendar = Key<AlternativeCalendarType>("alternativeCalendar", default: .lunar) | ||
| static let calendarIsShowingAlternate = Key<Bool>("calendarIsShowingAlternate", default: false) | ||
|
|
||
| // MARK: Fullscreen Media Detection | ||
| static let hideNotchOption = Key<HideNotchOption>("hideNotchOption", default: .nowPlayingOnly) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This view should be refactored. It shouldn't have the hidden view for sizing in a ZStack and it should probably use the
.headlinefont for lunar to keep its characters a similar size to the year.