allow calling Beat() without passing in epoch
This commit is contained in:
parent
81caede8fc
commit
3938098a07
11
README.md
11
README.md
@ -2,4 +2,13 @@
|
|||||||
|
|
||||||
Library for printing time in Swatch .beat time.
|
Library for printing time in Swatch .beat time.
|
||||||
|
|
||||||
More info [here](https://www.swatch.com/en_us/internet-time).
|
More info on Swatch Internet Time [here](https://www.swatch.com/en_us/internet-time).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
``` Swift
|
||||||
|
let nb = Beat()
|
||||||
|
|
||||||
|
nb.int() // Gives ya back an Int
|
||||||
|
nb.text() // Gives ya back a String
|
||||||
|
```
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
public struct Beat {
|
public struct Beat {
|
||||||
fileprivate var db: Int
|
fileprivate var db: Int
|
||||||
public init(_ epoch: Double) {
|
public init(_ epoch: Double = Date().timeIntervalSince1970) {
|
||||||
let utc_1 = Int(epoch + 3600)
|
let utc_1 = Int(epoch + 3600)
|
||||||
let r = utc_1%86400
|
let r = utc_1%86400
|
||||||
self.db = (Int(Double(r)/86.4))
|
self.db = (Int(Double(r)/86.4))
|
||||||
|
@ -9,6 +9,11 @@ final class BeatTests: XCTestCase {
|
|||||||
XCTAssertGreaterThan(b.int(), 0)
|
XCTAssertGreaterThan(b.int(), 0)
|
||||||
XCTAssertLessThan(b.int(), 1000)
|
XCTAssertLessThan(b.int(), 1000)
|
||||||
XCTAssertEqual(b.text(), "997")
|
XCTAssertEqual(b.text(), "997")
|
||||||
|
|
||||||
|
// now beat
|
||||||
|
let nb = Beat()
|
||||||
|
XCTAssertGreaterThan(nb.int(), 0)
|
||||||
|
XCTAssertLessThan(nb.int(), 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
static var allTests = [
|
static var allTests = [
|
||||||
|
Loading…
Reference in New Issue
Block a user