About RDHDateAdjustment
RDHDateAdjustment is a powerful Swift library that provides a set of helpful methods for manipulating and adjusting dates easily. It’s designed to simplify common date operations and make it easier for developers to work with dates in their Swift projects.
Installation
To add RDHDateAdjustment to your project, simply follow these steps:
- Open your project in Xcode.
- Go to File -> Swift Packages -> Add Package Dependency.
- Enter the URL of the repo: https://github.com/rdhupar/RDHDateAdjustment.git
- Choose the version or branch you want to use.
- Click on Next and Xcode will handle the rest. The library will be added to your project and you can start using it.
Usage
The library provides a wide range of date manipulation options that can be accessed through the various methods it offers. Here are some common use cases:
Adjusting by Days
To adjust a date by a specific number of days, you can use the adjustDays(_:)
method.
let currentDate = Date()
let nextWeekDate = currentDate.adjustDays(7) // Adds 7 days to the current date
let previousWeekDate = currentDate.adjustDays(-7) // Subtracts 7 days from the current date
Adjusting by Months
If you want to adjust a date by a specific number of months, you can use the adjustMonths(_:)
method.
let currentDate = Date()
let nextMonthDate = currentDate.adjustMonths(1) // Adds 1 month to the current date
let previousMonthDate = currentDate.adjustMonths(-1) // Subtracts 1 month from the current date
Adjusting by Years
For adjusting by years, the adjustYears(_:)
method can be used.
let currentDate = Date()
let nextYearDate = currentDate.adjustYears(1) // Adds 1 year to the current date
let previousYearDate = currentDate.adjustYears(-1) // Subtracts 1 year from the current date
Comparing Dates
The library also provides methods for comparing dates. Here’s an example:
let date1 = Date()
let date2 = Date(timeIntervalSinceNow: 3600) // 1 hour ahead of date1
let isSameDate = date1.isSameDate(as: date2) // Check if date1 and date2 represent the same calendar date
let isBefore = date1.isBefore(date2) // Check if date1 is before date2
let isAfter = date1.isAfter(date2) // Check if date1 is after date2
Documentation
For detailed documentation on all available methods and usage examples, please visit the project’s GitHub repository.
Contributing
If you’d like to contribute to RDHDateAdjustment, feel free to submit a pull request on the GitHub repository. Your contributions are highly appreciated.
License
RDHDateAdjustment is released under the MIT License. See the LICENSE file for more information.