Skip to content

Commit

Permalink
Merge branch 'master' of github.com:batoulapps/adhan-swift
Browse files Browse the repository at this point in the history
  • Loading branch information
z3bi committed Oct 12, 2018
2 parents 692e16f + c8e26f6 commit 7e972c4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Adhan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
WATCHOS_DEPLOYMENT_TARGET = 3.0;
};
name = Debug;
};
Expand All @@ -1013,7 +1013,7 @@
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
WATCHOS_DEPLOYMENT_TARGET = 3.0;
};
name = Release;
};
Expand Down
18 changes: 14 additions & 4 deletions AdhanTests/TimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ class TimeTests: XCTestCase {
}

func testTimes() {
#if os(Linux)
let fileManager = FileManager.default
let currentDir = URL(fileURLWithPath: fileManager.currentDirectoryPath)
let fixtureDir = currentDir.appendingPathComponent("Shared/Times")
let paths = try! fileManager.contentsOfDirectory(at: fixtureDir, includingPropertiesForKeys: nil)
.filter { $0.pathExtension == "json" }
#else
let bundle = Bundle(for: type(of: self))
let paths = bundle.paths(forResourcesOfType: "json", inDirectory: "Times")
.compactMap(URL.init(fileURLWithPath:))
#endif

for path in paths {
var output = "################\nTime Test Output\n"
let data = try? Data(contentsOf: URL(fileURLWithPath: path))
let data = try? Data(contentsOf: path)
let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary
let params = json["params"] as! NSDictionary
let lat = params["latitude"] as! NSNumber
Expand Down Expand Up @@ -94,8 +104,8 @@ class TimeTests: XCTestCase {

let variance = json["variance"] as? Double ?? 0
let times = json["times"] as! [NSDictionary]
output += "Times for \((path as NSString).lastPathComponent) - \(params["method"]!)\n"
print("Testing \((path as NSString).lastPathComponent) (\(times.count) days)")
output += "Times for \(path.lastPathComponent) - \(params["method"]!)\n"
print("Testing \(path.lastPathComponent) (\(times.count) days)")
var totalDiff = 0.0
var maxDiff = 0.0
for time in times {
Expand Down Expand Up @@ -140,7 +150,7 @@ class TimeTests: XCTestCase {
output += "\($0.1.prefix(1).capitalized): \(timeFormatter.string(from: $0.0).padding(toLength: paddingLength, withPad: " ", startingAt: 0)) JSON: \(jsonTime.padding(toLength: paddingLength, withPad: " ", startingAt: 0)) Diff: \(Int($0.2))\n"
}
}
output += "Difference for \((path as NSString).lastPathComponent) - \(params["method"]!)\n"
output += "Difference for \(path.lastPathComponent) - \(params["method"]!)\n"
output += "Average difference: \(totalDiff/Double(times.count * 6))\n"
output += "Max difference: \(maxDiff)\n"
if maxDiff > 0 {
Expand Down
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Adhan",
products: [
.library(
name: "Adhan",
targets: ["Adhan"]
)
],
targets: [
.target(
name: "Adhan",
path: "Sources",
exclude: ["AdhanObjc.swift"]
),
.testTarget(
name: "Tests",
dependencies: ["Adhan"],
path: "AdhanTests",
exclude: ["ObjcTests.m", "Info.plist"]
)
]
)
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ Adhan supports [Carthage](https://github.com/Carthage/Carthage). Simply add the
github "batoulapps/adhan-swift" "master"
```

### Swift Package Manager

Adhan supports [SPM](https://swift.org/package-manager/). Simply add the following line to your dependencies value of your `Package.swift` file:

```swift
// swift-tools-version:4.2
dependencies: [
.package(url: "https://github.com/batoulapps/adhan-swift", .branch("master")),
]
```

### Manual

Expand Down Expand Up @@ -133,7 +142,7 @@ let formatter = DateFormatter()
formatter.timeStyle = .medium
formatter.timeZone = TimeZone(identifier: "America/New_York")!

print("fajr %@", formatter.string(from: prayers.fajr))
print("fajr \(formatter.string(from: prayers.fajr))")
```

## Full Example
Expand All @@ -148,19 +157,19 @@ if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationPa
let formatter = DateFormatter()
formatter.timeStyle = .medium
formatter.timeZone = TimeZone(identifier: "America/New_York")!
print("fajr %@", formatter.string(from: prayers.fajr))
print("sunrise %@", formatter.string(from: prayers.sunrise))
print("dhuhr %@", formatter.string(from: prayers.dhuhr))
print("asr %@", formatter.string(from: prayers.asr))
print("maghrib %@", formatter.string(from: prayers.maghrib))
print("isha %@", formatter.string(from: prayers.isha))

print("fajr \(formatter.string(from: prayers.fajr))")
print("sunrise \(formatter.string(from: prayers.sunrise))")
print("dhuhr \(formatter.string(from: prayers.dhuhr))")
print("asr \(formatter.string(from: prayers.asr))")
print("maghrib \(formatter.string(from: prayers.maghrib))")
print("isha \(formatter.string(from: prayers.isha))")
}
```

## Convenience Utilities

The `PrayerTimes` struct has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it
The `PrayerTimes` struct has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it
easier to dynamically show countdowns until the next prayer.

```swift
Expand Down Expand Up @@ -193,9 +202,9 @@ let qiblaDirection = Qibla(coordinates: nyc).direction

## Contributing

Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all
developers. We accept feature contributions provided that they are properly documented and include the appropriate
unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different
Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all
developers. We accept feature contributions provided that they are properly documented and include the appropriate
unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different
locations, we do ask that the source of the comparison values be properly documented.

## License
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/CalculationMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Foundation

/* Preset calculation parameters */
public enum CalculationMethod {
public enum CalculationMethod: CaseIterable {

// Muslim World League
case muslimWorldLeague
Expand Down

0 comments on commit 7e972c4

Please sign in to comment.