Date and Time Picker Field - Version 2.0.12

Version Description

  • Added support for date format dd/mm/yy
  • Bugfix
Download this release

Release Info

Developer PerS
Plugin Icon 128x128 Date and Time Picker Field
Version 2.0.12
Comparing to
See all releases

Code changes from version 2.0.11 to 2.0.12

acf-date_time_picker.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced Custom Fields: Date and Time Picker
4
  Plugin URI: https://github.com/soderlind/acf-field-date-time-picker
5
  Description: Date and Time Picker field for Advanced Custom Fields
6
- Version: 2.0.11
7
  Author: Per Soderlind
8
  Author URI: http://soderlind.no
9
  License: GPLv2 or later
3
  Plugin Name: Advanced Custom Fields: Date and Time Picker
4
  Plugin URI: https://github.com/soderlind/acf-field-date-time-picker
5
  Description: Date and Time Picker field for Advanced Custom Fields
6
+ Version: 2.0.12
7
  Author: Per Soderlind
8
  Author URI: http://soderlind.no
9
  License: GPLv2 or later
date_time_picker-v3.php CHANGED
@@ -28,7 +28,7 @@ class acf_field_date_time_picker extends acf_Field {
28
  $this->title = __( 'Date and Time Picker' );
29
  $this->domain = 'acf-date_time_picker';
30
  $this->defaults = array(
31
- , 'label' => __( 'Choose Time', $this->domain )
32
  , 'time_format' => 'hh:mm'
33
  , 'show_date' => 'true'
34
  , 'date_format' => 'yy-mm-dd'
@@ -296,13 +296,11 @@ class acf_field_date_time_picker extends acf_Field {
296
  function update_value($post_id, $field, $value) {
297
  $field = array_merge($this->defaults, $field);
298
  if ($value != '' && $field['save_as_timestamp'] == 'true') {
299
- if ( $field['show_date'] == 'true') {
300
- $date = DateTime::createFromFormat(sprintf("%s %s",$this->js_to_php_dateformat($field['date_format']),$this->js_to_php_timeformat($field['time_format'])), $value);
301
- } else {
302
- $date = DateTime::createFromFormat(sprintf("%s",$this->js_to_php_timeformat($field['time_format'])), $value);
303
- }
304
- $value = $date->getTimestamp();
305
- }
306
 
307
  parent::update_value($post_id, $field, $value);
308
  }
@@ -383,10 +381,8 @@ class acf_field_date_time_picker extends acf_Field {
383
  return strtr((string)$time_format, $chars);
384
  }
385
 
386
- function isValidTimeStamp($timestamp) { //from http://stackoverflow.com/a/2524761/1434155
387
- return ((string) (int) $timestamp === $timestamp)
388
- && ($timestamp <= PHP_INT_MAX)
389
- && ($timestamp >= ~PHP_INT_MAX);
390
  }
391
 
392
  /*--------------------------------------------------------------------------------------
28
  $this->title = __( 'Date and Time Picker' );
29
  $this->domain = 'acf-date_time_picker';
30
  $this->defaults = array(
31
+ 'label' => __( 'Choose Time', $this->domain )
32
  , 'time_format' => 'hh:mm'
33
  , 'show_date' => 'true'
34
  , 'date_format' => 'yy-mm-dd'
296
  function update_value($post_id, $field, $value) {
297
  $field = array_merge($this->defaults, $field);
298
  if ($value != '' && $field['save_as_timestamp'] == 'true') {
299
+ if (preg_match('/^dd?\//',$field['date_format'] )) { //if start with dd/ or d/ (not supported by strtotime())
300
+ $value = str_replace('/', '-', $value);
301
+ }
302
+ $value = strtotime( $value );
303
+ }
 
 
304
 
305
  parent::update_value($post_id, $field, $value);
306
  }
381
  return strtr((string)$time_format, $chars);
382
  }
383
 
384
+ function isValidTimeStamp($timestamp) {
385
+ return ((string)(int)$timestamp === (string)$timestamp);
 
 
386
  }
387
 
388
  /*--------------------------------------------------------------------------------------
date_time_picker-v4.php CHANGED
@@ -311,11 +311,10 @@ class acf_field_date_time_picker extends acf_field
311
  }
312
 
313
 
314
- function isValidTimeStamp($timestamp) { //from http://stackoverflow.com/a/2524761/1434155
315
- return ((string) (int) $timestamp === $timestamp)
316
- && ($timestamp <= PHP_INT_MAX)
317
- && ($timestamp >= ~PHP_INT_MAX);
318
  }
 
319
  /*
320
  * update_value()
321
  *
@@ -332,15 +331,25 @@ class acf_field_date_time_picker extends acf_field
332
  * @return $value - the modified value
333
  */
334
 
335
- function update_value( $value, $post_id, $field ) {
336
- $field = array_merge($this->defaults, $field);
337
- if ($value != '' && $field['save_as_timestamp'] == 'true') {
338
- $value = strtotime( $value );
339
- }
340
- return $value;
341
- }
342
-
343
-
 
 
 
 
 
 
 
 
 
 
344
 
345
  /*
346
  * input_admin_enqueue_scripts()
311
  }
312
 
313
 
314
+ function isValidTimeStamp($timestamp) {
315
+ return ((string)(int)$timestamp === (string)$timestamp);
 
 
316
  }
317
+
318
  /*
319
  * update_value()
320
  *
331
  * @return $value - the modified value
332
  */
333
 
334
+ // function update_value( $value, $post_id, $field ) {
335
+ // $field = array_merge($this->defaults, $field);
336
+ // if ($value != '' && $field['save_as_timestamp'] == 'true') {
337
+ // $value = strtotime( $value );
338
+ // }
339
+ // return $value;
340
+ // }
341
+
342
+ function update_value( $value, $post_id, $field ) {
343
+ $field = array_merge($this->defaults, $field);
344
+ if ($value != '' && $field['save_as_timestamp'] == 'true') {
345
+ if (preg_match('/^dd?\//',$field['date_format'] )) { //if start with dd/ or d/ (not supported by strtotime())
346
+ $value = str_replace('/', '-', $value);
347
+ }
348
+ $value = strtotime( $value );
349
+ }
350
+
351
+ return $value;
352
+ }
353
 
354
  /*
355
  * input_admin_enqueue_scripts()
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: PerS
3
  Donate link: http://soderlind.no/donate/
4
  Tags: acf, custom field,datepicker,timepicker
5
- Requires at least: 3.4
6
- Tested up to: 3.6
7
- Stable tag: 2.0.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -110,6 +110,9 @@ TT AM or PM for AM/PM
110
  The Date and Time Picker field is saved as an UNIX timestamp. Use the PHP [date](http://php.net/manual/en/function.date.php) function when you use it in your theme.
111
 
112
  == Changelog ==
 
 
 
113
  = 2.0.11 =
114
  * Added option to retrive field values, using the_field() and get_field(), as a timestamp
115
  = 2.0.10 =
2
  Contributors: PerS
3
  Donate link: http://soderlind.no/donate/
4
  Tags: acf, custom field,datepicker,timepicker
5
+ Requires at least: 3.6
6
+ Tested up to: 3.7.1
7
+ Stable tag: 2.0.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
110
  The Date and Time Picker field is saved as an UNIX timestamp. Use the PHP [date](http://php.net/manual/en/function.date.php) function when you use it in your theme.
111
 
112
  == Changelog ==
113
+ = 2.0.12 =
114
+ * Added support for date format dd/mm/yy
115
+ * Bugfix
116
  = 2.0.11 =
117
  * Added option to retrive field values, using the_field() and get_field(), as a timestamp
118
  = 2.0.10 =