Initial bits for Beat - a package for diddling .beat time
https://www.swatch.com/en_us/internet-time
This commit is contained in:
commit
38bf02e344
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
28
Package.swift
Normal file
28
Package.swift
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// swift-tools-version:5.1
|
||||||
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "Beat",
|
||||||
|
products: [
|
||||||
|
// Products define the executables and libraries produced by a package, and make them visible to other packages.
|
||||||
|
.library(
|
||||||
|
name: "Beat",
|
||||||
|
targets: ["Beat"]),
|
||||||
|
],
|
||||||
|
dependencies: [
|
||||||
|
// Dependencies declare other packages that this package depends on.
|
||||||
|
// .package(url: /* package url */, from: "1.0.0"),
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
|
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||||
|
.target(
|
||||||
|
name: "Beat",
|
||||||
|
dependencies: []),
|
||||||
|
.testTarget(
|
||||||
|
name: "BeatTests",
|
||||||
|
dependencies: ["Beat"]),
|
||||||
|
]
|
||||||
|
)
|
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Beat
|
||||||
|
|
||||||
|
Library for printing time in Swatch .beat time.
|
||||||
|
|
||||||
|
More info [here](https://www.swatch.com/en_us/internet-time).
|
18
Sources/Beat/Beat.swift
Normal file
18
Sources/Beat/Beat.swift
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct Beat {
|
||||||
|
fileprivate var db: Int
|
||||||
|
public init(_ epoch: Double) {
|
||||||
|
let utc_1 = Int(epoch + 3600)
|
||||||
|
let r = utc_1%86400
|
||||||
|
self.db = (Int(Double(r)/86.4))
|
||||||
|
}
|
||||||
|
|
||||||
|
public func int() -> Int {
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
public func text() -> String {
|
||||||
|
return "\(db)"
|
||||||
|
}
|
||||||
|
}
|
17
Tests/BeatTests/BeatTests.swift
Normal file
17
Tests/BeatTests/BeatTests.swift
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import Beat
|
||||||
|
|
||||||
|
final class BeatTests: XCTestCase {
|
||||||
|
func testBeat() {
|
||||||
|
let t = 1564181796.96353
|
||||||
|
let b = Beat(t)
|
||||||
|
|
||||||
|
XCTAssertGreaterThan(b.int(), 0)
|
||||||
|
XCTAssertLessThan(b.int(), 1000)
|
||||||
|
XCTAssertEqual(b.text(), "997")
|
||||||
|
}
|
||||||
|
|
||||||
|
static var allTests = [
|
||||||
|
("testBeat", testBeat),
|
||||||
|
]
|
||||||
|
}
|
9
Tests/BeatTests/XCTestManifests.swift
Normal file
9
Tests/BeatTests/XCTestManifests.swift
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import XCTest
|
||||||
|
|
||||||
|
#if !canImport(ObjectiveC)
|
||||||
|
public func allTests() -> [XCTestCaseEntry] {
|
||||||
|
return [
|
||||||
|
testCase(BeatTests.allTests),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
#endif
|
7
Tests/LinuxMain.swift
Normal file
7
Tests/LinuxMain.swift
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import XCTest
|
||||||
|
|
||||||
|
import BeatTests
|
||||||
|
|
||||||
|
var tests = [XCTestCaseEntry]()
|
||||||
|
tests += BeatTests.allTests()
|
||||||
|
XCTMain(tests)
|
Loading…
Reference in New Issue
Block a user