DateToolsObjC

1.0.7

Package for Objective-C DateTools library. Parse, validate, manipulate, and display dates, time and timezones
3a4oT/DateToolsObjC

What's New

Release 1.0.7

2020-12-13T22:13:32Z

Build Status Carthage compatible Swift Package Manager compatible

Thank you, Matthew York and community for awesome library. You can find original repo/docs here. This package was created because I need Carthage support and distinguish between Swift and Objective-C implementation. Swift ABI not stable (yet) and I do not want to spend time to recompile binaries every time new Swift version come. Objective-C API works perfectly fine.

This is hard fork of original repo. This means there is no guarantee that codebase will fully reflect original repo.

  • DateTools removes the boilerplate required to access date components, handles more nuanced date comparisons, and serves as the foundation for entirely new concepts like Time Periods and their collections.

How to check if two date ranges overlaps in Objective-C? With DateTools it's really easy.

// Just example.
DTTimePeriod *periodA = [[DTTimePeriod alloc] initWithStartDate:request.startDate endDate:request.endDate];
DTTimePeriod *periodB = [[DTTimePeriod alloc] initWithStartDate:requestB.startDate endDate:requestB.endDate];
//Magic here
if ([periodA overlapsWith:periodB]) {
    NSLog(@"Is it cool?");
}

Use with Swift Package Manager

.package(url: "https://github.com/3a4oT/DateToolsObjC", .upToNextMajor(from: "1.0.5"))
  • Add to your Cartfile github "3a4oT/DateToolsObjC"
  • Run carthage build 3a4oT/DateToolsObjC
  • Add DateToolsObjC.framework to your target
  • In your *.h/*.m just @import DateToolsObjC;

Can I use it from Swift?

Well, technically yes. But...=) it will work for NSDate and not for Date out the box. You will ask why? Shorty - NSDate and Date are two different types (some more food). Don't be confused about other thing you may hear that's different. So far you have 3 option to go with

  1. Checkout original repo and use Swift API.
  2. Cast Date to NSDate and back:
    import DateToolsObjC
    
    let today: NSDate = Date() as NSDate
    //usage in DateToolsAPI return NSDate cast back if you need.
    let result: Date = today.timeAgo() as Date
  3. My favorite - just make Swift Extension under needed DateToolsObjC API which will cast NSDate to Date for you.

MIT License

Copyright (c) 2017 Petro Rovenskyi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Mar 24 2024 02:00:44 GMT-0900 (Hawaii-Aleutian Daylight Time)