<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Date math for lazy people</title>
	<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Tue, 06 Jan 2009 03:47:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Konstantin Shilov</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-17187</link>
		<author>Konstantin Shilov</author>
		<pubDate>Thu, 04 Dec 2008 11:34:06 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-17187</guid>
		<description>To add a week support, you can modify your script, and add this lines:
&lt;pre class="code"&gt;
switch(datepart.toLocaleLowerCase()) 
{
    ...

    case "week":
        datepart = "date";
        number = number * 7;
        break;

    ...
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>To add a week support, you can modify your script, and add this lines:</p>
<pre class="code">
switch(datepart.toLocaleLowerCase())
{
    ...

    case "week":
        datepart = "date";
        number = number * 7;
        break;

    ...
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-16069</link>
		<author>peterd</author>
		<pubDate>Tue, 07 Oct 2008 19:21:08 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-16069</guid>
		<description>Vesta,
That's OK, gush away.

Peter</description>
		<content:encoded><![CDATA[<p>Vesta,<br />
That&#8217;s OK, gush away.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vesta</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-16068</link>
		<author>Vesta</author>
		<pubDate>Tue, 07 Oct 2008 19:07:02 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-16068</guid>
		<description>I hate to gush, but this is terrific.  Now a part of my utilities from now until forever!</description>
		<content:encoded><![CDATA[<p>I hate to gush, but this is terrific.  Now a part of my utilities from now until forever!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: i0n</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-12665</link>
		<author>i0n</author>
		<pubDate>Tue, 13 May 2008 18:55:35 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-12665</guid>
		<description>A optimize version of the code.

Note: I do not use a ColdFusion Server. Modify it has your require for that.

&lt;pre class="code"&gt;
public static function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date {
		    date = date == null ? new Date() : new Date(date.time);
		
		    switch(datepart.toLocaleLowerCase()) {

		    	case "y":
		    	case "fullyear":
		        case "yyyy":
		        case "year":
		            datepart = "fullYear";
		            break;
		            
		        case "m":
		        case "month":
		            datepart = "month";
		            break;
		        
		        case "d":
		        case "day":
		        case "date":
		            datepart = "date";
		            break;
		            
		        case "h":
		        case "hours":
		            datepart = "hours";
		            break;
	            
	            case "minutes":
		        case "n":
		            datepart = "minutes";
		            break;
		            
	            case "seconds":
		        case "s":
		            datepart = "seconds";
		            break;
		            
		        case "milliseconds":
		        case "l":
		            datepart = "milliseconds";
		            break;
	            default:
		            datepart = null;
		    }
		
		    if(datepart != null)
		    	date[datepart]  += number;
		    return date;
		}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>A optimize version of the code.</p>
<p>Note: I do not use a ColdFusion Server. Modify it has your require for that.</p>
<pre class="code">
public static function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date {
		    date = date == null ? new Date() : new Date(date.time);

		    switch(datepart.toLocaleLowerCase()) {

		    	case "y":
		    	case "fullyear":
		        case "yyyy":
		        case "year":
		            datepart = "fullYear";
		            break;

		        case "m":
		        case "month":
		            datepart = "month";
		            break;

		        case "d":
		        case "day":
		        case "date":
		            datepart = "date";
		            break;

		        case "h":
		        case "hours":
		            datepart = "hours";
		            break;

	            case "minutes":
		        case "n":
		            datepart = "minutes";
		            break;

	            case "seconds":
		        case "s":
		            datepart = "seconds";
		            break;

		        case "milliseconds":
		        case "l":
		            datepart = "milliseconds";
		            break;
	            default:
		            datepart = null;
		    }

		    if(datepart != null)
		    	date[datepart]  += number;
		    return date;
		}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: kpli</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-5575</link>
		<author>kpli</author>
		<pubDate>Fri, 28 Dec 2007 04:30:02 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-5575</guid>
		<description>Thanks for the info bro...i was searching for this for a long time...u're certainly pro at this...</description>
		<content:encoded><![CDATA[<p>Thanks for the info bro&#8230;i was searching for this for a long time&#8230;u&#8217;re certainly pro at this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prath</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-4986</link>
		<author>Prath</author>
		<pubDate>Wed, 12 Dec 2007 12:48:26 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-4986</guid>
		<description>Thanks dude. you made my day.</description>
		<content:encoded><![CDATA[<p>Thanks dude. you made my day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross MacLachlan</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-4932</link>
		<author>Ross MacLachlan</author>
		<pubDate>Mon, 10 Dec 2007 16:17:00 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-4932</guid>
		<description>"fullyear" does not work. It's actualy "fullYear" with the capital Y.
To fix this remove the ".toLowerCase()" and pass in correct case. change the
line-&#62; case "fullyear": 
to-&#62; case "fullYear":

Thanks for the example. I find this site more helpful than the Adobe site for finding the exact tweek you need.

Keep up the great work.</description>
		<content:encoded><![CDATA[<p>&#8220;fullyear&#8221; does not work. It&#8217;s actualy &#8220;fullYear&#8221; with the capital Y.<br />
To fix this remove the &#8220;.toLowerCase()&#8221; and pass in correct case. change the<br />
line-&gt; case &#8220;fullyear&#8221;:<br />
to-&gt; case &#8220;fullYear&#8221;:</p>
<p>Thanks for the example. I find this site more helpful than the Adobe site for finding the exact tweek you need.</p>
<p>Keep up the great work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-437</link>
		<author>peterd</author>
		<pubDate>Fri, 24 Aug 2007 19:55:48 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/#comment-437</guid>
		<description>I think this should work for the various date aliases, bringing my &lt;code&gt;dateAdd()&lt;/code&gt; function a bit closer in line with ColdFusion's (with the exception of support for "q" (quarter) and "ww" (week)):

&lt;pre class="code"&gt;
private function dateAdd(datepart:String = &#34;&#34;, number:Number = 0, date:Date = null):Date {
    if (date == null) {
        /* Default to current date. */
        date = new Date();
    }

    var returnDate:Date = new Date(date.time);

    &lt;span style="color:red;"&gt;switch(datepart.toLocaleLowerCase()) {
        case &#34;yyyy&#34;:
        case &#34;year&#34;:
            datepart = &#34;fullYear&#34;;
            break;
        case &#34;m&#34;:
            datepart = &#34;month&#34;;
            break;
        case &#34;y&#34;:
        case &#34;d&#34;:
        case &#34;w&#34;:
        case &#34;day&#34;:
            datepart = &#34;date&#34;;
            break;
        case &#34;h&#34;:
            datepart = &#34;hours&#34;;
            break;
        case &#34;n&#34;:
            datepart = &#34;minutes&#34;;
            break;
        case &#34;s&#34;:
            datepart = &#34;seconds&#34;;
            break;
        case &#34;l&#34;:
            datepart = &#34;milliseconds&#34;;
            break;
    }&lt;/span&gt;

    switch (datepart.toLowerCase()) {
        case &#34;fullyear&#34;:
        case &#34;month&#34;:
        case &#34;date&#34;:
        case &#34;hours&#34;:
        case &#34;minutes&#34;:
        case &#34;seconds&#34;:
        case &#34;milliseconds&#34;:
            returnDate[datepart]  = number;
            break;
        default:
            /* Unknown date part, do nothing. */
            break;
    }
    return returnDate;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I think this should work for the various date aliases, bringing my <code>dateAdd()</code> function a bit closer in line with ColdFusion&#8217;s (with the exception of support for &#8220;q&#8221; (quarter) and &#8220;ww&#8221; (week)):</p>
<pre class="code">
private function dateAdd(datepart:String = &quot;&quot;, number:Number = 0, date:Date = null):Date {
    if (date == null) {
        /* Default to current date. */
        date = new Date();
    }

    var returnDate:Date = new Date(date.time);

    <span style="color:red;">switch(datepart.toLocaleLowerCase()) {
        case &quot;yyyy&quot;:
        case &quot;year&quot;:
            datepart = &quot;fullYear&quot;;
            break;
        case &quot;m&quot;:
            datepart = &quot;month&quot;;
            break;
        case &quot;y&quot;:
        case &quot;d&quot;:
        case &quot;w&quot;:
        case &quot;day&quot;:
            datepart = &quot;date&quot;;
            break;
        case &quot;h&quot;:
            datepart = &quot;hours&quot;;
            break;
        case &quot;n&quot;:
            datepart = &quot;minutes&quot;;
            break;
        case &quot;s&quot;:
            datepart = &quot;seconds&quot;;
            break;
        case &quot;l&quot;:
            datepart = &quot;milliseconds&quot;;
            break;
    }</span>

    switch (datepart.toLowerCase()) {
        case &quot;fullyear&quot;:
        case &quot;month&quot;:
        case &quot;date&quot;:
        case &quot;hours&quot;:
        case &quot;minutes&quot;:
        case &quot;seconds&quot;:
        case &quot;milliseconds&quot;:
            returnDate[datepart]  = number;
            break;
        default:
            /* Unknown date part, do nothing. */
            break;
    }
    return returnDate;
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
