Skip to content
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

Changed from a struct to a class #33

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ Solar performs its calculations locally using an algorithm from the [United Stat

## Usage


Solar simply needs a date and a location specified as a latitude and longitude:

```swift
let solar = Solar(for: someDate, latitude: 51.528308, longitude: -0.1340267)
let solar = Solar(for: someDate, CLLocationCoordinate2D(latitude: 51.528308, longitude: -0.1340267))
let sunrise = solar.sunrise
let sunset = solar.sunset
```

We can also omit providing a date if we just need the sunrise and sunset for today:

```swift
let solar = Solar(latitude: 51.528308, longitude: -0.1340267)
let solar = Solar(CLLocationCoordinate2D(latitude: 51.528308, longitude: -0.1340267))
let sunrise = solar.sunrise
let sunset = solar.sunset
```

Solar with then cache the calculation and update it as the time moves when you ask.

Note that all dates are UTC. Don't forget to format your date into the appropriate timezone if required.

### Types of sunrise and sunset
Expand Down
7 changes: 7 additions & 0 deletions Solar iOSTests/Solar_iOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,11 @@ final class Solar_iOSTests: XCTestCase {
let solar2 = Solar(for: testDate, coordinate: invalidCoordinate2)
XCTAssertNil(solar2)
}

func testSolar_implicit_creation_for_currentTime() {
let city = cities.first(where: { $0.name == "London" })!
let solar = Solar(coordinate: city.coordinate)

XCTAssertNotNil(solar, "Solar creation work without time")
}
}
6 changes: 3 additions & 3 deletions Solar.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Pod::Spec.new do |s|
s.name = "Solar"
s.version = "2.1.0"
s.version = "3.1.0"
s.summary = "A Swift library for generating Sunrise and Sunset times."
s.description = "A Swift library for generating Sunrise and Sunset times. All calculations take place locally without the need for a network request."
s.homepage = "http://github.com/ceek/solar"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Chris Howell" => "chris.kevin.howell@gmail.com" }
s.author = { "Chris Howell" => "chris.kevin.howell@gmail.com" }
s.ios.deployment_target = '8.0'
s.watchos.deployment_target = '3.0'
s.tvos.deployment_target = '9.0'
s.osx.deployment_target = '10.9'
s.source = { :git => "https://github.com/ceek/Solar.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/ceek/Solar.git", :tag => "#{s.version}" }
s.source_files = "Solar/*.{swift}"
s.requires_arc = true
end
140 changes: 137 additions & 3 deletions Solar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
14456B861EF96ACA00D76A4D /* Solar_iOSTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Solar_iOSTests.swift; path = "Solar iOSTests/Solar_iOSTests.swift"; sourceTree = "<group>"; };
14456B891EF96AD900D76A4D /* CorrectResults.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = CorrectResults.json; path = "Solar iOSTests/CorrectResults.json"; sourceTree = "<group>"; };
14456B8A1EF96AD900D76A4D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = "Solar iOSTests/Info.plist"; sourceTree = "<group>"; };
55C04150209A25A100A642BC /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
55D65083209A3D1800D69A50 /* Solar_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Solar_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
55D65093209A3D5D00D69A50 /* Info-macOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = "<group>"; };
55D65098209A3DEF00D69A50 /* Solar.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Solar.podspec; sourceTree = "<group>"; };
97837EAB1E4BB1DE000FEF64 /* Solar_iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Solar_iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F7FC5B5A1D469B2700C4D3EB /* Solar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Solar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F7FC5B651D469B4E00C4D3EB /* Solar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Solar.swift; sourceTree = "<group>"; };
Expand All @@ -46,6 +50,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
55D6507F209A3D1800D69A50 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
97837EA81E4BB1DE000FEF64 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -97,6 +108,8 @@
F7FC5B5C1D469B2700C4D3EB /* Solar */,
14456B801EF96A8F00D76A4D /* Solar iOSTests */,
F7FC5B5B1D469B2700C4D3EB /* Products */,
55C04150209A25A100A642BC /* README.md */,
55D65098209A3DEF00D69A50 /* Solar.podspec */,
);
sourceTree = "<group>";
};
Expand All @@ -106,6 +119,7 @@
F7FC5B5A1D469B2700C4D3EB /* Solar.framework */,
97837EAB1E4BB1DE000FEF64 /* Solar_iOSTests.xctest */,
1410E9C01EF12B5A001829A5 /* Solar.framework */,
55D65083209A3D1800D69A50 /* Solar_macOS.framework */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -115,6 +129,7 @@
children = (
F7FC5B651D469B4E00C4D3EB /* Solar.swift */,
1410E9B71EF12AD4001829A5 /* Info-iOS.plist */,
55D65093209A3D5D00D69A50 /* Info-macOS.plist */,
1410E9B81EF12AD4001829A5 /* Info-watchOS.plist */,
);
path = Solar;
Expand All @@ -130,6 +145,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
55D65080209A3D1800D69A50 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
F7FC5B571D469B2700C4D3EB /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -158,6 +180,24 @@
productReference = 1410E9C01EF12B5A001829A5 /* Solar.framework */;
productType = "com.apple.product-type.framework";
};
55D65082209A3D1800D69A50 /* Solar_macOS */ = {
isa = PBXNativeTarget;
buildConfigurationList = 55D6508A209A3D1900D69A50 /* Build configuration list for PBXNativeTarget "Solar_macOS" */;
buildPhases = (
55D6507E209A3D1800D69A50 /* Sources */,
55D6507F209A3D1800D69A50 /* Frameworks */,
55D65080209A3D1800D69A50 /* Headers */,
55D65081209A3D1800D69A50 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = Solar_macOS;
productName = Solar_macOS;
productReference = 55D65083209A3D1800D69A50 /* Solar_macOS.framework */;
productType = "com.apple.product-type.framework";
};
97837EAA1E4BB1DE000FEF64 /* Solar_iOSTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 97837EB51E4BB1DE000FEF64 /* Build configuration list for PBXNativeTarget "Solar_iOSTests" */;
Expand Down Expand Up @@ -208,9 +248,14 @@
CreatedOnToolsVersion = 8.3.3;
ProvisioningStyle = Manual;
};
55D65082209A3D1800D69A50 = {
CreatedOnToolsVersion = 9.3;
DevelopmentTeam = V7JGZY6Z4Z;
ProvisioningStyle = Automatic;
};
97837EAA1E4BB1DE000FEF64 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 34J4G6G665;
DevelopmentTeam = V7JGZY6Z4Z;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
Expand All @@ -234,6 +279,7 @@
targets = (
F7FC5B591D469B2700C4D3EB /* Solar_iOS */,
1410E9BF1EF12B5A001829A5 /* Solar_watchOS */,
55D65082209A3D1800D69A50 /* Solar_macOS */,
97837EAA1E4BB1DE000FEF64 /* Solar_iOSTests */,
);
};
Expand All @@ -247,6 +293,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
55D65081209A3D1800D69A50 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
97837EA91E4BB1DE000FEF64 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -273,6 +326,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
55D6507E209A3D1800D69A50 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
97837EA71E4BB1DE000FEF64 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -354,11 +414,76 @@
};
name = Release;
};
55D65088209A3D1900D69A50 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = V7JGZY6Z4Z;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Solar/Info-macOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
PRODUCT_BUNDLE_IDENTIFIER = "me.chrishowell.Solar-macOS";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
55D65089209A3D1900D69A50 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = V7JGZY6Z4Z;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Solar/Info-macOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
PRODUCT_BUNDLE_IDENTIFIER = "me.chrishowell.Solar-macOS";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Release;
};
97837EB31E4BB1DE000FEF64 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
DEVELOPMENT_TEAM = 34J4G6G665;
DEVELOPMENT_TEAM = V7JGZY6Z4Z;
INFOPLIST_FILE = "Solar iOSTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.chrishowell.SolarTests;
Expand All @@ -373,7 +498,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
DEVELOPMENT_TEAM = 34J4G6G665;
DEVELOPMENT_TEAM = V7JGZY6Z4Z;
INFOPLIST_FILE = "Solar iOSTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.chrishowell.SolarTests;
Expand Down Expand Up @@ -550,6 +675,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
55D6508A209A3D1900D69A50 /* Build configuration list for PBXNativeTarget "Solar_macOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
55D65088209A3D1900D69A50 /* Debug */,
55D65089209A3D1900D69A50 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
97837EB51E4BB1DE000FEF64 /* Build configuration list for PBXNativeTarget "Solar_iOSTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
5 changes: 4 additions & 1 deletion Solar.xcodeproj/project.xcworkspace/contents.xcworkspacedata

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

6 changes: 2 additions & 4 deletions Solar.xcodeproj/xcshareddata/xcschemes/Solar iOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -71,7 +70,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion Solar/Info-iOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>3.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
24 changes: 24 additions & 0 deletions Solar/Info-macOS.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Solar/Info-watchOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>3.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down