Search code examples
phpapidatetimepodio

Working with Podio API and accessing date time, is podio documentation incomplete?


I saw the question and the subsequent answer to Working with podio api, i get a DateTime object and cant exccess its values.

The answer given did work for me, which was to use the format function, but it made me wonder if this documentation on podio is out of date because it doesn't seem to work.

http://podio.github.io/podio-php/fields/#date-field

In particular here are the examples given on the podio site for getting values that didn't seem to work 'as is' unless I extended the reference with a "->format('Y-m-d H:i:s')". Since these statements are "print" statements versus something like an assignment statement, I would think this is an important detail to drop off.

Am I wrong and missing something?

$item = PodioItem::get_basic(123);
$field_id = 'date';

print $item->fields[$field_id]->start; // E.g. DateTime or null
print $item->fields[$field_id]->start_date; // E.g. DateTime or null
print $item->fields[$field_id]->start_time; // E.g. DateTime or null
print $item->fields[$field_id]->end; // E.g. DateTime or null
print $item->fields[$field_id]->end_date; // E.g. DateTime or null
print $item->fields[$field_id]->end_time; // E.g. DateTime or null
print $item->fields[$field_id]->humanized_value; E.g. "2014-02-14 14:00-15:00"

Solution

  • The docs do state that a DateTime object is returned. As DateTime objects don't have a __toString method you can't print them directly and need to format them first. This is a PHP issue and not related to Podio or podio-php.

    I've removed the print statements from the docs to avoid this ambiguity.