Skip to content

Commit

Permalink
fixing initial behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTBrown committed Sep 30, 2017
1 parent 7ce6335 commit 9c5b007
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Example:
type: 'datetime',
name: 'dt',
message: 'When would you like a table?',
inital: new Date('2017-01-01 12:30'),
initial: new Date('2017-01-01 12:30'),
}
```

Expand Down
4 changes: 3 additions & 1 deletion example/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var questions = [
type: 'datetime',
name: 'dt',
message: 'When would you like a table?',
initial: Date.parse('01/03/2017'),
date: {
min: '1/1/2000'
min: "1/1/2017",
max: "3/1/2017"
},
time: {
min: '5:00 PM',
Expand Down
46 changes: 10 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function Prompt() {
time: {
max: null,
min: null,

hours: {
interval: 1
},
Expand Down Expand Up @@ -73,32 +72,6 @@ function Prompt() {
this.opt.time.min = (typeof this.opt.time.min === 'string') ? standardizeTime(Date.parse(this.opt.time.min)) : null;
this.opt.time.max = (typeof this.opt.time.max === 'string') ? standardizeTime(Date.parse(this.opt.time.max)) : null;

// Determine Date for Start of Prompt
var startDate = this.opt.initial || Date.present();
if (this.opt.date.min) {
startDate = startDate.set({
day: this.opt.date.min.getDate(),
month: this.opt.date.min.getMonth(),
year: this.opt.date.min.getFullYear()
});
}

if (this.opt.time.min) {
startDate = startDate.set({
hour: this.opt.time.min.getHours(),
minutes: this.opt.time.min.getMinutes(),
seconds: this.opt.time.min.getSeconds()
});
}

// Define Selection, State Helper for Selection
this._selection = {
cur: 0,
value: 0,
date: startDate,
elements: []
};

// Parse Elements
var opt = this.opt;
var selection = this._selection;
Expand Down Expand Up @@ -131,18 +104,19 @@ function Prompt() {
});
}

// Validate Date
if (opt.date.max && datePropose.isAfter(opt.date.max)) {
datePropose = validateDate(opt.date.max);
}

if (opt.date.min && datePropose.isBefore(opt.date.min)) {
datePropose = validateDate(opt.date.min);
}
return datePropose;
};

this._selection.date = validateDate(this._selection.date);
// Determine Date for Start of Prompt
var startDate = validateDate(opt.initial || Date.present());

// Define Selection, State Helper for Selection
selection = this._selection = {
cur: 0,
value: 0,
date: startDate,
elements: []
};

_.each(this.opt.format, function(str) {
switch (str) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Datepicker prompt for inquirer.js",
"main": "index.js",
"scripts": {
"style": "jshint . && jscs ."
"style": "jshint . && jscs .",
"prepare": "rm -rf example"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 9c5b007

Please sign in to comment.