krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

Packages/MoonriseKit/Tests/SkyEngineTests/TonightTests.swift

24 lines · 882 bytes

 1import Foundation
 2import Testing
 3@testable import SkyEngine
 4
 5@Test func tonightFromDarkStartsNowAndEndsAtSunrise() throws {
 6    // 2026-10-17 02:00 UT is 21:00 CDT on the 16th: already dark in Chicago.
 7    let t = try Tonight(at: observed, from: chicago)
 8    #expect(t.start == observed)
 9    #expect(t.sunset == nil)
10    let sunrise = try #require(t.sunrise)
11    #expect(abs(sunrise.timeIntervalSince(ut(12, 6))) < 120)
12    let saturn = try #require(t.planets.first { $0.body == .saturn })
13    #expect(saturn.best != nil)
14    #expect(t.planets.first?.best != nil)
15}
16
17@Test func tonightFromAfternoonStartsAtSunset() throws {
18    // 2026-10-17 18:00 UT is 13:00 CDT.
19    let afternoon = ut(18, 0)
20    let t = try Tonight(at: afternoon, from: chicago)
21    let sunset = try #require(t.sunset)
22    #expect(abs(sunset.timeIntervalSince(ut(23, 6))) < 120)
23    #expect(t.start == sunset)
24}