From 38bf02e344ae4b345a4972cadd04036eb4ddb682 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 26 Jul 2019 17:17:22 -0600 Subject: [PATCH] Initial bits for Beat - a package for diddling .beat time https://www.swatch.com/en_us/internet-time --- .gitignore | 4 ++++ Package.swift | 28 +++++++++++++++++++++++++++ README.md | 5 +++++ Sources/Beat/Beat.swift | 18 +++++++++++++++++ Tests/BeatTests/BeatTests.swift | 17 ++++++++++++++++ Tests/BeatTests/XCTestManifests.swift | 9 +++++++++ Tests/LinuxMain.swift | 7 +++++++ 7 files changed, 88 insertions(+) create mode 100644 .gitignore create mode 100644 Package.swift create mode 100644 README.md create mode 100644 Sources/Beat/Beat.swift create mode 100644 Tests/BeatTests/BeatTests.swift create mode 100644 Tests/BeatTests/XCTestManifests.swift create mode 100644 Tests/LinuxMain.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02c0875 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e1a44cd --- /dev/null +++ b/Package.swift @@ -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"]), + ] +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..8097d55 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Beat + +Library for printing time in Swatch .beat time. + +More info [here](https://www.swatch.com/en_us/internet-time). diff --git a/Sources/Beat/Beat.swift b/Sources/Beat/Beat.swift new file mode 100644 index 0000000..3c54db6 --- /dev/null +++ b/Sources/Beat/Beat.swift @@ -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)" + } +} diff --git a/Tests/BeatTests/BeatTests.swift b/Tests/BeatTests/BeatTests.swift new file mode 100644 index 0000000..b69a4a1 --- /dev/null +++ b/Tests/BeatTests/BeatTests.swift @@ -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), + ] +} diff --git a/Tests/BeatTests/XCTestManifests.swift b/Tests/BeatTests/XCTestManifests.swift new file mode 100644 index 0000000..82c36db --- /dev/null +++ b/Tests/BeatTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(BeatTests.allTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..d36e18f --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import BeatTests + +var tests = [XCTestCaseEntry]() +tests += BeatTests.allTests() +XCTMain(tests)