<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>farp.blog &#187; conversion</title>
	<atom:link href="http://fredandrandall.com/blog/tag/conversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://fredandrandall.com/blog</link>
	<description>Bloggin&#039; about whatever</description>
	<lastBuildDate>Tue, 04 Nov 2014 07:15:30 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Natural Time Conversion</title>
		<link>http://fredandrandall.com/blog/2010/10/02/natural-time-conversion/</link>
		<comments>http://fredandrandall.com/blog/2010/10/02/natural-time-conversion/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 01:50:59 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=78</guid>
		<description><![CDATA[Its Saturday, 2:00 PM and my Michigan Wolverines are have a football game at 3:30PM. I&#8217;m rushing to get out of the house and on my way to Ann Arbor. My girlfriend asks me, &#8220;how long before the game starts?&#8221; &#8230; <a href="http://fredandrandall.com/blog/2010/10/02/natural-time-conversion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2010/10/timeconversion.jpg"><img class="alignleft size-medium wp-image-82" title="timeconversion" src="http://fredandrandall.com/blog/wp-content/uploads/2010/10/timeconversion-300x137.jpg" alt="" width="300" height="137" /></a>Its Saturday, 2:00 PM and my Michigan Wolverines are have a football game at 3:30PM. I&#8217;m rushing to get out of the house and on my way to Ann Arbor. My girlfriend asks me, &#8220;how long before the game starts?&#8221;</p>
<p>There are lots of answers to that question. 90 minutes, 1 hour and 30 minutes, an hour and a half, etc. The last one is probably the most natural for a human to say.</p>
<p>So how do you convert a time you get from a computer into a natural spoken amount of time?<br />
<span id="more-78"></span><br />
It is fairly easy, there are just lots of little things. For example, if there is one hour, people often say &#8220;an&#8221; hour. Also, if there is only one hour you say &#8220;hour&#8221; instead of hours&#8221;. Same goes for minutes. Then there are half hours, quarter hours, and on and on.</p>
<p>I put together a simple little objective-c class that will convert a number in minutes into an NSString that would sound like a more natural duration.</p>
<pre class="brush: objc; title: ; notranslate">
//
//  NaturalTimeConverter.h
//  LocationBlaster
//
//  Created by Randall Brown on 9/27/10.
//  Copyright 2010 FARP. All rights reserved.
//

#import &lt;Foundation/Foundation.h&gt;


@interface NaturalTimeConverter : NSObject {

}

+(NSString*)stringWithNaturalTime:(NSInteger)numberOfMinutes;

@end

</pre>
<pre class="brush: objc; title: ; notranslate">

//
//  NaturalTimeConverter.m
//  LocationBlaster
//
//  Created by Randall Brown on 9/27/10.
//  Copyright 2010 FARP. All rights reserved.
//

#import &quot;NaturalTimeConverter.h&quot;


@implementation NaturalTimeConverter

+(NSString*)stringWithNaturalTime:(NSInteger)numberOfMinutes
{
	int hours = numberOfMinutes / 60;
	int minutes = numberOfMinutes % 60;
	
	NSString* timeString;
	if (hours == 0 )
	{
		if( minutes == 30 )
		{
			timeString = @&quot;half hour&quot;;
		}
		else if( minutes == 1 )
		{
			timeString = @&quot;minute&quot;;
		}
		else 
		{
			timeString = [NSString stringWithFormat:@&quot;%i minutes&quot;];
		}
	}
	else if( hours == 1 )
	{
		if( minutes == 30 )
		{
			timeString = @&quot;hour and a half&quot;;
		}
		else if( minutes == 1 )
		{
			timeString = @&quot;hour and 1 minute&quot;;
		}
		else 
		{
			timeString = [NSString stringWithFormat:@&quot;hour and %i minutes&quot;, minutes];
		}
	}
	else 
	{
		if( minutes == 30 )
		{
			timeString = [NSString stringWithFormat:@&quot;%i and a half hours&quot;, hours];
		}
		else if( minutes == 1 )
		{
			timeString = [NSString stringWithFormat:@&quot;%i hours and 1 minute&quot;, hours];
		}
		else 
		{
			timeString = [NSString stringWithFormat:@&quot;%i hours and %i minutes&quot;, hours, minutes];
		}
		
	}
	
	return timeString;
}

@end
</pre>
<p>Feel free to use and modify the code as you see fit. It probably doesn&#8217;t do everything everyone needs but at least it is a start.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2010/10/02/natural-time-conversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
