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

add history/update type of minDate/maxDate for android/fixed bug for ios #182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Type: Date | empty String

Default: `(empty String)`

### history - iOS, Android
Remember the date you last selected, show the date when you select again

Type: Boolean

Values: `true` | `false`

Default: `false`

### titleText - Android
Label for the dialog title. If empty, uses android default (Set date/Set time).

Expand Down
34 changes: 26 additions & 8 deletions www/android/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
function DatePicker() {
//this._callback;
this.history
}

/**
Expand All @@ -26,13 +27,29 @@ DatePicker.prototype.ANDROID_THEMES = {
*/
DatePicker.prototype.show = function(options, cb, errCb) {

if (options.date && options.date instanceof Date) {
options.date = (options.date.getMonth() + 1) + "/" +
(options.date.getDate()) + "/" +
(options.date.getFullYear()) + "/" +
(options.date.getHours()) + "/" +
(options.date.getMinutes());
}
var formatDate = function(date) {
return Date.parse(new Date(date))
}

if (options.history && this.history) {
options.date = this.history;
}

if (options.date && options.date instanceof Date) {
options.date = (options.date.getMonth() + 1) + "/" +
(options.date.getDate()) + "/" +
(options.date.getFullYear()) + "/" +
(options.date.getHours()) + "/" +
(options.date.getMinutes());
}

if (options.minDate) {
options.minDate = formatDate(options.minDate);
}

if (options.maxDate) {
options.maxDate = formatDate(options.maxDate);
}

var defaults = {
mode : 'date',
Expand All @@ -55,11 +72,12 @@ DatePicker.prototype.show = function(options, cb, errCb) {
}

//this._callback = cb;

var _this = this;
var callback = function(message) {
if(message != 'error'){
var timestamp = Date.parse(message);
if(isNaN(timestamp) == false) {
_this.history = new Date(message)
cb(new Date(message));
}
else {
Expand Down
11 changes: 8 additions & 3 deletions www/ios/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var exec = require('cordova/exec');
*/
function DatePicker() {
this._callback;
this.history;
}

/**
Expand All @@ -35,7 +36,7 @@ DatePicker.prototype.ANDROID_THEMES = {
*/
DatePicker.prototype.show = function(options, cb) {
var padDate = function(date) {
if (date.length == 1) {
if (date.toString().length == 1) {
return ("0" + date);
}
return date;
Expand All @@ -44,7 +45,7 @@ DatePicker.prototype.show = function(options, cb) {
var formatDate = function(date){
// date/minDate/maxDate will be string at second time
if (!(date instanceof Date)) {
date = new Date(date)
return date
}
date = date.getFullYear()
+ "-"
Expand All @@ -61,7 +62,10 @@ DatePicker.prototype.show = function(options, cb) {
}

if (options.date) {
options.date = formatDate(options.date);
if (options.history && this.history) {
options.date = this.history
}
options.date = formatDate(options.date);
}

if (options.minDate) {
Expand Down Expand Up @@ -112,6 +116,7 @@ DatePicker.prototype.show = function(options, cb) {

DatePicker.prototype._dateSelected = function(date) {
var d = new Date(parseFloat(date) * 1000);
this.history = d;
if (this._callback)
this._callback(d);
};
Expand Down