semantical/dated
Welcome to **Dated**, a Swift framework designed to help you work with dates in a way that aligns with a user's mental model, rather than physical time. This framework provides types for modeling calendrical concepts in a way that resembles a paper-based calendar, ensuring that d
Installation
Add the following dependency to your Package.swift file:
.package(url: "https://github.com/semantical/Dated.git", from: "0.0.1")[!WARNING] This package is in beta and breaking changes may occur in patch releases.
Usage
Calendar Subdivisions
let localDate = LocalDate.now
let date = CalendarDate(localDate) // or: CalendarDate.now
let day = date.day
let week = date.week
let month = date.month
let year = date.yearPerform calculations or iterate over ranges of calendar subdivisions.
let weekdays = Week.current.days
print(weekdays.map(\.veryShortWeekdaySymbol))
// On a system that uses a calendar with Monday as the first weekday,
// the result is ["M", "T", "W", "T", "F", "S", "S"]. If Sunday is the
// first weekday, we get ["S", "M", "T", "W", "T", "F", "S"] instead.
let today = Day.current
print(today.isInWeekend)
// Returns `true` when called on a weekend.
print(today.isToday)
// Always `true`.
// Print 10 days starting today.
for day in today..<(today + .days(10)) {
print(day.dayOfMonth)
}
// The same day next year.
let sameDayNextYear = today + .years(1)Time Differences and Date Intervals
You can create and manipulate time differences and date intervals easily.
let startDate = CalendarDate.now
let endDate = startDate + .days(5)
let interval = CalendarDateInterval(start: startDate, end: endDate)
print(interval.contains(CalendarDate.now)) // true
let duration = TimeDifference.minutes(120)
let newEndDate = startDate + duration
// Iterate over the daily intervals within the date interval.
for interval in interval.intervalsPerDay() {
// ...
}Package Metadata
Repository: semantical/dated
Default branch: main
README: README.md