From 23f64437db44fe87e1036c1288f0cf84a36b7c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=98=E6=A2=A6=E7=90=B3?= Date: Sun, 15 May 2016 03:21:11 +0800 Subject: [PATCH 1/2] add history/update type of minDate/maxDate for android/fix bug for ios --- README.md | 9 +++++++++ www/android/DatePicker.js | 34 ++++++++++++++++++++++++++-------- www/ios/DatePicker.js | 9 +++++++-- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e26c432..a5a6a73 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/www/android/DatePicker.js b/www/android/DatePicker.js index 3ba4c22..35e56e2 100644 --- a/www/android/DatePicker.js +++ b/www/android/DatePicker.js @@ -8,6 +8,7 @@ */ function DatePicker() { //this._callback; + this.history } /** @@ -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', @@ -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 { diff --git a/www/ios/DatePicker.js b/www/ios/DatePicker.js index a09a9b2..eb28dcc 100644 --- a/www/ios/DatePicker.js +++ b/www/ios/DatePicker.js @@ -16,6 +16,7 @@ var exec = require('cordova/exec'); */ function DatePicker() { this._callback; + this.history; } /** @@ -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; @@ -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) { @@ -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); }; From 3253c500e9395006b29bd6d6b0fee2133067c8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=98=E6=A2=A6=E7=90=B3?= Date: Mon, 6 Jun 2016 14:35:59 +0800 Subject: [PATCH 2/2] fixed bug of date in ios --- www/ios/DatePicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/ios/DatePicker.js b/www/ios/DatePicker.js index eb28dcc..3c31bcc 100644 --- a/www/ios/DatePicker.js +++ b/www/ios/DatePicker.js @@ -45,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() + "-"