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

Year is stored as "Y" instead of the actual year #7

Closed
zedejose opened this issue Sep 28, 2015 · 5 comments
Closed

Year is stored as "Y" instead of the actual year #7

zedejose opened this issue Sep 28, 2015 · 5 comments

Comments

@zedejose
Copy link

Not sure if I'm doing something wrong but when defining the field as:

$cmb->add_field( array(
'name'       => __( 'Test Date Range', 'cmb2' ),
'desc'       => __( 'field description (optional)', 'cmb2' ),
'id'         => $this->field_prefix . 'date_range',
'type'       => 'date_range',
) );

This is what gets saved to the database:

a:2:{s:5:"start";s:6:"9/28/Y";s:3:"end";s:7:"10/31/Y";}

i.e. the year is saved as "Y" instead of the actual year

@misfist
Copy link

misfist commented Oct 4, 2015

I'm seeing the same thing. It's being saved as:

a:2:{s:5:"start";s:6:"10/1/Y";s:3:"end";s:6:"10/4/Y";}

This might be related to this bug? CMB2/CMB2#300

In addition, although the value is stored, it doesn't display in the metabox after saving the post.

@davidlonguk
Copy link

Ditto. Seeing the same.

@davidlonguk
Copy link

davidlonguk commented Nov 11, 2016

Since this plugin appears to be broken and unsupported I thought I'd share a work around I've used.
Create the field as a CMB2 text field and make sure one of the parameters sets a class name of date_range_picker

$cmb_schedule->add_field( array(
            'name'  => __( 'Date Range', 'cmb' ),
            'desc'  => __( 'Choose the date range', 'cmb' ),
            'id'    => $prefix . 'date_range',
            'type'  => 'text',
            'attributes' => array(
            'class' => __( 'date_range_picker', 'cmb' ),
            ),

then add this JS to run on your admin pages

$(function() {
     // add date picker support to dates  taxonomy 


         $(".date_range_picker").datepicker({
            numberOfMonths: 2,
            dateFormat : 'yy-mm-dd', //format your date here
            onSelect: function( selectedDate ) {
                if(!$(this).data().datepicker.first){
                    $(this).data().datepicker.inline = true
                    $(this).data().datepicker.first = selectedDate;
                }else{
                    if(selectedDate > $(this).data().datepicker.first){
                        $(this).val($(this).data().datepicker.first+"_"+selectedDate);
                    }else{
                        $(this).val(selectedDate+"_"+$(this).data().datepicker.first);
                    }
                    $(this).data().datepicker.inline = false;
                }
            },
            onClose:function(){
                delete $(this).data().datepicker.first;
                $(this).data().datepicker.inline = false;
            }
         })
     });

@davidlonguk
Copy link

@jtsternberg Thanks for submitting a fix for this. I have already implemented another solution but may come back and test it out if I get time. Appreciate you supporting this plugin - sorry if my comments offended.

@jtsternberg
Copy link
Contributor

No offense taken. It's been over a year since this was reported, and you provided a workaround, so your comments were both truthful and helpful. That's what open source is about. Unfortunately, sometimes things get abandoned or neglected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants