gitmyhub

DateTools

Objective-C ★ 7.2k updated 1y ago

Dates and times made easy in iOS

An iOS library that makes date and time handling easy in Objective-C and Swift, add human-readable 'time ago' strings in 35+ languages, natural-language date arithmetic, and time period overlap checks.

Objective-CSwiftCocoaPodsiOSsetup: easycomplexity 2/5

DateTools is an iOS library that makes working with dates and times much easier in Objective-C and Swift. Apple's built-in date handling requires a lot of setup code to do common tasks: getting the year or month out of a date, comparing two dates, or calculating how long ago something happened. DateTools reduces that boilerplate to short, readable calls.

The library adds several categories of functionality. "Time Ago" strings convert a past date into a phrase like "2 days ago" or a short form like "2d", with translations available in over 35 languages including Arabic, Japanese, Hindi, and Welsh. Date components like year, month, and day become simple properties on a date object. Date arithmetic is written in natural English: 2.days.earlier gives you a date two days before now. Date comparison methods let you check whether two dates are on the same day, in the same week, or within a certain time interval of each other.

The more distinctive feature is the Time Period concept. A Time Period is a span of time with a defined start and end. You can check relationships between two periods: whether one contains the other, whether they overlap, and by how much. Time Periods can be grouped into Collections (an unordered set) or Chains (sequential, where each period starts as the previous one ends), which makes reasoning about schedules and event sequences easier.

Installation is through CocoaPods, the standard iOS dependency manager. Both Objective-C and Swift versions are available. The README notes that DateTools has been used in well-known apps including YouTube Music and Khan Academy. It is distributed under the MIT license.

Where it fits