Skip to content

Commit

Permalink
✨ year(), monthNumber(), day() extensions for Date (fixes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngarbezza committed Oct 2, 2019
1 parent e9498d6 commit bc94b90
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- [Date.today(), Date.yesterday(), Date.tomorrow() (#9)](https://github.com/ngarbezza/oow/issues/9)
- [day(), monthNumber(), year() for Date objects (#10)](https://github.com/ngarbezza/oow/issues/10)

## [1.7.0] - 2019-10-01

Expand Down
12 changes: 11 additions & 1 deletion src/date_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ const DateExtensions = {
return result;
},
},
instance: { },
instance: {
day() {
return this.getDate();
},
monthNumber() {
return this.getMonth() + 1;
},
year() {
return this.getFullYear();
},
},
};

applyExtension(DateExtensions, Date);
17 changes: 17 additions & 0 deletions test/date_extension_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,33 @@ suite('messages added to Date', () => {
const now = new Date();
assert.areEqual(today.toString(), now.toString());
});

test('tomorrow() returns tomorrows date', () => {
const tomorrow = Date.tomorrow();
const now = new Date();
now.setDate(now.getDate() + 1);
assert.areEqual(tomorrow.toString(), now.toString());
});

test('yesterday() returns yesterdays date', () => {
const yesterday = Date.yesterday();
const now = new Date();
now.setDate(now.getDate() - 1);
assert.areEqual(yesterday.toString(), now.toString());
});

test('day() is equivalent to getDate()', () => {
const now = new Date();
assert.areEqual(now.day(), now.getDate());
});

test('monthNumber() is equivalent to getMonth() but starting month numbers at 1', () => {
const now = new Date();
assert.areEqual(now.monthNumber(), now.getMonth() + 1);
});

test('year() is equivalent to getFullYear()', () => {
const now = new Date();
assert.areEqual(now.year(), now.getFullYear());
});
});

0 comments on commit bc94b90

Please sign in to comment.