Permalink
Browse files

setUTCFullYear and setFullYear now accept the same optional parameter…

…s that Date does
  • Loading branch information...
1 parent 3103bbd commit 0254eae54ab5dc36e8703715abe3f00765d822d6 Evan Larkin committed Dec 7, 2012
Showing with 52 additions and 2 deletions.
  1. +40 −0 spec/date.spec.js
  2. +12 −2 src/date.js
View
@@ -233,4 +233,44 @@ describe('timezoneJS.Date', function () {
expect(dt.toString()).toEqual('2011-12-31 00:00:00');
expect(dt.getTime()).toEqual(t);
});
+
+ it("accepts an optional parameter for month in setUTCFullYear", function() {
+ var date = new timezoneJS.Date(2000, 11, 31, 0, 0, 0, "Etc/UTC");
+ expect(date.getUTCMonth()).toEqual(11);
+ expect(date.getUTCDate()).toEqual(31);
+ date.setUTCFullYear(2012, 1);
+ //Febuary does not have a 31st, thus we should wrap to march
+ expect(date.getUTCMonth()).toEqual(2);
+ expect(date.getUTCDate()).toEqual(2);
+ });
+
+ it("accepts a second optional parameter for date in setUTCFullYear", function() {
+ var date = new timezoneJS.Date(2000, 11, 31, 0, 0, 0, "Etc/UTC");
+ expect(date.getUTCMonth()).toEqual(11);
+ expect(date.getUTCDate()).toEqual(31);
+ date.setUTCFullYear(2012, 1, 1);
+ //Do not wrap to March because we are setting the date as well
+ expect(date.getUTCMonth()).toEqual(1);
+ expect(date.getUTCDate()).toEqual(1);
+ });
+
+ it("accepts an optional parameter for month in setFullYear", function() {
+ var date = new timezoneJS.Date(2000, 11, 31, 0, 0, 0, "America/New_York");
+ expect(date.getMonth()).toEqual(11);
+ expect(date.getDate()).toEqual(31);
+ date.setFullYear(2012, 1);
+ //Febuary does not have a 31st, thus we should wrap to march
+ expect(date.getMonth()).toEqual(2);
+ expect(date.getDate()).toEqual(2);
+ });
+
+ it("accepts a second optional parameter for date in setFullYear", function() {
+ var date = new timezoneJS.Date(2000, 11, 31, 0, 0, 0, "America/New_York");
+ expect(date.getMonth()).toEqual(11);
+ expect(date.getDate()).toEqual(31);
+ date.setFullYear(2012, 1, 1);
+ //Do not wrap to March because we are setting the date as well
+ expect(date.getMonth()).toEqual(1);
+ expect(date.getDate()).toEqual(1);
+ });
});
View
@@ -256,7 +256,12 @@
return dt;
},
setDate: function (n) { this.setAttribute('date', n); },
- setFullYear: function (n) { this.setAttribute('year', n); },
+ setFullYear: function (year, month, date) {
+ if (date !== undefined) { this.setAttribute('date', 1); }
+ this.setAttribute('year', year);
+ if (month !== undefined) { this.setAttribute('month', month); }
+ if (date !== undefined) { this.setAttribute('date', date); }
+ },
setMonth: function (n) { this.setAttribute('month', n); },
setYear: function (n) { this.setUTCAttribute('year', n); },
setHours: function (n) { this.setAttribute('hours', n); },
@@ -268,7 +273,12 @@
this.setFromTimeProxy(n, this.timezone);
},
setUTCDate: function (n) { this.setUTCAttribute('date', n); },
- setUTCFullYear: function (n) { this.setUTCAttribute('year', n); },
+ setUTCFullYear: function (year, month, date) {
+ if (date !== undefined) { this.setUTCAttribute('date', 1); }
+ this.setUTCAttribute('year', year);
+ if (month !== undefined) { this.setUTCAttribute('month', month); }
+ if (date !== undefined) { this.setUTCAttribute('date', date); }
+ },
setUTCHours: function (n) { this.setUTCAttribute('hours', n); },
setUTCMilliseconds: function (n) { this.setUTCAttribute('milliseconds', n); },
setUTCMinutes: function (n) { this.setUTCAttribute('minutes', n); },

0 comments on commit 0254eae

Please sign in to comment.