CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_event_create zeroes out dates
Pages: [1]

Author Topic: civicrm_event_create zeroes out dates  (Read 2305 times)

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
civicrm_event_create zeroes out dates
May 09, 2008, 08:00:22 pm
I can't create an event properly with civicrm_event_create. Any date fields, such as 'start_date' get replaced with zeroes.

For example, I'm setting $params['start_date'] with a string in the form of '2008-05-09 18:00:00' but the in the created event, it ends up as '0000-00-00 00:00:00'. I've also tried setting $params['start_date'] as a DateTime object.

Even this doesn't work, which should make an exact copy of an existing event:

<code>
$event = civicrm_event_get($p);

$cloned_event = $event;
unset($cloned_event['id']);

civicrm_event_create($cloned_event);
</code>

(Yes, I've initialized, included the v2/ file, and set $p with a valid event ID.)

The resulting event is an exact copy, except all the fields that should contains dates contain 0000-00-00 00:00:00 instead.

This sure looks like a bug in the API, unless I'm really missing something.

Any help?


Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Deepak Srivastava

  • Ask me questions
  • ****
  • Posts: 677
  • Karma: 65
Re: civicrm_event_create zeroes out dates
May 10, 2008, 12:49:52 am
Quote
For example, I'm setting $params['start_date'] with a string in the form of '2008-05-09 18:00:00' but the in the created event, it ends up as '0000-00-00 00:00:00'. I've also tried setting $params['start_date'] as a DateTime object.

I tried it this way:
Code: [Select]
$params['start_date'] = 20080509180000;
and it works perfectly (i.e '2008-05-09 18:00:00' in the db).
« Last Edit: May 10, 2008, 01:38:39 am by Deepak Srivastava »
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_event_create zeroes out dates
May 10, 2008, 01:34:44 am
For more example for event create api, you can check following test cases.

http://fisheye.civicrm.org/browse/~raw,r=12855/CiviCRM/trunk/test-new/SimpleTest/api-v2/EventCreate.php

kurund
Found this reply helpful? Support CiviCRM

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_create zeroes out dates
May 10, 2008, 10:28:43 am
That's very strange that it would be stored & output form the database one way, but must be input another way. Since the input format is more efficient (fewer characters), I would think that would be the best way to store it. It would also make the api much more intuitive if all params were expected to be formatted as they are stored.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_create zeroes out dates
May 10, 2008, 11:13:47 am
Also, while we're looking at  counter-intuitive expectations of the Event api,

civicrm_event_delete($params) expects params as ('event_id' => $id), while the rest of the event api functions expect ('id' => $id )

Of course backward compatibility should be preserved, but these functions should be made smarter to deal with formats that match the database along with any current internal formatting.

Also, functions like _get and _delete should accept a single integer as an argument, as an alternative to the array, since only the ID matters anyway.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_event_create zeroes out dates
May 10, 2008, 11:22:25 am
thats a mysql feature :) the output / input of date formats is different, and we need to reformat the date to save in the db

both get and create are basically thin layers over our DB framework, and we prefer to reformat values before those functions are called

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: civicrm_event_create zeroes out dates
May 10, 2008, 11:31:45 am
Ah, very interesting about mysql... feature... :-)

To justify my whining, here's a patch for _get and _delete to do what I suggested for these.

Just apply to /api/v2/Event.php

I wasn't sure if the date formatting issue should be addressed here, or in Core ?
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_event_create zeroes out dates

This forum was archived on 2017-11-26.