Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

week_no

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

week_no - npm Package Compare versions

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);
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc