Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Intents/GetSunriseTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import AppIntents
import CoreLocation
import Solar

struct GetSunriseTime: AppIntent {
static var title: LocalizedStringResource = "Get Sunrise Time"
Expand All @@ -29,7 +28,7 @@ struct GetSunriseTime: AppIntent {
throw $location.needsValueError("What location do you want to see the sunrise for?")
}

let solar = Solar(for: date, coordinate: coordinate)
let solar = NTSolar(for: date, coordinate: coordinate, timeZone: location.timeZone ?? .autoupdatingCurrent)

return .result(
value: solar?.sunrise,
Expand Down
3 changes: 1 addition & 2 deletions Intents/GetSunsetTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import AppIntents
import CoreLocation
import Solar

struct GetSunsetTime: AppIntent {
static var title: LocalizedStringResource = "Get Sunset Time"
Expand All @@ -29,7 +28,7 @@ struct GetSunsetTime: AppIntent {
throw $location.needsValueError("What location do you want to see the sunset for?")
}

let solar = Solar(for: date, coordinate: coordinate)
let solar = NTSolar(for: date, coordinate: coordinate, timeZone: location.timeZone ?? .autoupdatingCurrent)

return .result(
value: solar?.sunset,
Expand Down
3 changes: 1 addition & 2 deletions Intents/ViewDaylight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import AppIntents
import CoreLocation
import Solar

struct ViewDaylight: AppIntent {
static var title: LocalizedStringResource = "View Daylight"
Expand All @@ -33,7 +32,7 @@ struct ViewDaylight: AppIntent {
formatter.unitsStyle = .full
formatter.allowedUnits = [.hour, .minute, .second]

let solar = Solar(for: date, coordinate: coordinate)
let solar = NTSolar(for: date, coordinate: coordinate, timeZone: location.timeZone ?? .autoupdatingCurrent)

let duration = (solar?.sunrise ?? .now).distance(to: solar?.sunset ?? .now)

Expand Down
3 changes: 1 addition & 2 deletions Intents/ViewRemainingDaylight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation
import AppIntents
import Solar
import CoreLocation

struct ViewRemainingDaylight: AppIntent {
Expand All @@ -26,7 +25,7 @@ struct ViewRemainingDaylight: AppIntent {
throw $location.needsValueError("What location do you want to see the daylight for?")
}

let solar = Solar(coordinate: coordinate)!
let solar = NTSolar(for: .now, coordinate: coordinate, timeZone: location.timeZone ?? .autoupdatingCurrent)!

var resultValue: TimeInterval

Expand Down
20 changes: 0 additions & 20 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,6 @@
}
}
},
"ceeK/Solar" : {
"localizations" : {
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "ceeK/Solar"
}
}
}
},
"Change how notifications behave when daily daylight begins to decrease. This can help with Seasonal Affective Disorder." : {
"localizations" : {
"it" : {
Expand Down Expand Up @@ -1556,16 +1546,6 @@
}
}
},
"Open Source Acknowledgements" : {
"localizations" : {
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ringraziamenti Open Source"
}
}
}
},
"Order" : {
"localizations" : {
"it" : {
Expand Down
94 changes: 29 additions & 65 deletions Solstice.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions Solstice/Charts/AnnualDaylightChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//

import SwiftUI
import Solar
import Charts
import TimeMachine

struct AnnualDaylightChart<Location: AnyLocation>: View {
@Environment(\.timeMachine) var timeMachine: TimeMachine
var location: Location

var kvPairs: KeyValuePairs<Solar.Phase, Color> = [
var kvPairs: KeyValuePairs<NTSolar.Phase, Color> = [
.astronomical: .indigo,
.nautical: .blue,
.civil: .teal,
Expand Down Expand Up @@ -45,15 +44,15 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
}

@ChartContentBuilder
private func solarBarMarks(for solar: Solar) -> some ChartContent {
private func solarBarMarks(for solar: NTSolar) -> some ChartContent {
astronomicalBarMark(for: solar)
nauticalBarMark(for: solar)
civilBarMark(for: solar)
daylightBarMark(for: solar)
}

@ChartContentBuilder
private func astronomicalBarMark(for solar: Solar) -> some ChartContent {
private func astronomicalBarMark(for solar: NTSolar) -> some ChartContent {
if let astronomicalSunrise = solar.astronomicalSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let astronomicalSunset = solar.astronomicalSunset?.withTimeZoneAdjustment(for: location.timeZone) {
let yStart: Double = max(0, solar.startOfDay.distance(to: astronomicalSunrise))
Expand All @@ -63,12 +62,12 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
yStart: .value("Astronomical Sunrise", yStart),
yEnd: .value("Astronomical Sunset", yEnd)
)
.foregroundStyle(by: .value("Phase", Solar.Phase.astronomical))
.foregroundStyle(by: .value("Phase", NTSolar.Phase.astronomical))
}
}

@ChartContentBuilder
private func nauticalBarMark(for solar: Solar) -> some ChartContent {
private func nauticalBarMark(for solar: NTSolar) -> some ChartContent {
if let nauticalSunrise = solar.nauticalSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let nauticalSunset = solar.nauticalSunset?.withTimeZoneAdjustment(for: location.timeZone) {
let yStart: Double = max(0, solar.startOfDay.distance(to: nauticalSunrise))
Expand All @@ -78,12 +77,12 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
yStart: .value("Nautical Sunrise", yStart),
yEnd: .value("Nautical Sunset", yEnd)
)
.foregroundStyle(by: .value("Phase", Solar.Phase.nautical))
.foregroundStyle(by: .value("Phase", NTSolar.Phase.nautical))
}
}

@ChartContentBuilder
private func civilBarMark(for solar: Solar) -> some ChartContent {
private func civilBarMark(for solar: NTSolar) -> some ChartContent {
if let civilSunrise = solar.civilSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let civilSunset = solar.civilSunset?.withTimeZoneAdjustment(for: location.timeZone) {
let yStart: Double = max(0, solar.startOfDay.distance(to: civilSunrise))
Expand All @@ -93,11 +92,11 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
yStart: .value("Civil Sunrise", yStart),
yEnd: .value("Civil Sunset", yEnd)
)
.foregroundStyle(by: .value("Phase", Solar.Phase.civil))
.foregroundStyle(by: .value("Phase", NTSolar.Phase.civil))
}
}

private func daylightBarMark(for solar: Solar) -> some ChartContent {
private func daylightBarMark(for solar: NTSolar) -> some ChartContent {
let sunrise: Date = solar.safeSunrise.withTimeZoneAdjustment(for: location.timeZone)
let sunset: Date = solar.safeSunset.withTimeZoneAdjustment(for: location.timeZone)
let yStart: Double = max(0, solar.startOfDay.distance(to: sunrise))
Expand All @@ -107,7 +106,7 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
yStart: .value("Sunrise", yStart),
yEnd: .value("Sunset", yEnd)
)
.foregroundStyle(by: .value("Phase", Solar.Phase.day))
.foregroundStyle(by: .value("Phase", NTSolar.Phase.day))
}

private var yAxisMarks: some AxisContent {
Expand Down Expand Up @@ -138,7 +137,7 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
}

extension AnnualDaylightChart {
var monthlySolars: Array<Solar> {
var monthlySolars: Array<NTSolar> {
guard let year = calendar.dateInterval(of: .year, for: timeMachine.date) else {
return []
}
Expand All @@ -153,7 +152,7 @@ extension AnnualDaylightChart {
}

return dates.map { date in
return Solar(for: date, coordinate: location.coordinate)
return NTSolar(for: date, coordinate: location.coordinate, timeZone: location.timeZone)
}.compactMap { $0 }
}
}
Expand Down
13 changes: 6 additions & 7 deletions Solstice/Charts/CircularSolarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import SwiftUI
import Solar
import TimeMachine
import Suite
import enum Accelerate.vDSP
Expand All @@ -26,8 +25,8 @@ struct CircularSolarChart<Location: AnyLocation>: View {

var timeZone: TimeZone { location.timeZone }

var solar: Solar? {
Solar(for: date ?? timeMachine.date, coordinate: location.coordinate)
var solar: NTSolar? {
NTSolar(for: date ?? timeMachine.date, coordinate: location.coordinate, timeZone: location.timeZone)
}

var majorSunSize: Double {
Expand Down Expand Up @@ -176,7 +175,7 @@ struct CircularSolarChart<Location: AnyLocation>: View {
private var phaseSlices: some View {
Group {
if let phases = solar?.phases {
let phaseKeys: [Solar.Phase] = Array(phases.keys)
let phaseKeys: [NTSolar.Phase] = Array(phases.keys)
ForEach(phaseKeys, id: \.self) { key in
phaseSlice(for: key, phases: phases)
}
Expand All @@ -186,7 +185,7 @@ struct CircularSolarChart<Location: AnyLocation>: View {
}

@ViewBuilder
private func phaseSlice(for key: Solar.Phase, phases: [Solar.Phase: (sunrise: Date?, sunset: Date?)]) -> some View {
private func phaseSlice(for key: NTSolar.Phase, phases: [NTSolar.Phase: (sunrise: Date?, sunset: Date?)]) -> some View {
if let (sunrise, sunset) = phases[key],
let sunrise,
let sunset {
Expand Down Expand Up @@ -258,15 +257,15 @@ struct CircularSolarChart<Location: AnyLocation>: View {
@ViewBuilder
private var phaseMarkers: some View {
if let phases = solar?.phases {
let phaseKeys: [Solar.Phase] = Array(phases.keys)
let phaseKeys: [NTSolar.Phase] = Array(phases.keys)
ForEach(phaseKeys, id: \.self) { key in
phaseMarker(for: key, phases: phases)
}
}
}

@ViewBuilder
private func phaseMarker(for key: Solar.Phase, phases: [Solar.Phase: (sunrise: Date?, sunset: Date?)]) -> some View {
private func phaseMarker(for key: NTSolar.Phase, phases: [NTSolar.Phase: (sunrise: Date?, sunset: Date?)]) -> some View {
if let (sunrise, sunset) = phases[key],
let sunrise,
let sunset {
Expand Down
21 changes: 10 additions & 11 deletions Solstice/Charts/DaylightChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@

import SwiftUI
import Charts
import Solar
import Suite

struct DaylightChart: View {
@Environment(\.isLuminanceReduced) var isLuminanceReduced
@Environment(\.colorScheme) var colorScheme

@State private var selectedEvent: Solar.Event?
@State private var selectedEvent: NTSolar.Event?
@State private var currentX: Date?

var solar: Solar
var solar: NTSolar
var timeZone: TimeZone
var showEventTypes = true

Expand Down Expand Up @@ -109,11 +108,11 @@ struct DaylightChart: View {
}
}

private var filteredEvents: [Solar.Event] {
private var filteredEvents: [NTSolar.Event] {
solar.events.filter { range.contains($0.date) }
}

private func eventPointMark(for solarEvent: Solar.Event) -> some ChartContent {
private func eventPointMark(for solarEvent: NTSolar.Event) -> some ChartContent {
PointMark(
x: .value("Event Time", solarEvent.date),
y: .value("Event", yValue(for: solarEvent.date))
Expand All @@ -123,9 +122,9 @@ struct DaylightChart: View {
.symbolSize(markSize * .pi * 2)
}

private func eventPointOpacity(for phase: Solar.Phase) -> Double {
let hiddenPhases: Set<Solar.Phase> = [.night, .day, .sunrise, .sunset]
let shouldShow: Bool = showEventTypes || !Solar.Phase.plottablePhases.contains(phase)
private func eventPointOpacity(for phase: NTSolar.Phase) -> Double {
let hiddenPhases: Set<NTSolar.Phase> = [.night, .day, .sunrise, .sunset]
let shouldShow: Bool = showEventTypes || !NTSolar.Phase.plottablePhases.contains(phase)
return (shouldShow && !hiddenPhases.contains(phase)) ? 1 : 0
}

Expand Down Expand Up @@ -307,7 +306,7 @@ extension DaylightChart {
solar.daylightDuration / dayLength
}

func pointMarkColor(for eventPhase: Solar.Phase) -> HierarchicalShapeStyle {
func pointMarkColor(for eventPhase: NTSolar.Phase) -> HierarchicalShapeStyle {
switch eventPhase {
case .astronomical:
return .quaternary
Expand Down Expand Up @@ -383,13 +382,13 @@ extension DaylightChart {
Form {
Group {
DaylightChart(
solar: Solar(coordinate: TemporaryLocation.placeholderLondon.coordinate)!,
solar: NTSolar(for: .now, coordinate: TemporaryLocation.placeholderLondon.coordinate, timeZone: TemporaryLocation.placeholderLondon.timeZone)!,
timeZone: TimeZone.autoupdatingCurrent,
scrubbable: true
)

DaylightChart(
solar: Solar(coordinate: TemporaryLocation.placeholderLondon.coordinate)!,
solar: NTSolar(for: .now, coordinate: TemporaryLocation.placeholderLondon.coordinate, timeZone: TemporaryLocation.placeholderLondon.timeZone)!,
timeZone: TimeZone.autoupdatingCurrent,
appearance: .graphical,
scrubbable: true
Expand Down
2 changes: 0 additions & 2 deletions Solstice/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import SwiftUI
import CoreData
import Solar
import Suite
import TimeMachine

Expand Down Expand Up @@ -187,4 +186,3 @@ struct ContentView: View {
.environment(CurrentLocation())
.environment(LocationSearchService())
}

Loading