]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
added sod and eod
authorIsaac Cambron <isaac@isaaccambron.com>
Sat, 14 Jan 2012 17:39:15 +0000 (12:39 -0500)
committerIsaac Cambron <isaac@isaaccambron.com>
Sat, 14 Jan 2012 17:39:15 +0000 (12:39 -0500)
moment.js
sitesrc/js/unit-tests.js

index d8e89a4ef84a2a85a545a7086108090afe3d2754..b8f0db6c48cd0f53821814df6f86f1d9d0a7672b 100644 (file)
--- a/moment.js
+++ b/moment.js
             var day = this._d.getDay();
             return input == null ? day :
                 this.add({ d : input - day });
+        },
+
+        sod: function () {
+            return this.clone()
+                .hours(0)
+                .minutes(0)
+                .seconds(0)
+                .milliseconds(0);
+        },
+
+        eod: function () {
+            return this.clone()
+                .hours(23)
+                .minutes(59)
+                .seconds(59)
+                .milliseconds(999);
         }
     };
 
index 0a2fe0287f6b1e15548ec77650d7fee82c7389f7..921c67c7209433e8fac125c2cc136583ee0aef43 100755 (executable)
@@ -436,5 +436,32 @@ test("zone", 2, function() {
     equal(moment().zone(), new Date().getTimezoneOffset(), 'zone should equal getTimezoneOffset');
 });
 
+module("sod");
+
+test("sod", 7, function(){
+    var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).sod();
+    equal(m.year(), 2011, "keep the year");
+    equal(m.month(), 1, "keep the month");
+    equal(m.date(), 2, "keep the day");
+    equal(m.hours(), 0, "strip out the hours"); 
+    equal(m.minutes(), 0, "strip out the minutes"); 
+    equal(m.seconds(), 0, "strip out the seconds"); 
+    equal(m.milliseconds(), 0, "strip out the milliseconds"); 
+});
+
+module("eod");
+
+test("eod", 7, function(){
+    var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).eod();
+    equal(m.year(), 2011, "keep the year");
+    equal(m.month(), 1, "keep the month");
+    equal(m.date(), 2, "keep the day");
+    equal(m.hours(), 23, "set the hours"); 
+    equal(m.minutes(), 59, "set the minutes"); 
+    equal(m.seconds(), 59, "set the seconds"); 
+    equal(m.milliseconds(), 999, "set the seconds");
+});
+
+
 })();