statamic / importer

Import content and data from XML or CSV with support for WP + Gutenberg.
https://statamic.com/addons/statamic/importer
MIT License
6 stars 0 forks source link

`Unexpected data found` error when importing dates #19

Open stephenmeehanuk opened 23 hours ago

stephenmeehanuk commented 23 hours ago

Bug description

I've got a handful of posts (in a .csv) with the date formatted like this:

postDateTime
2020-04-01 12:39:00
2020-06-15 14:03:00
2020-05-05 18:27:00
2020-12-09 15:43:00
2020-12-10 8:36:00

postDateTime from my csv is mapped to date in Statamic

The date in my blueprint looks like this

            handle: date
            field:
              type: date
              required: true
              default: now
              validate:
                - required
              time_enabled: true
              time_seconds_enabled: true

When I run the import, I get this error:

local.ERROR: Unexpected data found.
Unexpected data found.
Not enough data available to satisfy format {"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): Unexpected data found.

The import works if I remove the date mapping.

How to reproduce

Try to import dates in this format

postDateTime
2020-04-01 12:39:00
2020-06-15 14:03:00
2020-05-05 18:27:00
2020-12-09 15:43:00
2020-12-10 8:36:00

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.29.0
PHP Version: 8.3.8
Composer Version: 2.6.5
Environment: local
Debug Mode: OFF
URL: vocal.test
Maintenance Mode: OFF
Timezone: Europe/London
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: redis
Session: file

Statamic
Addons: 3
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.35.0 PRO

Statamic Addons
jonassiewertsen/statamic-jobs: 1.5.0
statamic/importer: 1.0.2
visuellverstehen/statamic-anchor-navigation: 1.0.0

Additional details

No response

stephenmeehanuk commented 22 hours ago

I updated my blueprint, removed time_enabled: true and time_seconds_enabled: true

            handle: date
            field:
              type: date
              required: true
              default: now
              validate:
                - required

and changed postDateTime to just date

postDateTime
--
2020-04-01
2020-06-15
2020-05-05
2020-12-09
2020-12-10

It works now. Would be handy to be able to import date and time in that format though.

jasonvarga commented 22 hours ago

Looks like this is because of 2020-12-10 8:36:00. It's 8: but probably should be 08:.

We might need handling to define what date format is being used in the csv fields.