<?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>Datejs &#187; Code</title>
	<atom:link href="http://www.datejs.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.datejs.com</link>
	<description>An open-source JavaScript Date Library</description>
	<lastBuildDate>Sun, 10 Oct 2010 23:33:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>New .same() Function, But Is It Useful?</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/</link>
		<comments>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comments</comments>
		<pubDate>Wed, 14 May 2008 00:59:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/</guid>
		<description><![CDATA[I need some feedback regarding a feature I just added to the library, but I'm struggling to explain/document clearly and I'm not sure if others would find this useful. The new .same() function will compare two date objects to determine if they occur on/in exactly the same instance of the given date part. (...like I [...]]]></description>
			<content:encoded><![CDATA[<p>I need some feedback regarding a feature I just added to the library, but I'm struggling to explain/document clearly and I'm not sure if others would find this useful.</p>
<p>The new .same() function will compare two date objects to determine if they occur on/in exactly the same instance of the given date part. (...like I said, I'm having a hard time explaining this one).</p>
<p>It's easier to understand with code...</p>
<p><strong>Scenario:</strong> Determine if the two dates occur on the same day.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">var d1 = Date.today(); // today at 00:00
var d2 = new Date();   // exactly now.

// Do they occur on the same day?
d1.same().day(d2); // true

// What if it's the same day, but one year apart?
var nextYear = Date.today().add(1).year();

d1.same().day(nextYear); // false, because the dates must occur on the exact same day.</pre>
<p>When comparing the dates in the same above, the .same() function will test that the year, month, and day match. Because we're only interested in whether the day is the same, the hour, minute, second &#038; millisecond values are ignored.</p>
<p>Using the same d1 &#038; d2 values from above, determine if the two dates occur on the same hour.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">// Do they occur on the same hour?
d1.same().hour(d2); // false, unless d2 hour is '00' (&lt; 1:00 am).</pre>
<p>If no date is passed as a parameter, by default the .same() function will use 'Now' (new Date()) as the default date to compare against.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">Date.today().same().day(); // true, 'today' occurs on 'today'
Date.today().same().hour(); // false, unless 'now' is '00' minutes (&lt; 1:00am)</pre>
<p>What do think? Would you find this functionality useful?</p>
<p>I do... because I'm often trying to determine if some date object occurs during today. The following samples demonstrate various ways to determine if a date object occurs today.</p>
<p><strong>Example (native JavaScript, without Datejs)</strong></p>
<pre class="brush: jscript; title: ; notranslate">
var temp = new Date();
temp.setHours(0);
temp.setMinutes(0);
temp.setSeconds(0);
temp.setMilliseconds(0);

var today = new Date(someDate.getTime()); // clone original instance so we don't actually change the original date.
var today.setHours(0);
var today.setMinutes(0);
var today.setSeconds(0);
var today.setMilliseconds(0);

(today == temp); // true|false</pre>
<p><strong>Example (with Datejs)</strong></p>
<pre class="brush: jscript; title: ; notranslate">// with Datejs, but without .same
someDate.clone().clearTime().equals(Date.today());

// New
someDate.same().day();

// Or,
someDate.is().today();</pre>
<p>Checking if a given date object occurs today is easy enough with Datejs and would not really justify adding the new .same() functionality, but things can get nasty when you need to compare against a date other than 'today'.</p>
<p><strong>Scenario:</strong> Determine if a given date occurs during some week period 2 months from now.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">// New
var future = Date.today().add(2).months();

return someDate.same().week(future); // true|false;</pre>
<p>The .same() function adds a third context to .second() within the library, which enables the following interesting (but freakishly cryptic) logic.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">Date.jan().second().monday().add(1).second().same().second();</pre>
<p>The .same() functionality has been added to sugarpak.js and is available from <a href="/svn/">SVN</a>.</p>
<p>Any feedback is appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Need Feedback From Arabic, Chinese And Several Other Cultures</title>
		<link>http://www.datejs.com/2008/02/10/need-feedback-from-arabic-chinese-and-several-other-cultures/</link>
		<comments>http://www.datejs.com/2008/02/10/need-feedback-from-arabic-chinese-and-several-other-cultures/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 05:17:05 +0000</pubDate>
		<dc:creator>geoffrey.mcgill</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.datejs.com/2008/02/10/need-feedback-from-arabic-chinese-and-several-other-cultures/</guid>
		<description><![CDATA[In preparation for an official final Release Version 1.0 within a month or two, we're just about to stamp the current Datejs code in SVN as Beta. But... we need some help. One area where we have not received much feedback is testing the Parser with cultures/languages outside of English. The Datejs library should properly [...]]]></description>
			<content:encoded><![CDATA[<p>In preparation for an official final Release Version 1.0 within a month or two, we're just about to stamp the current Datejs code in <a href="/svn/">SVN</a> as Beta.</p>
<p>But... we need some help. One area where we have not received much feedback is testing the Parser with cultures/languages outside of English.</p>
<p>The Datejs library should properly parse month and day names (both full and abbreviated strings) in over 150 different cultures.</p>
<p>The variations of German, Spanish, French and most European culture parsing seem good.</p>
<p>The big unknown cultures are Arabic and Chinese.</p>
<p>Haven't heard much feedback from India either.</p>
<p>The following list details the cultures we're most interested in receiving feedback:</p>
<ul>
<li><a href="http://datejs.googlecode.com/svn/trunk/build/date-ar-SA.js">Arabic (Saudi Arabia) date-ar-SA.js (or any other Arabic culture)</a></li>
<li><a href="http://datejs.googlecode.com/svn/trunk/build/date-zh-CN.js">Chinese (People's Republic of China) date-zh-CN.js</a></li>
<li><a href="http://datejs.googlecode.com/svn/trunk/build/date-pa-IN.js">Punjabi (India) date-pa-IN.js</a></li>
<li><a href="http://datejs.googlecode.com/svn/trunk/build/date-ru-RU.js">Russian (Russia) date-ru-RU.js</a></li>
<li><a href="http://datejs.googlecode.com/svn/trunk/build/date-th-TH.js">Thai (Thailand) date-th-TH.js</a></li>
</ul>
<p>If any developers could confirm the Datejs Parser is working (or not) in any of the above cultures, we would really appreciate the thumbs up/down. <strong>By "<em>working</em>", we're specifically interested in whether the Parser is correctly parsing Day and Month names in each culture and whether the  expected date format for that culture parses properly</strong>.</p>
<p>If the following strings (translated into the appropriate language) return the proper date, things should be good.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">
Date.parse('July 2008');
Date.parse('Sat July 3, 2004');
Date.parse('Dec');
Date.parse('monday');
</pre>
<p>The parser ships with some date phrase support (eg. 'today', 'next march'), although those strings may require translation. A couple cultures have already been translated by the community and available for download from the Datejs forums.</p>
<ul>
<li><a href="http://datejs.googlegroups.com/web/fr-FR.js?gda=yvqRPDkAAACj4pfxnMAccUJgWAAm-fNY6SzurZOCWQd0m4PLNpJn92G1qiJ7UbTIup-M2XPURDQL8fBfGGAKs4SAK81ZMSOW">français-French (France)</a></li>
<li><a href="http://datejs.googlegroups.com/web/es-ES.js?gda=ziWqPjkAAACj4pfxnMAccUJgWAAm-fNY6SzurZOCWQd0m4PLNpJn92G1qiJ7UbTIup-M2XPURDS5f9oo1MROwnxkoNkL7Kbg">espanol-Spanish (Spain)</a></li>
</ul>
<p>To test your culture, download a culture-specific file from SVN /trunk/build/ and add to any web page. If you are using FireFox, the easiest way run test scripts is with <a href="http://www.getfirebug.com/">FireBug</a>.</p>
<p>Thanks for the help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datejs.com/2008/02/10/need-feedback-from-arabic-chinese-and-several-other-cultures/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Advice On Datejs Compression And Performance Tuning</title>
		<link>http://www.datejs.com/2008/01/22/advice-on-datejs-compression-and-performance-tuning/</link>
		<comments>http://www.datejs.com/2008/01/22/advice-on-datejs-compression-and-performance-tuning/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 12:38:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.datejs.com/2008/01/22/advice-on-datejs-compression-and-performance-tuning/</guid>
		<description><![CDATA[Guy Fraser recently chronicled a series of his recommendations for Datejs compression and performance enhancements. Check it out. One recommendation from Guy was to hold a reference to the Date.prototype in a local var, thereby saving characters and simplifying access to the prototype. Example After changing everything over we were able to shave a little [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.adaptavist.com/display/~gfraser/2008/01/12/DateJS%2C+Compression%2C+Performance">Guy Fraser</a> recently chronicled a series of his recommendations for Datejs compression and performance enhancements. <a href="https://www.adaptavist.com/display/~gfraser/2008/01/12/DateJS%2C+Compression%2C+Performance">Check it out</a>.</p>
<p>One recommendation from Guy was to hold a reference to the Date.prototype in a local <code>var</code>, thereby saving characters and simplifying access to the prototype.</p>
<p><strong>Example</strong></p>
<pre class="brush: jscript; title: ; notranslate">
(function () {
    // Store prototype in local variable making
    // syntax shorter and access faster.
    var $P = Date.prototype;

    // Old
    // Date.prototype.clearTime = function() {

    // New
    $P.clearTime = function () {
        this.setHours(0);
        this.setMinutes(0);
        this.setSeconds(0);
        this.setMilliseconds(0);
        return this;
    };
}());
</pre>
<p>After changing everything over we were able to shave a little over 1k off the total library size and our performance tests did register an improvement. Great advice, and Datejs is now better (and faster!).</p>
<p>All this has been checked into <a href="/svn/">SVN</a> for public consumption.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datejs.com/2008/01/22/advice-on-datejs-compression-and-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SVN Commits And New Sugar</title>
		<link>http://www.datejs.com/2007/12/10/svn-commits-and-new-sugar/</link>
		<comments>http://www.datejs.com/2007/12/10/svn-commits-and-new-sugar/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 00:06:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.datejs.com/2007/12/10/svn-commits-and-new-sugar/</guid>
		<description><![CDATA[Since the Alpha 1 launch a couple weeks ago we've been steadily hammering away at Datejs enhancements, writing tests and pushing towards our goal of a solid Beta 1 release for early January 2008. The launch went well and community feedback has been steady and very much appreciated. As defects are discovered we're doing our [...]]]></description>
			<content:encoded><![CDATA[<p>Since the <a href="/2007/12/04/ajaxian-24-hours/">Alpha 1 launch</a> a couple weeks ago we've been steadily hammering away at Datejs enhancements, writing <a href="/test/">tests</a> and pushing towards our goal of a solid Beta 1 release for early January 2008.</p>
<p>The launch went well and community feedback has been steady and very much appreciated. As defects are discovered we're doing our best to fix immediately and commit the new code to <a href="/svn/">SVN</a>.</p>
<p><a href="http://groups.google.com/group/datejs-commits/topics"><img src="/wp-content/uploads/2007/12/svn_commits1.gif" alt="Datejs SVN Commit messages" style="float: right; padding-left: 10px;" /></a>If you're interested in following along as we commit code to the source repository, you might want to subscribe to the <a href="http://groups.google.com/group/datejs-commits/topics">Datejs-commits Discussion Group</a>. The Datejs-commits Group automagically catches all the SVN commit log messages and creates a <a href="http://groups.google.com/group/datejs-commits/feeds">feed</a> which is then easily consumed into your favourite news reader. We're doing our best to always ensure the SVN log notes give plenty of detail regarding all new code and/or revisions.</p>
<h3>A spoonful of SugarPak</h3>
<p>For developers partial to the <a href="/test/rememberthemilk/index.html">RememberTheMilk.com</a> date input options we added the following API functions and abbreviations.</p>
<pre class="brush: jscript; title: ; notranslate">
Date.tod();       // Date.today()
Date.tomorrow();
Date.tom();
Date.yesterday();
Date.yes();
</pre>
<p>Added a new <code>.at()</code> function which accepts a Time string or Time config object.</p>
<pre class="brush: jscript; title: ; notranslate">
Date.today().at(&quot;6:15 PM&quot;);
Date.today().at({hour: 18, minute: 15});
</pre>
<p>Added <code>.next()</code> and <code>.last()</code> as static functions to the Date object, so you no longer need to instantiate a Date object first before calling <code>.next()</code> or <code>.last()</code>.</p>
<pre class="brush: jscript; title: ; notranslate">
// Existing
Date.today().next().friday();
Date.today().last().march();

// New
// The above code still works,
// but if you want to be relative to 'today',
// the following code is tighter.
Date.next().friday();
Date.last().march();
</pre>
<p>Date logic actually gets fun to write when you start combining the functions to build amazingly readable Date expressions.</p>
<pre class="brush: jscript; title: ; notranslate">
Date.next().friday().at(&quot;6:15 PM&quot;);
</pre>
<p><strong>[Use Case]</strong> Schedule a reminder to be sent a week before the start of the next month at 9 in the morning.</p>
<pre class="brush: jscript; title: ; notranslate">
(1).week().before(Date.next().month()).at(&quot;9:00 am&quot;);
</pre>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datejs.com/2007/12/10/svn-commits-and-new-sugar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

