Get Updates By E-mail 

Article Written By:
Johann Dowa

NSDate Add-On Category For Easily Obtaining Locale Adjusted Date Information

  •  
  •  
  •  
  •  
  •  

If you’ve got an app that utilizes dates, and events then you’re going to need to make adjustments for user time differences and calendar differences.

Mattt  Thompson has created CupertinoYankee, an NSDate category that enhances NSDate to gather locale aware date information using NSCalendar and NSDateComponents to handle any complex calculations.

Provided are methods for gathering the beginning and end of the day, week, month or year based on the user’s locale.

Here’s an example as shown on the readme – entering:

NSLog(@"Current Time: %@", date);
NSLog(@"Beginning of Day:%@", [date beginningOfDay]);
NSLog(@"End of Day:%@", [date endOfDay]);
NSLog(@"Beginning of Week:%@", [date beginningOfWeek]);
NSLog(@"End of Week:%@", [date endOfWeek]);
NSLog(@"Beginning of Month:%@", [date beginningOfMonth]);
NSLog(@"End of Month:%@", [date endOfMonth]);
NSLog(@"Beginning of Year:%@", [date beginningOfYear]);
NSLog(@"End of Year:%@", [date endOfYear]);

Provides the result:

Current Time: 2012-04-17 06:12:21 +0000
Beginning of Day: 2012-04-16 07:00:00 +0000
End of Day 2012-04-17 06:59:59 +0000
Beginning of Week: 2012-04-16 07:00:00 +0000
End of Week: 2012-04-23 06:59:59 +0000
Beginning of Month: 2012-04-01 07:00:00 +0000
End of Month: 2012-05-01 06:59:59 +0000
Beginning of Year: 2012-01-01 08:00:00 +0000
End of Year: 2013-01-01 07:59:59 +0000

You can find CupertinoYankee on Github here.

A nice simple category making it easier to make adjustments for the user’s locale.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments