Parsing DateTime Strings in Objective-C

In my current project I found that I was coming back to the same section of code repeatedly and that I needed to refactor it out as well to maintain it, as I new that I would be back here quite a bit. The particular section of code was used for parsing date time strings into NSDate objects, the strings coming from RSS and Atom XML.

I had come across a few articles on parsing internet dates doing just this already and had seen a bit of code on GitHub doing this task as well. But what I didn’t find is a project doing just this on GitHub.

So I made one.

You can see it here.

This isn’t my first project on GitHub, but it is my first Objective-C one, and once more it’s something I actually need and hope others will too. To use it simply add the files in your project, include the header file and:

Or if you think you know the format used for your date you can give it a hint:

The NSDate Category supports parsing RFC 2822 and 3339 formatted dates. Right now it’s just the few common ones I’ve come across, but it handles the heavy lifting in a nice manner for you.

This is in large part based on Apples documentation about NSDateFormatter and Internet Dates.

Code 365: Day 39 – 42

Day 39 – A bit of this and that type of work.

Day 40-41: Zip Zilch Nada

Day 42: Finally got my NSDate Category for Internet Date Time parsing in objective-c up on GitHub! Take a look at it here.

Weekly Update

Tough week, my youngest has a pretty bad injury from snowboarding. Thought it was a simple fracture (even that’s lame) but it appears to be more than that. Still I got a few hours in and managed to get my NSDate Category out the door. I’d love to be able to spend larger chunks on my projects, but the idea was to spend at least an hour a day, and that I’m still hacking at.

Code 365: Day 38

So my code is extracted into a side project to encapsulate the category stuff I’ve done for NSDate. I polished it some making it more flexible and allowing for hints (more in a separate post).

Being the first piece of objective-c code I’ve shared, and only being an Objective-C programmer for 2 months I’m happy with what I have. This bit of code has been a great learning tool for:

  • Synchronization (NSLock)
  • NSFormatter
  • Various ways to implement the Singleton Pattern in Objective-C
  • The quirks of string conversion to dates in Objective-C/Cocoa
  • How various popular projects organize projects for presentation on GitHub

I still need to make a README before I push my code to GitHub, then I’m back to my main project.

Project Code 365 Progress

Doing a checkin now while it’s on my mind.

I’m 30 for 38 days, 3 for 5 weekly checkins and now 10% through the year! I wish I had not missed those two checkins, but I’m still staying the course on continued work on my project(s). It’s fun to be doing this and that’s what still counts.

Code 365: Day 36 & 37

Day 36

Worked on extracting some of my code into a new project which is turning into a nice diversion. Mostly learning, not a ton of code.

Day 37

I spent a bit of extra time enjoying my little diversion. It’s requiring me to dig into objective-c and cocoa a bit more, understanding how dates are handled and understanding more about the common date formats. I’m building a category for NSDate to handle conversion of strings to dates for the common date formats; I plan on putting it on GitHub once it’s ready for my own use?

Why go through the trouble of putting something on GitHub?

  1. I found that I kept coming back to this section of code and needing it to be more robust.
  2. Making something “good enough to show” others makes you do it right (or at least what your interpretation of right is).
  3. I’ve been helped by others who’ve shared their great libraries as open source.
  4. I couldn’t find what I needed already (though I was inspired by something coming close).

Anyhow, it should be “good enough to show” soon.

Code 365: Day 34 & 35

Day 34 – Super Bowl. Enough Said.

Day 35 – My intention was to finish a feature I started Saturday. But instead I discovered a bug to squash! Interesting bug, I’m not sure how I’d hit it outside of a development environment, but having your app crash on startup without doing anything is a fun one.

From there I worked on where I left off with my Testing on Saturday and ended up learning a lot about parsing “Internet Dates” in objective-c. Which led me to starting a little side project. More on that later.


Code 365: Day 32 & 33

Day 32 was intercepted by a date with my wife and indoor soccer for my kids.

Day 33, I worked on some new test code while sitting with my daughter at the ski lodge. I likely wouldn’t have gotten any programming in if not for her untimely crash on the mountain which resulted in a doctors visit for her.

Code 365: Day 30 & 31

Both of these days were no-codes. My schedule didn’t permit any time unfortunately.

Code 365: Day 29

So close, but the current piece of code is stretching my objective-c skills. Code blocks, main dispatch threads, access to variables in my success blocks. Definitely need more than an hour to finish this bit of code, more like 2 or 3. Unfortunately my schedule doesn’t have room tonight.

Code 365: Day 28

Went snowboarding today (one of my best days boarding ever if you were asking). Guess that bug was just for the evening, but my kids are still down with it . But coding must be done! I just need do one last feature and I can be done with my Beta!

Code 365: Day 27

Had a bug or something last night (now my girls have it) and was zonked out on the sofa by 7.