Hi. Thanks for the great work with feeds.

I've used feeds several times on Drupal 7, and it's a very useful module. I'm using the new Alpha 1 release for Drupal 8 the first time, but there appears to be a bug with importing time/dates. I've mapped a field to 'Authored on', and no matter which format I use, I get an error:

created.0.value: This value should be of the correct primitive type

I've tried Unix Timestamps, yyyy-mm-dd, Y-m-d h:i:s etc, but nothing seems to work. If I take out the created field and associated mapping, imports work fine.

I've spent hours trying a variety or formats, so I think there is a good chance this is a bug with Alpha 1?

Kind regards,

Comments

infoox created an issue. See original summary.

turpentyne’s picture

Following up on this, as I'd posted on the same problem, before realizing there was an issue already. I got one suggestion to use Epoch time (U), and that did work - but only after creating a whole new import. (though I did get an unrelated error, it appears: DOMDocument cannot parse XML").

When importing with anything but unix epoch time, I get this error on import attempt: "created.0.value: This value should be of the correct primitive type." Is there a way to provide those formats?

I'm currently using 8.x-3.0-alpha2. One step newer than original issue creator, but problem persists.

megachriz’s picture

I think currently only Unix timestamp values are supported. Not dates in string format. It would be a good idea to add support for date strings as well.

The implementation is in \Drupal\feeds\Feeds\Target\Timestamp. I think the target should operate similar as \Drupal\feeds\Feeds\Target\DateTime.

Perhaps all we need to do is let Timestamp extend DateTime?

megachriz’s picture

Title: Date/time importing through CSV file » Allow date strings as source for timestamp targets (like 'Authored on'/'created')
achikas’s picture

I also need the post date to be imported.
I created a D7 views csv export with Unix Timestamp (U) as date format.

Feeds still can't import and says again:
created.0.value: This value should be of the correct primitive type.

Did anyone made a successful date field import, yet?

turpentyne’s picture

@achikas ... I can't remember now, but I think a few weeks back, I just converted to Epoch time and imported that way. Don't quote me on that though. :)

achikas’s picture

I use Unix Timestamp for any date field now. I also works fine for date ranges.
For me its the best solution now, because i don't have to think about the different language date notations.

megachriz’s picture

Status: Active » Needs review
StatusFileSize
new12.6 KB

This patch should you allow to import from a date string.

Let's see if I did not break the regular date target with it...

Status: Needs review » Needs work

The last submitted patch, 8: feeds-date-string-to-timestamp-2969197-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

megachriz’s picture

Status: Needs work » Needs review
StatusFileSize
new18.42 KB
new7.08 KB

This hopefully fixes the test failures and the coding standard issues.

megachriz’s picture

StatusFileSize
new18.42 KB
new502 bytes

Minor text correction.

bisonbleu’s picture

Thanks for the patch @MegaChriz, that's great!

After applying the patch, I tried the following:

  • 2018-03-12
  • 2018/03/12
  • 12-Mar-2012
  • 2012-03-12 10:59:58
  • 03/12/2012
  • 03-12-2012
  • 08-14-2012 FAILS!

They all work except the last one. Makes sense to me since the logic of mm-dd-yyyy is at best ambiguous.

Here is the error.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'created' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, title, uid, created, changed, promote, sticky, default_langcode, revision_translation_affected) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array ( [:db_insert_placeholder_0] => 97 [:db_insert_placeholder_1] => 97 [:db_insert_placeholder_2] => article [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => Title of article 05 [:db_insert_placeholder_6] => 1 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => 1537798934 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 )

megachriz’s picture

StatusFileSize
new18.75 KB
new2.28 KB

@bisonbleu
Thanks for catching the SQL error! This patch should cause the validation to fail when providing a date like "08-14-2012".

  • MegaChriz committed 72966b6 on 8.x-3.x
    Issue #2969197 by MegaChriz, bisonbleu: Allow date strings as source for...
megachriz’s picture

Status: Needs review » Fixed

Committed #13.

megachriz’s picture

Category: Bug report » Feature request

Actually this wasn't a bug. More like a feature request. Changing the issue category. This has effect on where this will be listed on the notes of the next release.

bisonbleu’s picture

StatusFileSize
new64.86 KB

Hey @MegaChriz, so I took some time to test patch in #13 with the following.

"xx_id","xx_title","xx_author","xx_pubdate","xx_text"
1,"Title of article 01","admin","1532231185","This is the short body of article 01."
2,"Title of article 02","admin","1533231185","This is the short body of article 02."
3,"Title of article 03","admin","03/12/2012","This is the short body of article 03."
4,"Title of article 04","admin","03-12-2012","This is the short body of article 04."
5,"Title of article 05","admin","08-14-2012","This is the short body of article 05."

And got these messages after import. Is this what you would expect?

system messages

p.s. I'm not using the latest dev version. Should I?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

back from 7’s picture

I am having the same issue with getting the "authored on" date "post date" to work. What format should the date be in. Can someone provided some working examples. Also is this working on the dev version?

I am migrating thousands of nodes through feeds and need to sort by original date posted.

back from 7’s picture

Using the dev branch: 8.x-3.x-dev

I was able to get the following Date string to work with Feeds in my CSV file:

2019-05-12T15:47:13+0000

back from 7’s picture

When compiling my csv from Views Data Export, I use a custom date format: "Y-m-d H:i:s"

This works!

maskedjellybean’s picture

I just wanted to say that I spent a long time trying to get a string in this format to import into a Date field:

9/15/2020 1:00 PM

The import would fail saying that the Date field value cannot be null. What ended up working was to install the feeds_tamper module and then applying the "String to Unix Timestamp".

lubwn’s picture

Is this still an issue? I am trying to import any date format to Created field on Articles node and it all fails. No matter if I try to import epoch timestamp or any other format, I am still getting an error. Applying patch from #13 did not work as well since the code is probably already in beta-1 release (newest one).

netzkombuese’s picture

I can confirm this is not working for the created and the changed field ( with this patch https://www.drupal.org/project/feeds/issues/3060308).
While this is working for my custom date fields, the core fields for created and changed can´t be set.
I export from views data export in the exact same format and use feeds tamper to do a string to timestamp.
For my custom date fields this is working.
For the created date I always get a

Drupal\tamper\Exception\TamperException: Input should be a string.

Also without tamper plugin I can use any format (as said in #23) but without success.

Any ideas why this not working for created and changed mappings?

Thanks

iPat’s picture

I got this to work today, exporting the article "Authored On" dates from D7 to D9. Had to set the export date format to something readable (2022-04-18 13:16:40) and on the import source mapping, had to check both the "Raw value" and "Inner XML" options. And gloriously, it worked.

jweirather’s picture

#21/#25 worked for me, custom format "Y-m-d H:i:s" to import date fields for feeds in Drupal 10 from a Drupal 7 site, in particular, to carry over "Post date" to "Created on", in order to preserve the post dates from migrated content. I did not need to use tamper.