-
Notifications
You must be signed in to change notification settings - Fork 573
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
Date picker problem in auto format dd/mm/Y (pt_BR) #300
Comments
Both datepicker and timepicker are messed up in international versions. date_format and time_format are ignored, and instead the defaults for the translation strings are used. And later on, as you said, validation is made against American date format, no matter what. So you choose May 12th and after save you see December 5th; or if you choose any day after the 12th it just wont save. (pt_BR, or es_ES; or most other locales for that matter). Confirming bug. |
I guess #282 and this one are related in some ways. (May 15th, May 8th, 8:35 PM) Discarded the first value, saved the wrong value for the second (its 1438732800 in the DB, which is August 5th instead of May 8th), and messed up the display of the time picker (although the value saved is the right one...) |
Problem lays at the sanitation method It just puts the incoming value through I replaced that line with a call to Regards |
Thanks, for your answer. Regards |
@mateusneves, I made the fix in a pull request, but it still need to be reviewed and accepted by the project owners, and then it would need to get integrated into a proper release. You are of course free to pull a copy from my fork at https://github.com/yivi/CMB2/tree/trunk and test the changes for yourself. I'm using them and havent found problems yet, but more people checking would always be welcome. |
@mateusneves what @yivi said. If you want to test his version, that can only help the project. Thanks for the PR @yivi. I'll try to look at it as soon as I can. |
Thanks, @yivi and @jtsternberg |
Hello @yivi, array(
'name' => __('Date de fin (si applicable)', 'carine'),
'id' => $prefix.'date_fin',
'type' => 'text_date',
'date_format' => 'd/m/Y'
), public function text_date_timestamp( $value ) {
//return is_array( $value ) ? array_map( 'strtotime', $value ) : strtotime( $value );
if ( is_array( $this->value ) ) {
$returnee = array();
foreach ( $this->value as $value ) {
$date_object = DateTime::createFromFormat( $this->field->args['date_format'], $value );
$returnee[] = $date_object ? $date_object->setTime( 0, 0, 0 )->getTimeStamp() : '';
}
} else {
$date_object = DateTime::createFromFormat( $this->field->args['date_format'], $this->value );
$returnee = $date_object ? $date_object->setTime( 0, 0, 0 )->getTimeStamp() : '';
}
return $returnee;
} Thanks for helping me! |
You have to update .po and .mo files to reflect |
@Lindorie, sorry for taking so long, I was in the middle of a very convoluted project and couldn't make time to come around here. There are a few more changes. It would be easier if you just checked out my fork. It's updated to 2.08 and working (I'm using it at the moment). I'm going to take another look to see if there is anything else I'm missing out. Hopefully at some point @jtsternberg will have time to review my PR and see if its merge-worthy... :) Regards! |
Thanks @yivi. Your fork really helped me to get the thing working in german. I hope this will be integrated into the main branch! |
Glad you found it useful @fabianpimminger. Still waiting for word from the project owners about accepting my PR. I'm willing to do more work on it if it's not up to scratch, but I guess there wasn't enough time to properly review it. Regards! |
@yivi yah, unfortunately time is not on my side. I try to test every PR thoroughly before merging, and as you can imagine, that takes some time. I'll leave some comments on your PR. |
any fix for this issue yet? |
Already has provision for the solution ? |
Hi there, I've created another fork to fix temporarily the issue with non-US dates. The fix is only for the Please note that my solution is not the best, but it works and until a fix on the original project it's better than nothing, I guess. :) |
Hi there @Lindorie, Could you please elaborate on what problems you had using my fork? Did you checkout the "yivi-date-time-picker-fixes" branch, which is up-to-date one? Thanks and regards. |
I have tried with the fork I found in this comment. But apparently you made some changes? (The link is now broken) |
Thanks Carine. Let me know, please. Regards! — On Fri, Oct 23, 2015 at 3:06 PM, Carine Pic [email protected]
|
@yivi |
Glad to hear it @Lindorie . Let me know if you find any issues. Regards! |
#446 has been merged. Please test trunk to verify these issues are good. thanks. |
Just a little more input on this, we worked around this issue today by using hyphens instead of slashes as the notes on For our use case this swap was acceptable, I'm not sure if this make it easier to solve for you CMB devs. |
I had problems with this using the latest tagged version as of now: 2.1.2. When I tried to use trunk it worked like a charm! @jtsternberg could you release new version? I would love to use tagged version in my composer.json. |
@onnimonni Yes, we'll be releasing very soon. For best results, tune in to @webdevstudios on twitter. |
I can't get this to work in trunk either. I set date_format on my text_datetime_timestamp field to d/m/Y for UK date format but if in the picker I select a day greater than 12 it doesn't save the value and returns a blank field. Even if the day in the picker is 12 or less it only saves the correct format every other post update which I found very odd. The time field now works perfectly though in trunk. I could never set it to 24h format but that works now. I really hope this can be fixed very soon. In the project I'm working on now I use date/time fields quite heavily but I'm completely stuck now with this issue. Just a quick edit to this. I can get it to work if I change the separator from / to - like @JasonD33 said above. It allows me to work around the issue for now at least. Thanks @JasonD33 ! |
Hi, I'm using the 'date_format': 'd-m-Y' on the field and I've changed the CMB2_JS.php file so that the default date format of the datepicker from jquery-ui use the same format. Thanks @JasonD33 And thanks CMB devs for the good work. |
This is still happening for German month names. Whenever the short month form doesn't comply to default english form, the date isn't saved. Any help here ? |
Can still confirm that the bug is still there in the newst release of CMB2. |
This bug appears to still be happening. :( I have built a sanitization function to replace slashes with slashes in numerical date formats, but if you have a date format such as F j Y where the month is spelled out, the date will not save. |
Is it possible to use the sanitization function conditionally based on the format chosen? Or is that |
The problem isn't just the date format - the problem is date format and language. So |
Compiling the issue is the fact that javascript and php don't follow the same formats/letters/etc. As the saying goes "dates are hard". |
Hello,
I'm using WordPress in pt_BR version. With this the date picker carries been translated into my language, and enter the date in the field in the format dd / mm / Y. And when the post unless the date is not saved when for example the day is greater than 12 , because by default the CMB2 will consider the day as month , and there could not convert the date in the format dd / mm / Y for the timestamp format .
The text was updated successfully, but these errors were encountered: