Date - leacode/SwiftWings GitHub Wiki
Source: Sources/Extensions/Foundation/Date
Tests: Tests/Extensions/Date
SwiftWings provides an extensive date toolkit that works across Apple platforms and Linux.
- Timestamp helpers (
timeMillis,currentTimeMillis). - Calendar checks (
isToday,isTomorrow,isInThisWeek,isInNextWeek). - Convenience accessors for adjacent days/weeks/months/years (e.g.
lastMonday,nextMonth).
- Adds computed properties for every
Calendar.Component(year,month,weekday, etc.) usingCalendar.current.
- Start/end of component calculations,
isSame(_:as:),difference(to:component:),isBetween,clamped, and generaladvanced(_:value:)arithmetic. - New DST-aware helpers (
interval(of:timeZone:),distanceComponents(to:timeZone:)).
- Wall-clock conversions between time zones, formatted output pinned to a
TimeZone, and component extraction using injected calendars.
- Convenience wrappers around
Calendar.dateInterval(of:for:)anddateComponents(_:from:to:)with time-zone overrides.
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "America/Los_Angeles")!
let meeting = DateComponents(calendar: calendar,
year: 2024,
month: 3,
day: 10,
hour: 9).date!
print(meeting.isToday) // depends on current date
print(meeting.start(of: .day, calendar: calendar)!) // 2024-03-10 08:00:00 +0000
print(meeting.interval(of: .day, timeZone: calendar.timeZone)?.duration ?? 0) // 82800 (23h, DST day)
let tokyo = TimeZone(identifier: "Asia/Tokyo")!
print(meeting.converted(from: calendar.timeZone, to: tokyo)
.formatted("yyyy-MM-dd HH:mm", timeZone: tokyo, locale: Locale(identifier: "en_US_POSIX")))
// "2024-03-11 01:00"