<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: New .same() Function, But Is It Useful?</title>
	<atom:link href="http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/</link>
	<description>An open-source JavaScript Date Library</description>
	<lastBuildDate>Fri, 30 Sep 2011 00:59:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Joshua S. Weinstein</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-632</link>
		<dc:creator>Joshua S. Weinstein</dc:creator>
		<pubDate>Wed, 14 Sep 2011 08:18:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-632</guid>
		<description>/**
Functions to set or test if Date is the end (last day) of the month or the start (first day) of the month.
*/

Date.prototype.end = function () { if (this._is) { this._is = false; return this.clone().addDays(1).getDate() == 1; } this.setDate(1); return this.addMonths(1).addDays(-1); }

Date.prototype.start = function () { if (this._is) { this._is = false; return this.getDate() == 1; } this.setDate(1); return this; }

/* 
Example Usage:
new Date(2012,2-1,1).end().getDate() === 29 
new Date(2012,2-1,1).next().month().end().getDate() === 31
Date.november().end().getDate() === 30
new Date(2011,2,15).is().end() === false
// The following are true for *any* Date:
new Date().end().is().end() === true
new Date().start().getDate() === 1
new Date().start().is().start() === true
new Date().end().is().start() === false
new Date().start().is().end() === false
*/</description>
		<content:encoded><![CDATA[<p>/**<br />
Functions to set or test if Date is the end (last day) of the month or the start (first day) of the month.<br />
*/</p>
<p>Date.prototype.end = function () { if (this._is) { this._is = false; return this.clone().addDays(1).getDate() == 1; } this.setDate(1); return this.addMonths(1).addDays(-1); }</p>
<p>Date.prototype.start = function () { if (this._is) { this._is = false; return this.getDate() == 1; } this.setDate(1); return this; }</p>
<p>/*<br />
Example Usage:<br />
new Date(2012,2-1,1).end().getDate() === 29<br />
new Date(2012,2-1,1).next().month().end().getDate() === 31<br />
Date.november().end().getDate() === 30<br />
new Date(2011,2,15).is().end() === false<br />
// The following are true for *any* Date:<br />
new Date().end().is().end() === true<br />
new Date().start().getDate() === 1<br />
new Date().start().is().start() === true<br />
new Date().end().is().start() === false<br />
new Date().start().is().end() === false<br />
*/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua S. Weinstein</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-631</link>
		<dc:creator>Joshua S. Weinstein</dc:creator>
		<pubDate>Wed, 14 Sep 2011 07:38:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-631</guid>
		<description>Hi Jonathan Kamens,

In the current version of datajs there appears to be a function called weekday:

Date.prototype.weekday = function () { 
    if (this._is) { 
        this._is = false; 
        return !this.is().sat() &amp;&amp; !this.is().sun(); 
    } 
    return false; 
}

However, this returns &#039;false&#039; if you do 
   Date().parse(&quot;8:30am&quot;).next().weekend();
instead of showing the next weekday.

The datajs code could be extended to include a &#039;workday&#039; and &#039;weekend&#039; function which allow next().workday() and prev().weekend(), assuming Mon-Fri are work days and Saturday is the start of the weekend.

Date.prototype.weekend = function() { 
        if (this._is) {
                this._is = false;                
                return this.is().saturday() &#124;&#124; this.is().sunday(); 
        }
        return this.saturday(); 
}

/**
Next Workday is the next day, skipping weekends (Saturdays and Sundays).

Example Usage and Output:

var now, nextWorkday, prevWorkday;

now = new Date(&quot;8:30 am July 17, 2010&quot;)
// Sat Jul 17 2010 08:30:00 
now.is().workday();
// false ... Satuday is the weekend, not a workday

// skip weekends and go straight to Monday.
nextWorkday = now.clone().next().workday()
// Mon Jul 19 2010 08:30:00 
nextWorkday.is().workday();
// true ... Monday is a weekday.

// Previous workday from a Monday, Saturday or Sunday is a Friday, not a Monday.
prevWorkday = nextWorkday.clone().prev().workday()
// Fri Jul 16 2010 08:30:00 
prevWorkday.is().workday()
// true ... Friday is a weekday

now.clone().next().day().is().workday();
// false ... Saturday and Sunday are not work days.

*/
Date.prototype.workday = function () {
    if (this._is) {
        this._is = false;                
        return !this.is().weekend();
    }
    this.day();
    if (this.is().weekend()) {
        this._orient &lt; 0 ? this.friday() : this.monday();
    }
    return this;
}


/* 
Licensed under The MIT License 
... feel free to include this code in next release of datajs
*/</description>
		<content:encoded><![CDATA[<p>Hi Jonathan Kamens,</p>
<p>In the current version of datajs there appears to be a function called weekday:</p>
<p>Date.prototype.weekday = function () {<br />
    if (this._is) {<br />
        this._is = false;<br />
        return !this.is().sat() &amp;&amp; !this.is().sun();<br />
    }<br />
    return false;<br />
}</p>
<p>However, this returns &#8216;false&#8217; if you do<br />
   Date().parse(&#8220;8:30am&#8221;).next().weekend();<br />
instead of showing the next weekday.</p>
<p>The datajs code could be extended to include a &#8216;workday&#8217; and &#8216;weekend&#8217; function which allow next().workday() and prev().weekend(), assuming Mon-Fri are work days and Saturday is the start of the weekend.</p>
<p>Date.prototype.weekend = function() {<br />
        if (this._is) {<br />
                this._is = false;<br />
                return this.is().saturday() || this.is().sunday();<br />
        }<br />
        return this.saturday();<br />
}</p>
<p>/**<br />
Next Workday is the next day, skipping weekends (Saturdays and Sundays).</p>
<p>Example Usage and Output:</p>
<p>var now, nextWorkday, prevWorkday;</p>
<p>now = new Date(&#8220;8:30 am July 17, 2010&#8243;)<br />
// Sat Jul 17 2010 08:30:00<br />
now.is().workday();<br />
// false &#8230; Satuday is the weekend, not a workday</p>
<p>// skip weekends and go straight to Monday.<br />
nextWorkday = now.clone().next().workday()<br />
// Mon Jul 19 2010 08:30:00<br />
nextWorkday.is().workday();<br />
// true &#8230; Monday is a weekday.</p>
<p>// Previous workday from a Monday, Saturday or Sunday is a Friday, not a Monday.<br />
prevWorkday = nextWorkday.clone().prev().workday()<br />
// Fri Jul 16 2010 08:30:00<br />
prevWorkday.is().workday()<br />
// true &#8230; Friday is a weekday</p>
<p>now.clone().next().day().is().workday();<br />
// false &#8230; Saturday and Sunday are not work days.</p>
<p>*/<br />
Date.prototype.workday = function () {<br />
    if (this._is) {<br />
        this._is = false;<br />
        return !this.is().weekend();<br />
    }<br />
    this.day();<br />
    if (this.is().weekend()) {<br />
        this._orient &lt; 0 ? this.friday() : this.monday();<br />
    }<br />
    return this;<br />
}</p>
<p>/*<br />
Licensed under The MIT License<br />
&#8230; feel free to include this code in next release of datajs<br />
*/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-561</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Wed, 27 Oct 2010 23:17:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-561</guid>
		<description>Hi,
great work!
I think this may be useful to me in the near future. I am developing a web application and part of it will notify the user at a certain point in the day that corresponds to a schedule in a table. I think this may work, but as I have just stumbled upon it I will do some research and testing and hope to have a working example soon.

cheers,
and keep up the good work!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
great work!<br />
I think this may be useful to me in the near future. I am developing a web application and part of it will notify the user at a certain point in the day that corresponds to a schedule in a table. I think this may work, but as I have just stumbled upon it I will do some research and testing and hope to have a working example soon.</p>
<p>cheers,<br />
and keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Kamens</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-520</link>
		<dc:creator>Jonathan Kamens</dc:creator>
		<pubDate>Sun, 18 Jul 2010 01:30:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-520</guid>
		<description>Hi,

It looks like the contact form on your contact page is broken, so I&#039;m posting here instead in the hope that you will see this comment.

Are you still maintaining / doing any sort of active development on this code? I&#039;m asking because it&#039;s really quite awesome and I&#039;d like to use it in a Thunderbird add-in I maintain, but there&#039;s one little feature missing... I&#039;d like to be able to say, for example, &quot;8:30 am next weekday&quot; and have &quot;weekday&quot; mean the next day if it is currently Monday through Thursday, or the following Monday if it is currently Saturday or Sunday.

I looked briefly at the code to see if this would be something easy to add, and boy, it&#039;s complicated!</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>It looks like the contact form on your contact page is broken, so I&#8217;m posting here instead in the hope that you will see this comment.</p>
<p>Are you still maintaining / doing any sort of active development on this code? I&#8217;m asking because it&#8217;s really quite awesome and I&#8217;d like to use it in a Thunderbird add-in I maintain, but there&#8217;s one little feature missing&#8230; I&#8217;d like to be able to say, for example, &#8220;8:30 am next weekday&#8221; and have &#8220;weekday&#8221; mean the next day if it is currently Monday through Thursday, or the following Monday if it is currently Saturday or Sunday.</p>
<p>I looked briefly at the code to see if this would be something easy to add, and boy, it&#8217;s complicated!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Colburn</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-65</link>
		<dc:creator>Rob Colburn</dc:creator>
		<pubDate>Fri, 04 Sep 2009 17:56:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-65</guid>
		<description>It looks like you&#039;re extending the Number class too.  It looked nice till then.</description>
		<content:encoded><![CDATA[<p>It looks like you&#8217;re extending the Number class too.  It looked nice till then.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JW</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-64</link>
		<dc:creator>JW</dc:creator>
		<pubDate>Sun, 23 Aug 2009 13:54:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-64</guid>
		<description>Seems to be very useful to me.

@Mike, because its not only used for days. You can also use d1.same().month(d2) or d1.same.hour(d2) for example, to check whether two event are in the same month (of the same year) or the same hour (of the same day of the same month of the same year) respectively.</description>
		<content:encoded><![CDATA[<p>Seems to be very useful to me.</p>
<p>@Mike, because its not only used for days. You can also use d1.same().month(d2) or d1.same.hour(d2) for example, to check whether two event are in the same month (of the same year) or the same hour (of the same day of the same month of the same year) respectively.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-63</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 05 Aug 2009 14:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-63</guid>
		<description>Why not call it sameDay() or isSameDay()?</description>
		<content:encoded><![CDATA[<p>Why not call it sameDay() or isSameDay()?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Schalk Neethling</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-62</link>
		<dc:creator>Schalk Neethling</dc:creator>
		<pubDate>Thu, 15 May 2008 13:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-62</guid>
		<description>I would definitely use it. Great idea!</description>
		<content:encoded><![CDATA[<p>I would definitely use it. Great idea!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-61</link>
		<dc:creator>David</dc:creator>
		<pubDate>Wed, 14 May 2008 13:35:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-61</guid>
		<description>This looks useful.</description>
		<content:encoded><![CDATA[<p>This looks useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Library &#187; Blog Archive &#187; New .same() function, but is it useful?</title>
		<link>http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/comment-page-1/#comment-60</link>
		<dc:creator>Library &#187; Blog Archive &#187; New .same() function, but is it useful?</dc:creator>
		<pubDate>Wed, 14 May 2008 02:13:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.datejs.com/2008/05/13/new-same-function-but-is-it-useful/#comment-60</guid>
		<description>[...] geoffrey.mcgill wrote an interesting post today on New .same() function, but is it useful?Here&#8217;s a quick excerptI 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 &#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] geoffrey.mcgill wrote an interesting post today on New .same() function, but is it useful?Here&#8217;s a quick excerptI 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 &#8230; [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

