Skip to content

tamarnachmany/DateTools

 
 

Repository files navigation

DateTools: The Breakup

Banner

DateTools: The Breakup is a fork of DateTools, which divides its powerhouse category (NSDate+DateTools) into several classes based on the single responsibility principle. These classes can be used to transform the way dates are presented on your app.

The original Date Tools has about 107 methods in its DateTools category. Because they are all grouped together, they are all imported into a class in one line of code. The Breakup divides these methods among several classes according to their purpose, making the codebase easier to understand and use.

The methods used by these classes have been taken directly from Date Tools, so all the functionalities of the original CocoaPod have been preserved. For information on what Date Tools can do, visit the [DateTime] (https://github.com/MatthewYork/DateTools).

Installation

Cocoapods

Add Code Pod Link

Manual Installation

All the classes required for DateTools are located in the DateTools folder in the root of this repository. They are listed below:

  • DTConstants.{h,m}
  • DTError.{h,m}
  • DTTimePeriod.{h,m}
  • DTTimePeriodChain.{h,m}
  • DTTimePeriodCollection.{h,m}
  • DTTimePeriodGroup.{h,m}
  • DateTools.h
  • NSDate+Comparators.{h,m}
  • NSDate+ComponentForDate.{h,m}
  • NSDate+ComponentForDateWithoutCalendar.{h,m}
  • NSDate+DateByAdding.{h,m}
  • NSDate+DateBySubtracting.{h,m}
  • NSDate+DateComponentsWithCalendar.{h,m}
  • NSDate+DateTools.{h,m}
  • NSDate+FormattedWithFormat.{h,m}
  • NSDate+FormattedWithStyle.{h,m}
  • NSDate+Helpers.{h,m}
  • NSDate+LocalizedStrings.{h,m}
  • NSDate+TimeAgo.{h,m}
  • NSDate+TimeFrom.{h,m}
  • NSDate+TimeFromCalendar.{h,m}
  • NSDate+TimeFromCalendar.{h,m}
  • NSDateConstants.{h,m}

The following bundle is necessary if you would like to support internationalization:

  • DateTools.bundle

Usage

Date Tools gives you access to many different methods that modify the way NSDate objects are presented on iOS apps

For a full documentation, please refer to the Date Tools ReadMe.

The primary difference between these two CocoaPods is that The Breakup changes NSDate+DateTools (one category on NSDate with many different types of methods, divided by #pragma mark) into several NSDate categories. Categories add methods to existing classes.

In this version, the comparator methods are all in one category, because these are all used for more or less the same purpose. In general, though, I have erred on the side of dividing methods as much as possible based on their purposes. For instance, dateByAdding and dateBySubtracting methods are in two separate categories.

Like Date Tools, NSDateTools: The Breakup offers a handful of methods that change the way dates can be displayed on your apps:

####NSDate+TimeAgo

This CocoaPod’s Time Ago methods (now found in NSDate+TimeAgo) change the way dates are displayed on your app.

####NSDate+LocalizedStrings

Using this category, you can easily translate the dates on your app into 32 languages (with two Chinese dialects).

####NSDate+DateComponentsWithCalendar

This category streamlines the process of getting date components from an NSDate.

Without Date Tools, you have to create a whole bunch of objects to get date components from an NSDate:

1. Create calendar
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unitFlags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];

2. Get components
NSInteger hour = dateComponents.hour;
NSInteger minute = dateComponents.minute;
NSInteger second = dateComponents.second;

With DateTools, grabbing components from a date is as simple as:

NSInteger hour = date.hour;
NSInteger minute = date.minute;
NSInteger second = date.second;

Thanks to Matthew York for his work on Date Tools, Kevin Lawler for his work on NSDate+TimeAgo, and all the others who have contributed to this CocoaPod.

About

Dates and times made easy in Objective-C

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 99.8%
  • Ruby 0.2%