Author Topic: Birthdays not stored properly in 0.8.4  (Read 8125 times)

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Birthdays not stored properly in 0.8.4
« on: December 22, 2012, 12:57:15 AM »
Hi,
I am not sure this is an issue (if so please let me know to report it), or if this applies to other addressbook fields as well. I tried to create a contact and specified a birthday. But when using advanced search, it does not display result. To be exact:

Birthday was set to 10/12/2012. When using search, putting '10/12/2012' in the search field shows no result. Putting '10' or '2012' finds the contact properly. Perhaps the date is stored in a specific form?
« Last Edit: January 01, 2013, 06:36:42 AM by grpprod »

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: Search by birthday
« Reply #1 on: December 22, 2012, 04:08:48 AM »
The birthday seems to be formatted as <year>-<day>-<month> like 2012-10-12, the search should be more flexible.
« Last Edit: December 22, 2012, 04:11:30 AM by SKaero »

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Search by birthday
« Reply #2 on: December 25, 2012, 02:28:39 PM »
IMHO, it does not look good to ask users to perform searches in this way. It wouldn't be too difficult to make the search search using the current date_format.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: Search by birthday
« Reply #3 on: December 26, 2012, 04:42:16 PM »
Agreed, a bug report should probably be made but it may have already been fixed it the git version and I don't have the time to test that right now.

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Search by birthday
« Reply #4 on: December 30, 2012, 03:51:23 AM »
Would just changing the SQL creation files solve this? I refer to:

Quote
ALTER TABLE `identities` ADD `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00' AFTER `user_id`;

CREATE TABLE `contactgroups` (
  `contactgroup_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',

etc.
If anyone else can confirm if this was fixed in git that would be nice.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Search by birthday
« Reply #5 on: December 31, 2012, 05:52:50 AM »
it has not been fixed in git master yet. I have created a ticket with some patches to do the job here http://trac.roundcube.net/ticket/1488888
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Search by birthday
« Reply #6 on: December 31, 2012, 10:00:49 AM »
in my 0.8.4, there is no program/lib/Roundcube directory. the file you mention is located in program/include, and it does not look the same.

for example, in rcube_vcard.php I can find the following:
Quote
      case 'birthday':
      case 'anniversary':
        if (($val = rcube_strtotime($value)) && ($fn = self::$fieldmap[$field]))

thanks so much anyway. since i am not familiar with this, could you please let me know how to apply the patch. thanks
« Last Edit: December 31, 2012, 10:16:42 AM by grpprod »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Search by birthday
« Reply #7 on: December 31, 2012, 11:37:27 AM »
you are correct in 0.8.* the files would be in /program/include. I had a look at the old files on git and from what i can see the affected lines are the same. as long as you can read diffs you should be fine. in rcube_contacts you'll need to use

Code: [Select]
if (is_array($value)) {
    if (($col == 'birthday' || $col == 'anniversary') && $val = rcube_strtotime($val))
        $val = date(rcube_vcard::$date_format, $val);

    $post_search[$col] = mb_strtolower($val);
}

since there is no framework. if you cant then i guess you'll have to wait and see if the devs choose to apply my patch
« Last Edit: December 31, 2012, 11:41:52 AM by JohnDoh »
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Search by birthday
« Reply #8 on: January 01, 2013, 06:08:49 AM »
Well, I've tried this. However I did not apply the second patch, only the first (format_date_in_abook_search.patch). I also included your correction for 0.8. However now this creates another issue. I did not bother to search yet, because now it alters the date. For example: I created a contact with birthday like the following:

06/12/1982 (DD/MM/YYYY).

When I save the contact, the date is stored as: 12/06/1982. Examining the record, it is stored like this:
BDAY;VALUE=date:1982-06-12

Am I missing something here?
EDIT: I see this is not caused by the patch, because I restored the unpatched files and the behaviour is the same. Perhaps datepicker sends wrong string?
« Last Edit: January 01, 2013, 06:40:22 AM by grpprod »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Birthdays not stored properly in 0.8.4
« Reply #9 on: January 01, 2013, 11:00:34 AM »
i think this is a function of php see http://uk3.php.net/manual/en/function.strtotime.php
Quote
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Birthdays not stored properly in 0.8.4
« Reply #10 on: January 01, 2013, 11:38:18 AM »
It's getting more complex now. Shouldn't this be predicted by RC? I'm kind of lost now. Even if I can't make search work properly, I would expect at least the date to be stored (and shown) as entered. IMHO, this is certainly a bug. This is also proven by the fact that if, for example, we enter a date which is out of bounds in the stored format (for example, if i enter '25/12/1980' nothing will be stored in the contact, because it will first be converted to 1980-25-12' which clearly is invalid.

In any case, is it possible to prohibit datepicker to add slashes? I did not add the slashes, it did.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Birthdays not stored properly in 0.8.4
« Reply #11 on: January 02, 2013, 09:37:58 AM »
you can change the date format in the config - date_format, i'm not sure where else it is used though.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline grpprod

  • Full Member
  • ***
  • Posts: 53
Re: Birthdays not stored properly in 0.8.4
« Reply #12 on: January 02, 2013, 12:19:37 PM »
This setting is already utilized. I don't think it is used in this case, though.