Skip to content

About

A simple date extension that easily allows you to provide custom repeat date options for the Gregorian calendar.

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Repository files navigation

custom-repeat-date

CI

A simple date extension that easily allows you to provide custom repeat date options for the Gregorian calendar. The package has been created and used for Expenses.app, inspired by Apple Reminders and Bluebird.

Usage

let option = CustomRepeatDateOption.monthly(frequency: 3, option: .daysOfWeek(weekdayOrdinal: .second, weekday: .tuesday))
let calendar = Calendar(identifier: .gregorian)

let startDate = date(year: 2022, month: 5, day: 5)                 // 2022-05-05 22:22:22 +0000
let repeat1 = calendar.nextDate(after: startDate, option: option)! // 2022-05-10 22:22:22 +0000
let repeat2 = calendar.nextDate(after: repeat1, option: option)!   // 2022-08-09 22:22:22 +0000
let repeat3 = calendar.nextDate(after: repeat2, option: option)!   // 2022-11-08 22:22:22 +0000
let repeat4 = calendar.nextDate(after: repeat3, option: option)!   // 2023-02-14 22:22:22 +0000
let repeat5 = calendar.nextDate(after: repeat4, option: option)!   // 2023-05-09 22:22:22 +0000

Handle the optional result in production code. Invalid options, non-finite dates, dates outside years 1 through 9999 CE (UTC), and searches with no matching date return nil. Dates must also be in the CE era in the calendar's time zone. Every returned date is strictly later than the starting date.

To see how it works in practice, check out Examples.

ex. 1 ex. 2

About

A simple date extension that easily allows you to provide custom repeat date options for the Gregorian calendar.

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages