Importer date format error

  • Hi


    I am building an importer script for collections. When the script hits this line of data:

    Code
    1. 'seminar_start' => '12:30:00',

    I get an error starting Fatal error: Uncaught Error: Call to a member function get_date() on null in


    The template is using the following field so just the time shows on the page:

    Code
    1. <perch:content id="seminar_start" label="Start time" type="time" format="H:i" native>

    The json in the db is "seminar_start":"13:20:00"


    I think that Perch is doing something clever to the time field, but I cannot work out the format I need to parse the time in, in order for the importer script to run correctly? Can anyone enlighten me please?

  • Ah yes, sorry, I cut it off as I thought the beginning was the relevant bit.


    I've solved this by concatenating the import item's date and time fields and using the resulting variable.

    Code
    1. $session_start = $item['Date'] . ' ' . $item['Session Start'];
    2. $session_end = $item['Date'] . ' ' . $item['Session Finish'];
    3. $Importer->add_item([
    4. 'seminar_start' => $session_start,
    5. 'seminar_end' => $session_end,
    6. ]);
  • Hi


    This issue has reared its head again – but I've only just seen the error when the site is being edited by the user.


    The template tag is this: <perch:content id="seminar_start" label="Start time" time type="time" format="H:i:s" default="09:00">


    Time is imported using the API as 9:50 into a collection.


    This then saves as 2019-07-29 09:50:00 in the database:


    When the collection item is saved again the field returns this to the initial format. e.g. 9:50


    So the item is now out of order in the listing as the format has changed (to what it should be).


    I can just use a text field as I only need the time but it would be nice if the importer kept to the format set in the template – or alternatively didn't change the actual data format once saved. Is this possible?