1. zurmo
  2. zurmo

Issues

Issue #57 resolved

DatePicker blocks to save model

Hisateru Tanaka
created an issue

In our locale -- Japan, jQuery's DatePicker formats date like as "12/04/17 10:10"(Japanese date format that points to 2012-04-17) but Yii can't convert it to datetime. Then we never create a meeting or such as which have "Start Time" field as required.

I suggest to specify date format as "YYYY-MM-DD" explicitly in every locale for DatePicker's config.

Comments (17)

  1. Hisateru Tanaka reporter

    I researched the source code deeply and found that CDateTimeParser::parse() failed to parse entered datetime from jQuery-ui's DateTimePicker because DateTimeUtil::getLocaleDateTimeFormat() returned "yy/MM/ddH:mm" but JQuery built string absolutely separated by single white space. It causes at some locales dateTimeFormat is seted as "{1}{0}" in Yii i18n data. (at least all ja and zh locales)

    I think that datetime format "{1}{0}" is not suitable to use with short format for every locale. Long formatted one like "2012年4月17日10時10分" is readable but "12/04/1710:10" is confusing even if for human. Zurmo is using short format often. I hope Yii would fix it in the next release...

    I suggest again not to change jQuery but to change DateTimeUtil class in zuromonic/framework to:

            public static function getLocaleDateTimeFormat()
            {
                // never use "{1}{0}" from Yii!
                // $dateTimePattern = Yii::app()->locale->getDateTimeFormat();
                $dateTimePattern = "{1} {0}";
    

    Though displaying date and time concatenated without any space is i18n bug of Yii, but parser logic should not depend on such view level bug.

  2. Jason Green

    Hisateru, Thanks for working on this issue.

    Sacha, I think the best approach is the make a method called getYiiToZurmoAdaptedDateTimeFormat() in the DateTimeUtil. Then we call this method instead of Yii::app()->locale->getDateTimeFormat(); In this method we can do a special IF statement for zh and ja. At least until Yii fixes it. Another option, is we can make a ZurmoLocale as an override to CLocale, then have that utilized in the config. Then we dont change the call to locale->getDateTimeFormat(), but instead override this method and check the zh/ja.

    What do you think?

  3. Hisateru Tanaka reporter

    Well, I think to override CLocale is better way than to add any method.

    To tell the truth, I got an issue not only for input but also displaying date-time data to HTML. Only adding a method to DateTimeUtil can't fix our ugly displaying such as '2012/4/2323:00'...

    I think, totally it is just from bad i18n data, so to patch there is better than special IF statement in deeper utility class. And when Yii-1.1.11 (that has been fixed completely) would come, simply we can remove the class from configuration. It may be soon than we expect.

  4. Sacha Telgenhof

    After investigating this some more, I think a specific class is the best option. We can there override the default getDateTimeFormat function and remove it once Yii has resolved the issue.

    I think it is good to keep the class after removal of the overridden function anyway, so we have our own class for any future other issues or functionalities we think of. Any particular location/folder this class needs to be put in?

    What do you think?

    BTW: Zurmo uses the short date format not the medium or long one.

  5. Sacha Telgenhof

    Hi guys,

    I am stuck on this one! Hoping you could help me out here. Following the path of creating a new locale class ZurmoLocale so we can override the default CLocale class, but it turned out that the CLocale's constructor and some variables are private and protected. This limits in the way we can superclass this...

    I thought I had the solution, but now a date time stamp in Zurmo does not get accepted at all. I have created a fork here: https://bitbucket.org/stelgenhof/zurmolocale.

    To use this fork, just make sure you have an up to date database and have a Zurmo user set to Japanese language. Don't worry about the language: if the Japanese language pack is not loaded you can still test this.

    What am I doing wrong here? Appreciate your help

    Sacha

  6. Anonymous

    My guess is because you have private variables that are the same in both ZurmoLocale and CLocale, something is getting wrecked along the way. I am thinking you have basically override all the methods in CLocale into ZurmoLocale and then it will be ok. This isn't ideal, but I see Hisateru is suggesting that this is fixed in 1.1.11? Is this true? If so we can do this fix now like you said, and then revert once we are using 1.1.11. Let me know what you guys think.

  7. Ivica Nedeljkovic

    I had some problem with some other Yii classes that had private memebers/functions, and only what you can do is to add those private members/functions into your class(maybe even whole class, if most public/protected functions are using those private properties).

  8. Sacha Telgenhof

    Thanks for your feedback. I will then see how far I need to override all of the variables/methods of CLocale. It feels a bit strange to do this for just a bug fix :(.

    Yes, it is solved and to become available in 1.1.11. Also I checked if I could find some info on when 1.1.11 of Yii is going to be released, but couldn't find anything.

  9. Sacha Telgenhof

    Hi Guys!

    Thanks for the feedback. I have basically almost overridden the CLocale class in a new class called ZurmoLocale. I have tested this issue now a couple of times and saving the date/time now works! Could you have a look in this fork (https://bitbucket.org/stelgenhof/zurmolocale) and let me know if it works for you too?

    If so, then I will create a pull request to have it changed in the main repository.

    Thanks! Sacha

  10. Hisateru Tanaka reporter

    Yii 1.1.11 development looks still working hardly because of the 1st release after switching to GitHub. I don't know when it would be released...

    I merged from stelgenhof/zurmolocale to my local branch then it worked fine with Japanese date picker. Thanks to your hard work.

  11. Alexander Demidov

    Hi

    I see strange situation: Correct datetime format: {1}, {2} But, my javascript datapicker and datetime plugin inserted datetime: {1} {2} (without comma) Снимок экрана_2015-10-23_16-06-54.png

    After submit form (Save record). Validator tell me: Your field Date Time needed as datetime (And inserted right format with comma) Снимок экрана_2015-10-23_16-07-15.png

    After save record with true datetime format - save its ok.

    How to configure javascript datepicker and time format and set to: {1}, {2} (with comma)?

  12. Log in to comment