<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Making time periods readable</title>
	<atom:link href="http://aidanlister.com/2004/04/making-time-periods-readable/feed/" rel="self" type="application/rss+xml" />
	<link>http://aidanlister.com/2004/04/making-time-periods-readable/</link>
	<description>Code is poetry</description>
	<lastBuildDate>Sat, 05 May 2012 15:50:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: jagged software</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-3825</link>
		<dc:creator>jagged software</dc:creator>
		<pubDate>Mon, 12 Mar 2012 16:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-3825</guid>
		<description>Thanks for sharing!
Modified to return compact strings:
duration(234567,true) = &quot;2d 17h 9m 27s&quot;

function duration($seconds, $compact=false, $use=null) {
    $periods = array (
        &#039;years&#039;     =&gt; 31556926,
        &#039;months&#039;    =&gt; 2629743,
        &#039;weeks&#039;     =&gt; 604800,
        &#039;days&#039;      =&gt; 86400,
        &#039;hours&#039;     =&gt; 3600,
        &#039;minutes&#039;   =&gt; 60,
        &#039;seconds&#039;   =&gt; 1
        );
 	$zeros = false;
    $seconds = (float)$seconds;
    $segments = array();
    foreach ($periods as $period =&gt; $value) {
        if ($use &amp;&amp; strpos($use, $period[0]) === false) continue;
        $count = floor($seconds / $value);
        if ($count == 0 &amp;&amp; !$zeros) continue;
		$key = $compact ? substr($period,0,1) : $period;
        $segments[strtolower($key)] = $count;
        $seconds = $seconds % $value;
    }
    $string = array();
    foreach ($segments as $key =&gt; $value) {
        $segment_name = $compact ? $key : &#039; &#039;.substr($key,0,-1);
        $segment = $value.$segment_name;
        if ($compact==false &amp;&amp; $value!=1) $segment .= &#039;s&#039;;
        $string[]=$segment;
    }
	if ( $compact ) return implode(&#039; &#039;, $string);
    return implode(&#039;, &#039;, $string);
}</description>
		<content:encoded><![CDATA[<p>Thanks for sharing!<br />
Modified to return compact strings:<br />
duration(234567,true) = &#8220;2d 17h 9m 27s&#8221;</p>
<p>function duration($seconds, $compact=false, $use=null) {<br />
    $periods = array (<br />
        &#8216;years&#8217;     =&gt; 31556926,<br />
        &#8216;months&#8217;    =&gt; 2629743,<br />
        &#8216;weeks&#8217;     =&gt; 604800,<br />
        &#8216;days&#8217;      =&gt; 86400,<br />
        &#8216;hours&#8217;     =&gt; 3600,<br />
        &#8216;minutes&#8217;   =&gt; 60,<br />
        &#8216;seconds&#8217;   =&gt; 1<br />
        );<br />
 	$zeros = false;<br />
    $seconds = (float)$seconds;<br />
    $segments = array();<br />
    foreach ($periods as $period =&gt; $value) {<br />
        if ($use &amp;&amp; strpos($use, $period[0]) === false) continue;<br />
        $count = floor($seconds / $value);<br />
        if ($count == 0 &amp;&amp; !$zeros) continue;<br />
		$key = $compact ? substr($period,0,1) : $period;<br />
        $segments[strtolower($key)] = $count;<br />
        $seconds = $seconds % $value;<br />
    }<br />
    $string = array();<br />
    foreach ($segments as $key =&gt; $value) {<br />
        $segment_name = $compact ? $key : &#8216; &#8216;.substr($key,0,-1);<br />
        $segment = $value.$segment_name;<br />
        if ($compact==false &amp;&amp; $value!=1) $segment .= &#8216;s&#8217;;<br />
        $string[]=$segment;<br />
    }<br />
	if ( $compact ) return implode(&#8216; &#8216;, $string);<br />
    return implode(&#8216;, &#8216;, $string);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ovidiu U</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-2490</link>
		<dc:creator>Ovidiu U</dc:creator>
		<pubDate>Thu, 24 Feb 2011 14:47:15 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-2490</guid>
		<description>Thank you, great function.</description>
		<content:encoded><![CDATA[<p>Thank you, great function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geetika</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-2443</link>
		<dc:creator>Geetika</dc:creator>
		<pubDate>Tue, 08 Feb 2011 07:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-2443</guid>
		<description>thnx.....alot.......for sharing......</description>
		<content:encoded><![CDATA[<p>thnx&#8230;..alot&#8230;&#8230;.for sharing&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-2020</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 01 Nov 2010 14:44:18 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-2020</guid>
		<description>Fantastic!!
What would I have to do to add  tenths and hundredths of a second?
Trying to nail down sub-second durations. 
Thanks a bunch!
Mark</description>
		<content:encoded><![CDATA[<p>Fantastic!!<br />
What would I have to do to add  tenths and hundredths of a second?<br />
Trying to nail down sub-second durations.<br />
Thanks a bunch!<br />
Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anya</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1867</link>
		<dc:creator>Anya</dc:creator>
		<pubDate>Thu, 14 Oct 2010 05:41:18 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1867</guid>
		<description>thanks for information!</description>
		<content:encoded><![CDATA[<p>thanks for information!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jm</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1413</link>
		<dc:creator>jm</dc:creator>
		<pubDate>Tue, 20 Apr 2010 18:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1413</guid>
		<description>I guess you cant post PHP within PHP tags...

echo time_duration(123, &#039;yMd&#039;);
echo time_duration(0);</description>
		<content:encoded><![CDATA[<p>I guess you cant post PHP within PHP tags&#8230;</p>
<p>echo time_duration(123, &#8216;yMd&#8217;);<br />
echo time_duration(0);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jm</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1412</link>
		<dc:creator>jm</dc:creator>
		<pubDate>Tue, 20 Apr 2010 18:09:08 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1412</guid>
		<description>Just wanted to point out a few bugs I found while working through this script.


</description>
		<content:encoded><![CDATA[<p>Just wanted to point out a few bugs I found while working through this script.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nbanba</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1402</link>
		<dc:creator>nbanba</dc:creator>
		<pubDate>Thu, 01 Apr 2010 19:05:46 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1402</guid>
		<description>Thanks! Very useful.</description>
		<content:encoded><![CDATA[<p>Thanks! Very useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aidan Lister</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1356</link>
		<dc:creator>Aidan Lister</dc:creator>
		<pubDate>Fri, 05 Feb 2010 13:35:51 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1356</guid>
		<description>toto, both years and months use the astronomical mean. Do you really think your visitors care if you&#039;re half a day off on a date that&#039;s a year away?</description>
		<content:encoded><![CDATA[<p>toto, both years and months use the astronomical mean. Do you really think your visitors care if you&#8217;re half a day off on a date that&#8217;s a year away?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: toto</title>
		<link>http://aidanlister.com/2004/04/making-time-periods-readable/comment-page-1/#comment-1355</link>
		<dc:creator>toto</dc:creator>
		<pubDate>Fri, 05 Feb 2010 07:18:15 +0000</pubDate>
		<guid isPermaLink="false">http://aidanlister.com/?p=47#comment-1355</guid>
		<description>totally fucked, years 366 / 365 months 28/29/30/31</description>
		<content:encoded><![CDATA[<p>totally fucked, years 366 / 365 months 28/29/30/31</p>
]]></content:encoded>
	</item>
</channel>
</rss>

