Comparing version 0.0.1 to 0.0.2
10
index.js
var firstMonday = new Date(1970, 0, 5).getTime() | ||
Date.prototype.weekNo = function(){ | ||
Date.prototype.weekNo = function() { | ||
var _date = new Date(this) | ||
@@ -8,6 +8,6 @@ _date.setHours(0,0,0,0) | ||
// get monday | ||
_date.setDate( _date.getDate() - ( _date.getDay() || 7 ) ) | ||
_date.setDate(_date.getDate() - (_date.getDay() || 7)) | ||
// calculate full weeks to nearest Thursday | ||
var weekNo = Math.ceil( ( ( ( _date - firstMonday ) / 86400000) + 1 ) / 7 ) | ||
var weekNo = Math.ceil((((_date - firstMonday) / 86400000) + 1) / 7) | ||
@@ -17,1 +17,5 @@ // Return array of year and week number | ||
} | ||
Date.prototype.weekNoRelative = function() { | ||
return this.weekNo() % 52 | ||
} |
{ | ||
"name": "week_no", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "get the week number for a date", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,2 +32,6 @@ | ||
## new Date(1970, 0, 5).weekNoRelative() | ||
Return a the number of weeks since `1970-1-5` modulo 52. | ||
# install | ||
@@ -34,0 +38,0 @@ |
@@ -1,16 +0,35 @@ | ||
require('../index.js') | ||
require("../index.js") | ||
describe('get week number', function(){ | ||
it("should be 0 for 1970-1-5", function(){ | ||
expect(new Date(1970, 0, 5).weekNo()).toBe(0); | ||
}); | ||
it("should be 0 for 1970-1-6", function(){ | ||
expect(new Date(1970, 0, 6).weekNo()).toBe(0); | ||
}); | ||
it("should be 52 for 1971-1-5", function(){ | ||
expect(new Date(1971, 0, 5).weekNo()).toBe(52); | ||
}); | ||
it("should be 104 for 1972-1-5", function(){ | ||
expect(new Date(1972, 0, 5).weekNo()).toBe(104); | ||
}); | ||
describe("get week number", function(){ | ||
describe("absolute week number", function() { | ||
it("is 0 for monday of the first week of 1970", function() { | ||
expect(new Date(1970, 0, 5).weekNo()).toBe(0); | ||
}) | ||
it("is 0 for tuesday of the first week of 1970", function() { | ||
expect(new Date(1970, 0, 6).weekNo()).toBe(0); | ||
}) | ||
it("is 52 for for the last week of 1970 which ends 1-1971", function() { | ||
expect(new Date(1971, 0, 5).weekNo()).toBe(52); | ||
}) | ||
it("is 104 for the last week of 1971 which ends 1-1972", function() { | ||
expect(new Date(1972, 0, 5).weekNo()).toBe(104); | ||
}) | ||
}) | ||
describe("relative week number", function() { | ||
it("is 0 for monday of the first week of 1970", function() { | ||
expect(new Date(1970, 0, 5).weekNoRelative()).toBe(0); | ||
}) | ||
it("is 0 for monday of the first week of 1971", function() { | ||
expect(new Date(1971, 0, 5).weekNoRelative()).toBe(0); | ||
}) | ||
it("is 0 for monday of the first week of 1971", function() { | ||
expect(new Date(1973, 0, 5).weekNoRelative()).toBe(0); | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3005
42
48