import Foundation import Testing @testable import WebsiteLibrary @Suite( "Date+Stamps extension", .tags(.extensionTests) ) struct DateStampsTests { // MARK: Methods tests @Test(arguments: zip( [0, -86_400, -172_800, -25_920_000] as [TimeInterval], ["today, 09:14", "yesterday, 09:14", "21 Sep, 09:14", "27 Nov 2025, 08:14"] )) func `stamps a date relative to today, on Amsterdam's clock`( offset: TimeInterval, expects stamp: String ) { #expect(Date.stub.addingTimeInterval(offset).stamp(relativeTo: .stub) == stamp) } @Test func `tells days apart at Amsterdam's midnight, not UTC's`() { // 23:30 and 01:00 in Amsterdam are 21:30 and 23:00 UTC: one day to UTC, two to Amsterdam. let lateEvening = Date.stub.addingTimeInterval(-35_040) let smallHours = Date.stub.addingTimeInterval(-29_640) #expect(lateEvening.stamp(relativeTo: smallHours) == "yesterday, 23:30") } @Test(arguments: zip( [171_000, 1_800, 180_000, 259_260] as [TimeInterval], ["47 h left", "under an hour left", "2 days left", "3 days left"] )) func `counts down in hours, then days`( interval: TimeInterval, expects countdown: String ) { #expect(Date.stub.addingTimeInterval(interval).countdown(from: .stub) == countdown) } }