Skip to content

Instantly share code, notes, and snippets.

@heddn
Created October 10, 2016 17:30
Show Gist options
  • Save heddn/00f80f1ac388cd579bb8d142a4fe560f to your computer and use it in GitHub Desktop.
Save heddn/00f80f1ac388cd579bb8d142a4fe560f to your computer and use it in GitHub Desktop.
- field_date: field_date
+ field_date:
+ plugin: iterator
+ source: field_date
+ process:
+ value: value
+ end_value: value2
@baisong
Copy link

baisong commented Feb 27, 2018

Here's an example tested on Drupal 8.4.5 that imports start and end times, and adds 4 hours in the process.

langcode: en
status: true
id: events_csv_import
label: 'Import events'
source:
  plugin: csv
  path: sites/default/files/events.csv
  delimiter: ','
  enclosure: '"'
  header_row_count: 1
  keys:
    - id
  column_names:
    - id: 'Unique Id'
    - title: Title
    - body: 'Post body'
    - start: start
    - end: end
process:
  title: title
  body: body
  field_time_range/value:
    plugin: format_date
    source: start
    from_format: 'Y-m-d\TH:i:s'
    to_format: 'Y-m-d\TH:i:s'
    from_timezone: PST
    to_timezone: PST
  field_time_range/end_value:
    plugin: format_date
    source: end
    from_format: 'Y-m-d\TH:i:s'
    to_format: 'Y-m-d\TH:i:s'
    from_timezone: PST
    to_timezone: PST
  type:
    plugin: default_value
    default_value: event
destination:
  plugin: 'entity:node'
migration_dependencies: null

And here's a sample row from my CSV:

id title body start end
1 Meeting on Jan 8 This meeting is really important! 2018-01-08T09:00:00 2018-01-08T11:00:00

@heddn
Copy link
Author

heddn commented Feb 27, 2018

You might have to use the data_format process plugin to reformat the start and end dates to the proper format for the destination.

@baisong
Copy link

baisong commented Feb 27, 2018

That works! Updated my code above.

One last issue I'm having: No matter what I try with from_timezone and to_timezone, and with or without -0800 (Pacfiic Standard Time) appended on the end of the CSV values, it always takes seems to add 4 hours.

@baisong
Copy link

baisong commented Feb 27, 2018

@heddn please let me know if you have any timezone tips. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment