Skip to content

Commit

Permalink
Fix bug in date where we accidentally called which should have been
Browse files Browse the repository at this point in the history
  • Loading branch information
victorquinn committed Oct 29, 2013
1 parent e888d6b commit be8d35f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chance.js
Expand Up @@ -789,12 +789,12 @@
};

Chance.prototype.date = function (options) {
var year = parseInt(chance.year(), 10),
m = chance.month({raw: true}),
var year = parseInt(this.year(), 10),
m = this.month({raw: true}),
// Necessary because Date() 0-indexes month but not day or year
// for some reason.
month = m.numeric - 1,
day = chance.natural({min: 1, max: m.days}),
day = this.natural({min: 1, max: m.days}),
date;

options = initOptions(options, {
Expand Down

2 comments on commit be8d35f

@sidwood
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?! No unit test? ;o)

@victorquinn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh shame on me!

I actually tried to find a way to do it but couldn't find one without breaking compatibility.

This is an odd case due to the fact that I am globally instantiating an object named "chance." So it actually passed my tests fine because PhantomJS (which I use for the tests) had access to the chance object. It is an edge case that will fail only when using this in Node and not anywhere else.

I considered creating another separate test suite spinning up Chance in Node rather than PhantomJS but that seemed unnecessarily complex.

Anyway, I know you were likely just joking with your comment, but I wanted to let you know I did think long and hard about it!

Please sign in to comment.