Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #30

Merged
merged 8 commits into from
Nov 17, 2017
Merged

Dev #30

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix for #8 dayOfYear()
  • Loading branch information
spencermountain committed Nov 17, 2017
commit ecccab716817ac2bac14ba9125918bd41b9f72b2
3 changes: 3 additions & 0 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const spacetime = require('./src');


//incorrect one
let obj = {}
for (let i = 0; i < 15; i++) {
var s = spacetime({
year: 2014 + i
}).endOf('year');
console.log(2014 + i, s.dayOfYear());
}

console.log(obj)
6 changes: 3 additions & 3 deletions src/methods/query/normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ let methods = {
return this;
}
//days since newyears - jan 1st is 1, jan 2nd is 2...
let sum = this.d.getDate();
let sum = 0
let month = this.d.getMonth();
let tmp;
//count the num days in each month
for (let i = 0; i < month; i++) {
for (let i = 1; i <= month; i++) {
tmp = new Date();
tmp.setYear(this.d.getFullYear()) //the year matters, because leap-years
tmp.setMonth(i);
tmp.setDate(1);
tmp.setHours(-2); //the last day of the month
sum += tmp.getDate();
}
return sum
return sum + this.d.getDate();
},
//bc/ad years
era: function(str) {
Expand Down
28 changes: 28 additions & 0 deletions test/leapYear.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,31 @@ test('feb-29th-doesnt-exist', t => {
});
t.end();
});

test('length of year', t => {
let right = {
'2014': 365,
'2015': 365,
'2016': 366,
'2017': 365,
'2018': 365,
'2019': 365,
'2020': 366,
'2021': 365,
'2022': 365,
'2023': 365,
'2024': 366,
'2025': 365,
'2026': 365,
'2027': 365,
'2028': 366
}
for (let i = 0; i < 15; i++) {
let year = 2014 + i
var s = spacetime({
year: year
}).endOf('year');
t.equal(right[year], s.dayOfYear(), 'year ' + year);
}
t.end();
});