allow calling Beat() without passing in epoch

This commit is contained in:
Aaron Bieber 2019-07-29 18:20:04 -06:00
parent 81caede8fc
commit 3938098a07
3 changed files with 16 additions and 2 deletions

View File

@ -2,4 +2,13 @@
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
```

View File

@ -2,7 +2,7 @@ import Foundation
public struct Beat {
fileprivate var db: Int
public init(_ epoch: Double) {
public init(_ epoch: Double = Date().timeIntervalSince1970) {
let utc_1 = Int(epoch + 3600)
let r = utc_1%86400
self.db = (Int(Double(r)/86.4))

View File

@ -9,6 +9,11 @@ final class BeatTests: XCTestCase {
XCTAssertGreaterThan(b.int(), 0)
XCTAssertLessThan(b.int(), 1000)
XCTAssertEqual(b.text(), "997")
// now beat
let nb = Beat()
XCTAssertGreaterThan(nb.int(), 0)
XCTAssertLessThan(nb.int(), 1000)
}
static var allTests = [