<?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>FlexOOP &#187; FlexDateUtils</title>
	<atom:link href="http://flexoop.com/category/code/flexdateutils/feed/" rel="self" type="application/rss+xml" />
	<link>http://flexoop.com</link>
	<description>Flex, AIR, ColdFusion, and everything in between</description>
	<lastBuildDate>Tue, 13 Jul 2010 03:56:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flex Date Utils &#8211; daysInYear, isLeapYear</title>
		<link>http://flexoop.com/2009/01/flex-date-utils-daysinyear-isleapyear/</link>
		<comments>http://flexoop.com/2009/01/flex-date-utils-daysinyear-isleapyear/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 03:13:02 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=129</guid>
		<description><![CDATA[These are the final 2 methods in my DateUtils Class of the FlexDateUtils library. I&#8217;ve got a Business class, a Holiday class and a DaylightSavingTimeUS class that are all included in the FlexDateUtils library, and I may go over those in the future, but not right now. /** * Gets the number of days in [...]]]></description>
			<content:encoded><![CDATA[<p>These are the final 2 methods in my DateUtils Class of the FlexDateUtils library.  I&#8217;ve got a Business class, a Holiday class and a DaylightSavingTimeUS class that are all included in the FlexDateUtils library, and I may go over those in the future, but not right now.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the number of days in the year
 * 
 * @param date	The date to check
 * 
 * @return		The total number of days in the year
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> daysInYear<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> DateUtils.<span style="color: #006600;">dateDiff</span><span style="color: #66cc66;">&#40;</span>
				DateUtils.<span style="color: #006600;">DAY_OF_MONTH</span>,
				<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>,
				DateUtils.<span style="color: #006600;">dateAdd</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">YEAR</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Very straight forward method.  This calculates how many days are in the year that is passed in.  Essentially I&#8217;m doing a date difference between the first of January of the requested year, and the first of January of the next year.  The method returns the number of days for that year.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _total:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">daysInYear</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2009</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would return 365.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Determines whether the year is a leap year or not
 * 
 * @param date	The date to check
 * 
 * @return		&lt;code&gt;true&lt;/code&gt; means it is a leap year, &lt;code&gt;false&lt;/code&gt; means it is not a leap year.
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> isLeapYear<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> daysInYear<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">365</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Another very straight forward method.  It accepts a date and determines if the year is a leap year.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _isLeapYear:<span style="color: #0066CC;">Boolean</span> = DateUtils.<span style="color: #006600;">isLeapYear</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2009</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would return <em>false</em> as 2009 is not a leap year.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
<p>I hope that this wasn&#8217;t too dry a topic for everyone that followed along.  I just get excited when I&#8217;m describing code I have written and as much as my wife <em>looks</em> like she&#8217;s interested in what I&#8217;m saying, I see her eyes glazing over every now and then <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , and I hope that others find new code as interesting as I do.  I wanted to make sure I got descriptions of everything in the DateUtils library to make it easier for anyone trying to figure out a use for it.  I think I&#8217;ll leave the library descriptions alone and go back to posting solutions to problems I&#8217;ve faced at work/home or interesting tidbits I&#8217;ve come across.  Perhaps I can revisit any new items I add in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2009/01/flex-date-utils-daysinyear-isleapyear/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; totalDayOfWeekInMonth, monthAsNumber</title>
		<link>http://flexoop.com/2009/01/flex-date-utils-totaldayofweekinmonth-monthasnumber/</link>
		<comments>http://flexoop.com/2009/01/flex-date-utils-totaldayofweekinmonth-monthasnumber/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 01:42:27 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=125</guid>
		<description><![CDATA[These 2 methods are quite useful. I use monthAsNumber quite frequently throughout the DateUtils library as it prevents any confusion about which month I am referencing (using the constants for a month rather than the numeric version, which in Flex and many programming languages is 0-11 rather than 1-12) /** * Gets the total number [...]]]></description>
			<content:encoded><![CDATA[<p>These 2 methods are quite useful.  I use monthAsNumber quite frequently throughout the DateUtils library as it prevents any confusion about which month I am referencing (using the constants for a month rather than the numeric version, which in Flex and many programming languages is 0-11 rather than 1-12)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the total number of dayOfWeek in the month
 * 
 * @param strDayOfWeek	The day of week to check
 * @param date			The date containing the month and year
 * 
 * @return				The number of &lt;code&gt;strDayOfWeek&lt;/code&gt; in that month and year
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> totalDayOfWeekInMonth<span style="color: #66cc66;">&#40;</span> strDayOfWeek:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> _startDate:<span style="color: #0066CC;">Date</span> = DateUtils.<span style="color: #006600;">dayOfWeekIterationOfMonth</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, strDayOfWeek, <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> _totalDays:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">dateDiff</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">DAY_OF_MONTH</span>, _startDate, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, <span style="color: #0066CC;">date</span>.<span style="color: #006600;">month</span>, DateUtils.<span style="color: #006600;">daysInMonth</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// have to add 1 because have to include first day that is found i.e. if wed is on 2nd of 31 day month, would total 5, of if wed on 6th, would total 4</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span> _totalDays <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">7</span> <span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method calculates the total number of a specific day of the week for a specified month.  The method accepts dayOfWeek as a string (use one the constants to make this easier) and a date containing the month and year requested.  It then returns a number with the total number of that day of the week for that month.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _total:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">totalDayOfWeekInMonth</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">Wednesday</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2009</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> JANUARY <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>which would return 4, as there are 4 Wednesdays in January 2009</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Formats a month to the numeric version of the month
 * 
 * @param strMonth	The month to convert
 * 
 * @return			A formatted month or -1 if month not found
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> monthAsNumber<span style="color: #66cc66;">&#40;</span> strMonth:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span> objMonth<span style="color: #66cc66;">&#91;</span> strMonth <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> ? objMonth<span style="color: #66cc66;">&#91;</span> strMonth <span style="color: #66cc66;">&#93;</span> : -<span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method takes a string version of the month, and then converts it to the numeric version of that month.  I use objMonth[ strMonth ] >= 0 rather than just objMonth[ strMonth ], as 0 is also &#8220;false&#8221; and was returning -1 instead of 0 (for January).  This is quite a useful method for me, and, even though it is more typing, I feel it makes more sense to someone skimming/reading the code, which prevents headaches in the future.  I even found one example I gave that was using 1, when I actually meant 0, for January, so I altered the example to use this method to remove all confusion.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2009/01/flex-date-utils-totaldayofweekinmonth-monthasnumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; dayOfWeekIterationOfMonth</title>
		<link>http://flexoop.com/2009/01/flex-date-utils-dayofweekiterationofmonth/</link>
		<comments>http://flexoop.com/2009/01/flex-date-utils-dayofweekiterationofmonth/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 02:29:59 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=121</guid>
		<description><![CDATA[This one is fairly complex, but quite useful, so I&#8217;m just going to demo one method today. /** * Gets the Xth day of the month. * e.g. get the 3rd Wednesday of the month * * @param iteration The iteration of the month to get e.g. 4th or Last * @param strDayOfWeek The day [...]]]></description>
			<content:encoded><![CDATA[<p>This one is fairly complex, but quite useful, so I&#8217;m just going to demo one method today.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the Xth day of the month.
 * e.g. get the 3rd Wednesday of the month
 * 
 * @param iteration		The iteration of the month to get e.g. 4th or Last
 * @param strDayOfWeek	The day of the week as a string
 * @param date			The date containing the month and year
 * 
 * @return				The date of the xth dayOfWeek of the month 
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dayOfWeekIterationOfMonth<span style="color: #66cc66;">&#40;</span> iteration:<span style="color: #0066CC;">Number</span>, strDayOfWeek:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// get the numeric day of the week for the requested day</span>
	<span style="color: #000000; font-weight: bold;">var</span> _dayOfWeek:<span style="color: #0066CC;">Number</span> = dayOfWeekAsNumber<span style="color: #66cc66;">&#40;</span> strDayOfWeek <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// get the date for the first of the month</span>
	<span style="color: #000000; font-weight: bold;">var</span> _firstOfMonth:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, <span style="color: #0066CC;">date</span>.<span style="color: #006600;">month</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// calculate how many days to add to get to the requested day from the first of the month</span>
	<span style="color: #000000; font-weight: bold;">var</span> _daysToAdd:<span style="color: #0066CC;">Number</span> = _dayOfWeek - DateUtils.<span style="color: #006600;">dayOfWeek</span><span style="color: #66cc66;">&#40;</span> _firstOfMonth <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// if dayOfWeek is before the first of the month, get the dayOfWeek for the following week</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _daysToAdd <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		_daysToAdd += <span style="color: #cc66cc;">7</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// set the date to the first day of the week for the requested date</span>
	<span style="color: #000000; font-weight: bold;">var</span> _firstDayOfWeekOfMonth:<span style="color: #0066CC;">Date</span> = DateUtils.<span style="color: #006600;">dateAdd</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">DAY_OF_MONTH</span>, _daysToAdd, _firstOfMonth <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// return the date if iteration is 1</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> iteration == <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> _firstDayOfWeekOfMonth;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// if requesting an iteration that is more than is in that month or requesting the last day of week of month</span>
		<span style="color: #808080; font-style: italic;">// return last date for that day of week of month</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">totalDayOfWeekInMonth</span><span style="color: #66cc66;">&#40;</span> strDayOfWeek, <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> iteration <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #66cc66;">&#40;</span> iteration == DateUtils.<span style="color: #006600;">LAST</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			iteration = DateUtils.<span style="color: #006600;">totalDayOfWeekInMonth</span><span style="color: #66cc66;">&#40;</span> strDayOfWeek, <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #808080; font-style: italic;">// subtract 1 as it starts from the first dayOfWeek of month</span>
		<span style="color: #b1b100;">return</span> DateUtils.<span style="color: #006600;">dateAdd</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">WEEK</span>, iteration - <span style="color: #cc66cc;">1</span>, _firstDayOfWeekOfMonth <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The name is a little cryptic, but it returns the total number of a day of the week in a specified month.  I heavily commented this method in order to be less confusing for anyone who might be trying to decipher what is going on, so I won&#8217;t go over what is being done within the method.  The method accepts 3 parameters: iteration which represents which dayofweek for a month to get, 1, 2, 3, 4, 5, or LAST (if using the constant), the string representation of the day of the week, and the date containing the month and year to query.  It returns the date for the specified iteration.</p>
<p>To implement, first import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dateOfIteration:<span style="color: #0066CC;">Date</span> = DateUtils.<span style="color: #006600;">dayOfWeekIterationOfMonth</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">3</span>, DateUtils.<span style="color: #006600;">TUESDAY</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2008</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">MAY</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will return May 20th, 2008, the 3rd Tuesday in May.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2009/01/flex-date-utils-dayofweekiterationofmonth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; daysInMonth, dayOfWeekAsString</title>
		<link>http://flexoop.com/2009/01/flex-date-utils-daysinmonth-dayofweekasstring/</link>
		<comments>http://flexoop.com/2009/01/flex-date-utils-daysinmonth-dayofweekasstring/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 15:40:45 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=115</guid>
		<description><![CDATA[These 2 methods are pretty self explanatory, daysInMonth and dayOfWeekAsString /** * Gets the days in the month * * @param date The date to check * * @return The number of days in the month */ public static function daysInMonth&#40; date:Date &#41;:Number &#123; // get the first day of the next month var _localDate:Date [...]]]></description>
			<content:encoded><![CDATA[<p>These 2 methods are pretty self explanatory, daysInMonth and dayOfWeekAsString</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the days in the month
 * 
 * @param date	The date to check
 * 
 * @return		The number of days in the month
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> daysInMonth<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// get the first day of the next month</span>
	<span style="color: #000000; font-weight: bold;">var</span> _localDate:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, DateUtils.<span style="color: #006600;">dateAdd</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">MONTH</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">month</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// subtract 1 day to get the last day of the requested month</span>
	<span style="color: #b1b100;">return</span> DateUtils.<span style="color: #006600;">dateAdd</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">DAY_OF_MONTH</span>, -<span style="color: #cc66cc;">1</span>, _localDate <span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">date</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method calculates how many days are in the month for the date passed in to the method.  It takes the date parameter and sets a temporary date to the first day of the next month.  Then it subtracts 1 day from that date to get the last day of the requested month.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _total:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">daysInMonth</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2009</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would return 31 to _total.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Formats a date to the string version of the day of the week
 * 
 * @param date	The date to format
 * 
 * @return		A formatted day of week
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dayOfWeekAsString<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> DateUtils.<span style="color: #006600;">dateFormat</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>, <span style="color: #ff0000;">&quot;EEEE&quot;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method returns a formatted date for the day of week.  Nothing crazy here.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dow:<span style="color: #0066CC;">String</span> = DateUtils.<span style="color: #006600;">dayOfWeekAsString</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2009</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>And this would return, Thursday</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2009/01/flex-date-utils-daysinmonth-dayofweekasstring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; dayOfYear and weekOfYear</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-dayofyear-and-weekofyear/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-dayofyear-and-weekofyear/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 04:47:25 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=113</guid>
		<description><![CDATA[2 more methods for today&#8217;s post. These may or may not be useful to people. I don&#8217;t think I have yet to use them in any of my code (maybe one time using the ColdFusion equivalents), but I thought I would translate them to Flex all the same. /** * Gets the ordinal value or [...]]]></description>
			<content:encoded><![CDATA[<p>2 more methods for today&#8217;s post.  These may or may not be useful to people.  I don&#8217;t think I have yet to use them in any of my code (maybe one time using the ColdFusion equivalents), but I thought I would translate them to Flex all the same.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the ordinal value or day of the year
 *
 * @param date	The date for which to get the day of the year
 * 
 * @return		A number representing the day of the year, 1 to 365 or 366 for a leap year
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dayOfYear<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// add one as it has to include first of year</span>
	<span style="color: #b1b100;">return</span> DateUtils.<span style="color: #006600;">dateDiff</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">DAY_OF_MONTH</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">fullYear</span>, DateUtils.<span style="color: #006600;">monthAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">JANUARY</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method takes a date and calculates the ordinal day of the year that that date represents, from 1 to 365 or 366 in a leap year.  This just uses the dateDiff method to subtract the number of days between the 1st of the year, and the date parameter (and adds one to include the first day of the year).</p>
<p>To implement, first import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dayOfYear:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">dayOfYear</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Gets the week of the year
 * 
 * @param date	The date for which to get the week of the year
 * 
 * @return		A number representing the week of the year, 1 to 53 ( as there are slightly more than 52 weeks of days in a year)
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> weekOfYear<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">ceil</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">dayOfYear</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">7</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method works very similarly to the dayOfYear method except that it calculates which week of the year the date falls in, and returns a number from 1 to 53.</p>
<p>To implement, first import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _weekOfYear:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">weekOfYear</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-dayofyear-and-weekofyear/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; DateDiff fix</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-datediff-fix/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-datediff-fix/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 16:09:25 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=110</guid>
		<description><![CDATA[I thought I would take a small break in the middle of my posts for the Flex Date Utils library to go over a fix I just had to make to the dateDiff method in the DateUtils class. I hadn&#8217;t really noticed this issue until I was reviewing my code for another fix I had [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I would take a small break in the middle of my posts for the Flex Date Utils library to go over a fix I just had to make to the dateDiff method in the DateUtils class.  I hadn&#8217;t really noticed this issue until I was reviewing my code for another fix I had put in previously (that was also not working correctly).</p>
<p>The main issue that cropped up was that to get the year, I was just subtracting the endDate year from the startDate year.  However, when you think about this, it is a very inaccurate way of treating year.  As year and months can vary in length, I couldn&#8217;t just use the Milliseconds contained within it to determine whether a year or month had occurred.  I had to just subtract one year or month from another.  However, if 2 months fall on separate years, but are not > 1 year apart, it will return 1, even though they could only be a month or so apart.  e.g. December 2008 to February 2009 is nowhere near 1 year apart, but subtracting 2008 from 2009, returns 1.</p>
<p>In order to fix this problem, I decided to check the total months that had passed also.  I then ran into yet <em>another</em> snag.  What if the month was the same, but the day of the month had not passed. e.g. July 16 2007 to July 5 2008 would not be 1 year, although if just using the months and year, it might suggest that it was 1 year apart.  To fix <em>this</em> problem, I decided to also check the milliseconds difference between the 2 dates.  This now fixes any dates that have different times within them also.</p>
<p>The dateDiff( MONTH ) was having a similar issue so this now fixes that problem also.</p>
<p>I put this fix up on the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> code and also updated the demo so that the issue would be fixed there also.</p>
<p>Make sure to download the latest code and you shouldn&#8217;t have any more issues with the dateDiff.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-datediff-fix/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; Date and Time Format (Part II)</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-ii/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-ii/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 04:22:31 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=105</guid>
		<description><![CDATA[This post is the second part of my description of the date and time format methods contained in the DateUtils class. I will be going over the public methods this time and showing how to call them from your code. // Date masks public static const SHORT_DATE_MASK:String = &#34;MM/DD/YY&#34;; public static const MEDIUM_DATE_MASK:String = &#34;MMM [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the second part of my description of the date and time format methods contained in the DateUtils class.  I will be going over the public methods this time and showing how to call them from your code.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Date masks</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SHORT_DATE_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;MM/DD/YY&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const MEDIUM_DATE_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;MMM D, YYYY&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LONG_DATE_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;MMMM D, YYYY&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const FULL_DATE_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;EEEE, MMMM D, YYYY&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Time masks</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SHORT_TIME_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;L:NN A&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const MEDIUM_TIME_MASK:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;L:NN:SS A&quot;</span>;
<span style="color: #808080; font-style: italic;">// TZD = TimeZoneDesignation = GMT + or - X hours, non-standard, requires a slight hack</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const LONG_TIME_MASK:<span style="color: #0066CC;">String</span>	= MEDIUM_TIME_MASK + <span style="color: #ff0000;">&quot; TZD&quot;</span>;</pre></div></div>

<p>These are the constants that can be used to denote the masks to use when calling the date and time formatters.  This makes the coder less prone to typing out incorrect values when entering a date.  User defined masks can still be passed as parameters, but the predefined masks should cover 99% of everyone&#8217;s needs.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Formats a time into a certain time format
 * 
 * @param date	The date to format
 * @param mask	How the date should be formatted
 * 
 * @return		A formatted time
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> timeFormat<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span>, mask:<span style="color: #0066CC;">String</span>=DateUtils.<span style="color: #006600;">SHORT_TIME_MASK</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> buildDateTime<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>, mask, <span style="color: #ff0000;">&quot;(A|:|J|H|K|L|N|S|TZD|<span style="color: #000099; font-weight: bold;">\\</span>s)+&quot;</span>, DateUtils.<span style="color: #006600;">SHORT_TIME_MASK</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method formats the date to a specified time.  The standard output uses the SHORT_TIME_MASK (L:NN A which creates in the format 12:05 am), but can be altered to whatever format the programmer wants.  I pass the date to the buildDateTime method (described in a <a href="/2008/12/flex-date-utils-date-and-time-format-part-i/" target="_blank">previous post</a>) to build the time, making sure to pass what constitutes a valid mask in the regular expression pattern.  The default is the SHORT_TIME_MASK again.</p>
<p>To use this method, import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _formatted:<span style="color: #0066CC;">String</span> = DateUtils.<span style="color: #006600;">timeFormat</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would take the current time and would output it like this: 11:16 pm</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Formats a date into a certain date format
 * 
 * @param date	The date to format
 * @param mask	How the date should be formatted
 * 
 * @return		A formatted date
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dateFormat<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span>, mask:<span style="color: #0066CC;">String</span>=DateUtils.<span style="color: #006600;">SHORT_DATE_MASK</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> buildDateTime<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>, mask, <span style="color: #ff0000;">&quot;(Y|M|D|E|<span style="color: #000099; font-weight: bold;">\\</span>W)+&quot;</span>, DateUtils.<span style="color: #006600;">SHORT_DATE_MASK</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method formats the date to a specified time.  The standard output uses the SHORT_DATE_MASK (MM/DD/YY which creates in the format 12/15/08), but can be altered to whatever format the programmer wants.  I pass the date to the buildDateTime method (described in a <a href="/2008/12/flex-date-utils-date-and-time-format-part-i/" target="_blank">previous post</a>) to build the date, making sure to pass what constitutes a valid mask in the regular expression pattern.  The default is the SHORT_DATE_MASK again.</p>
<p>To use this method, import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _formatted:<span style="color: #0066CC;">String</span> = DateUtils.<span style="color: #006600;">dateFormat</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would take the current date and would output it like this: 12/15/08</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Formats a date into a certain date/time format
 * 
 * @param date	The date to format
 * @param mask	How the date should be formatted
 * 
 * @return		A formatted date
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dateTimeFormat<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span>, mask:<span style="color: #0066CC;">String</span>=<span style="color: #ff0000;">&quot;MM/DD/YYYY L:NN:SS A&quot;</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> buildDateTime<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>, mask, <span style="color: #ff0000;">&quot;(Y|M|D|E|A|J|H|K|L|N|S|TZD|<span style="color: #000099; font-weight: bold;">\\</span>W)+&quot;</span>, DateUtils.<span style="color: #006600;">SHORT_DATE_MASK</span> + <span style="color: #ff0000;">' '</span> + DateUtils.<span style="color: #006600;">SHORT_TIME_MASK</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And finally,<br />
This method formats the date to a specified date and time.  The standard output uses a combination of the SHORT_DATE_MASK (MM/DD/YY which creates in the format 12/15/08) and the SHORT_TIME_MASK (L:NN A which creates in the format 12:05 am), but can be altered to whatever format the programmer wants.  I pass the date to the buildDateTime method (described in a <a href="/2008/12/flex-date-utils-date-and-time-format-part-i/" target="_blank">previous post</a>) to build the date and time, making sure to pass what constitutes a valid mask in the regular expression pattern.  The default is the SHORT_DATE_MASK and the DateUtils.SHORT_TIME_MASK again.</p>
<p>To use this method, import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _formatted:<span style="color: #0066CC;">String</span> = DateUtils.<span style="color: #006600;">dateTimeFormat</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This would take the current date and would output it like this: 12/15/08 11:20 pm</p>
<p>Once again, a very useful function that did not get included in the Flex framework for whatever reason, but now can easily be include in anyone&#8217;s code.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; Date and Time Format (Part I)</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-i/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-i/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 02:57:23 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=98</guid>
		<description><![CDATA[I will have to split this post into 2 separate parts, as there are several methods that are all related, and this post would be huge. In this post I will go over what is happening behind the scenes when date, time, and dateTimeFormat are called. All of these methods are private, so other than [...]]]></description>
			<content:encoded><![CDATA[<p>I will have to split this post into 2 separate parts, as there are several methods that are all related, and this post would be huge.  In this post I will go over what is happening behind the scenes when date, time, and dateTimeFormat are called.  All of these methods are private, so other than explaining how and why they work, nothing will be accessible outside of the DateUtils class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Internal variable used in date/time formatting</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _dateFormatter:DateFormatter;
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> dateFormatter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:DateFormatter <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>_dateFormatter <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		_dateFormatter = <span style="color: #000000; font-weight: bold;">new</span> DateFormatter;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> _dateFormatter;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I use a static getter for a DateFormatter instantiation so that I can use the built in features of the DateFormatter class to format my dates.  I figure, why reinvent the wheel, when it has been done so well in Flex already <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * @private
 * 
 * Calculates a timeZoneOffset, and converts it to a string, in standard GMT XX:XX format
 * 
 * @param date	The date on which to calculate the offset
 * 
 * @return		The formatted time zone designation
 */</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> buildTimeZoneDesignation<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span><span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">var</span> timeZoneAsString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;GMT &quot;</span>;
	<span style="color: #808080; font-style: italic;">// timezoneoffset is the number that needs to be added to the local time to get to GMT, so</span>
	<span style="color: #808080; font-style: italic;">// a positive number would actually be GMT -X hours</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getTimezoneOffset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getTimezoneOffset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		timeZoneAsString += <span style="color: #ff0000;">&quot;-0&quot;</span> + <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getTimezoneOffset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getTimezoneOffset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">date</span>.<span style="color: #006600;">timezoneOffset</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&gt;</span> -<span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		timeZoneAsString += <span style="color: #ff0000;">&quot;0&quot;</span> + <span style="color: #66cc66;">&#40;</span> -<span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">getTimezoneOffset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// add zeros to match standard format</span>
	timeZoneAsString += <span style="color: #ff0000;">&quot;00&quot;</span>;
	<span style="color: #b1b100;">return</span> timeZoneAsString;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As the description states, this method takes a date and builds the time zone designation in the GMT -XX:00 timezone offset.  If date is null, then it returns an empty string.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * @private
 * 
 * This function will remove any invalid characters from the date/time mask based upon a pattern
 * 
 * @param mask			The string for matching
 * @param pattern		The valid characters for this mask
 * @param defaultValue	The default value to return to the calling page should the mask not match the pattern
 * 
 * @return				Returns a validated &lt;code&gt;mask&lt;/code&gt; based upon the original pattern
 */</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> removeInvalidDateTimeCharacters<span style="color: #66cc66;">&#40;</span> mask:<span style="color: #0066CC;">String</span>, pattern:<span style="color: #0066CC;">String</span>, defaultValue:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// test for invalid date and time characters</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> mask.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span> pattern, <span style="color: #ff0000;">&quot;ig&quot;</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// if user is passing an invalid mask, default to defaultValue</span>
		mask = defaultValue;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// temporarily replace TZD with lowercase tzd for replacing later</span>
	<span style="color: #b1b100;">return</span> mask.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;TZD&quot;</span>, <span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;tzd&quot;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I use this method to remove any bad characters that may have been passed in to the date/time formatters.  It takes a mask, a pattern, and a default value.  The default value is my fallback in case an invalid characters have been passed in.  First I replace all characters based upon the pattern passed to the method.  If any characters are left, then it is a bad pattern, and it uses the default value.  I then replace TZD and switch it to lowercase so that it can be replaced with the actual time zone designation at a later point (and the dateformatter does not balk at it when it comes across it).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * @private
 * 
 * Formats a date into a certain date/time format
 * 
 * @param date			The date to format
 * @param mask			The string for matching
 * @param pattern		The valid characters for this mask
 * @param defaultValue	The default value to return to the calling page should the mask not match the pattern
 * 
 * @return		A formatted date
 */</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> buildDateTime<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Date</span>, mask:<span style="color: #0066CC;">String</span>, pattern:<span style="color: #0066CC;">String</span>, defaultValue:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
	dateFormatter.<span style="color: #006600;">formatString</span> = removeInvalidDateTimeCharacters<span style="color: #66cc66;">&#40;</span> mask, pattern, defaultValue <span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> dateFormatter.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;TZD&quot;</span>, <span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #66cc66;">&#41;</span>, buildTimeZoneDesignation<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">date</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This is where the dateformat &#8220;magic&#8221; happens <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   The function receives a date, the mask of how to format the date, a pattern that determines which characters are valid characters, and a default value to use should there be any invalid characters.</p>
<p>This sets the formatString of the static dateFormatter and removes any invalid characters.  Then it formats the date based upon that formatString, and finally replaces any TZD it finds (which would have been lowercased in the removeInvalidDateTimeCharacters method) with the actual timezone designation, if there was a time zone designation requested in the mask.</p>
<p>Even though none of these methods are available outside of the DateUtils class, I always like to know how things are working under the hood, and hopefully others do too.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; dayOfWeekAsNumber</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-dayofweekasnumber/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-dayofweekasnumber/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 04:53:12 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=91</guid>
		<description><![CDATA[// Days of week public static const MONDAY:String = &#34;monday&#34;; public static const TUESDAY:String = &#34;tuesday&#34;; public static const WEDNESDAY:String = &#34;wednesday&#34;; public static const THURSDAY:String = &#34;thursday&#34;; public static const FRIDAY:String = &#34;friday&#34;; public static const SATURDAY:String = &#34;saturday&#34;; public static const SUNDAY:String = &#34;sunday&#34;; &#160; // a generic object for holding day of [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// Days of week</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const MONDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;monday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const TUESDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;tuesday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const WEDNESDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;wednesday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const THURSDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;thursday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const FRIDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;friday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SATURDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;saturday&quot;</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SUNDAY:<span style="color: #0066CC;">String</span>	= <span style="color: #ff0000;">&quot;sunday&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// a generic object for holding day of the week values</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _objDaysOfWeek:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> objDaysOfWeek<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>_objDaysOfWeek <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		_objDaysOfWeek = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">SUNDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">0</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">MONDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">1</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">TUESDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">2</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">WEDNESDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">3</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">THURSDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">4</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">FRIDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">5</span>;
		_objDaysOfWeek<span style="color: #66cc66;">&#91;</span> DateUtils.<span style="color: #006600;">SATURDAY</span> <span style="color: #66cc66;">&#93;</span>	= <span style="color: #cc66cc;">6</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> _objDaysOfWeek;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Formats a date to the numeric version of the day of the week
 * 
 * @param strDayOfWeek	The day of week to convert
 * 
 * @return		A formatted day of week or -1 if day not found
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> dayOfWeekAsNumber<span style="color: #66cc66;">&#40;</span> strDayOfWeek:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span> objDaysOfWeek<span style="color: #66cc66;">&#91;</span> strDayOfWeek <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> ? objDaysOfWeek<span style="color: #66cc66;">&#91;</span> strDayOfWeek <span style="color: #66cc66;">&#93;</span> : -<span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method will actually take a string that represents the day of the week, and will convert that to the numeric representation in Flex for that day of the week, ranging from 0-6.</p>
<p>I actually created a generic object that would hold all of the values for the days of the week to make my life easier when trying to return and reference values in it.  I also created constants for all of the days of the week, so anyone calling any method that needs a string of the day of the week, can simply reference the constants, instead of trying to guess what I called the days of the week.</p>
<p>The method tries to reference whatever string is passed to it in the generic dayOfWeek object, and will return the value it finds, or if the object does not contain that string, it will return -1.  As long as you use the constants, the -1 should never be returned.</p>
<p>So in order to use this method, first import the package</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dow:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">dayOfWeekAsNumber</span><span style="color: #66cc66;">&#40;</span> DateUtils.<span style="color: #006600;">MONDAY</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>_dow would now be 1, as _objDaysOfWeek[ DateUtils.MONDAY ] is equal to 1.  I tend to use this method whenever I&#8217;m passing a day of the week value to one of my other methods, just so I don&#8217;t confuse the actual day value ( i.e. using 1-7 instead of 0-6 ).</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-dayofweekasnumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Date Utils &#8211; isDate</title>
		<link>http://flexoop.com/2008/12/flex-date-utils-isdate/</link>
		<comments>http://flexoop.com/2008/12/flex-date-utils-isdate/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 03:12:26 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexDateUtils]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://flexoop.com/?p=89</guid>
		<description><![CDATA[2 short methods again today, but one I find is very useful (and the first one that got me started on my date utils library) /** * Determines whether a value is actually a valid date * * @param value The date value * * @return &#60;code&#62;true&#60;/code&#62; means this is a valid date, &#60;code&#62;false&#60;/code&#62; means [...]]]></description>
			<content:encoded><![CDATA[<p>2 short methods again today, but one I find is very useful (and the first one that got me started on my date utils library)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Determines whether a value is actually a valid date
 * 
 * @param value	The date value
 * 
 * @return		&lt;code&gt;true&lt;/code&gt; means this is a valid date, &lt;code&gt;false&lt;/code&gt; means it is not a valid date
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> isDate<span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Date</span>.<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>My isDate method will check whether the value that is passed to it is actually a date or not.  I was surprised to find this wasn&#8217;t included somewhere in the Flex framework, but quite happy at how easy it was to create it.  All that needs to be done is to check whether the date can be parsed by the Date class.  If yes, it&#8217;s a date, if not, it is not a date.</p>
<p>To implement, first import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _validDate:<span style="color: #0066CC;">Boolean</span> = DateUtils.<span style="color: #006600;">isDate</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'this is not a date'</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Straight forward and simple <img src='http://flexoop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Converts the month to a Flex month
 * 
 * @param date	The human readable month
 * 
 * @return		The Flex converted month or 0 aka January
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> toFlexMonth<span style="color: #66cc66;">&#40;</span> localMonth:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span> localMonth <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&amp;&amp;</span> localMonth <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">13</span> <span style="color: #66cc66;">&#41;</span> ? localMonth - <span style="color: #cc66cc;">1</span> : <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This method is another one that I created to try to make my life easier when thinking about months, so I didn&#8217;t get confused about using 0-11 instead of 1-12.  I actually use another method I created instead of this one now, but I thought I should leave it in as it may be useful to someone, even if I don&#8217;t use it that much.</p>
<p>This accepts a month, 1-12, and returns the flex value for that month, 0-11.</p>
<p>Once again, to use, import the package:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexoop</span>.<span style="color: #006600;">utilities</span>.<span style="color: #006600;">dateutils</span>.<span style="color: #006600;">DateUtils</span>;</pre></div></div>

<p>and then:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _newMonth:<span style="color: #0066CC;">Number</span> = DateUtils.<span style="color: #006600;">toFlexMonth</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">6</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>And this would return 5.  Nothing awe inspiring in that method, but perhaps useful to someone.</p>
<p>All methods in this series are describing code in the <a href="http://code.google.com/p/flexdateutils/" target="_blank">FlexDateUtils</a> package I put on Google code.</p>
]]></content:encoded>
			<wfw:commentRss>http://flexoop.com/2008/12/flex-date-utils-isdate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

