Skip to content

Feature/1561 time fields#1593

Merged
angrybrad merged 2 commits into5.xfrom
feature/1561-time-fields
Feb 6, 2025
Merged

Feature/1561 time fields#1593
angrybrad merged 2 commits into5.xfrom
feature/1561-time-fields

Conversation

@i-just
Copy link
Contributor

@i-just i-just commented Feb 6, 2025

Description

Updated version of PR #1566 - thanks @jamesmacwhite!
Targets v5 (for Craft 4) and adds format options.

Original description:
This adds initial support for Feed Me to properly handle Craft time fields. Currently time fields are only possible to be imported when times are written as strings. This update parses time values through the DateHelper to ensure they are valid. Using the existing DateHelper, the parseTimeString method is used to parse mapped values.

In addition, the default value on the mapping uses a Craft time field, rather than a plain text field

The following test data was used as part of testing:

{
  "content": [{
    "title": "Example entry title 1",
    "startTime": "13:00",
    "endTime": "15:00"
  }, {
    "title": "Example entry title 2",
    "startTime": "01-01-1900 16:00",
    "endTime": "01-01-1900 18:00"
  }]
}

This is the initial starting point to ensure time fields can be used in Feed Me, currently there is no proper handling of this field type leading to issues with importing.

Related issues

#1561

@i-just i-just requested a review from angrybrad as a code owner February 6, 2025 10:39
@angrybrad angrybrad merged commit 002dd63 into 5.x Feb 6, 2025
6 checks passed
@angrybrad angrybrad deleted the feature/1561-time-fields branch February 6, 2025 23:59
angrybrad added a commit that referenced this pull request Feb 7, 2025
@jamesmacwhite
Copy link
Contributor

jamesmacwhite commented Feb 8, 2025

Just an FYI, I noticed these errors after upgrading to 6.7.0 in the FeedMe logs. I believe it is because the time field is using the format option but because this was added after the feed model was created the value was null. Resaving the field model populates "auto" and should fix it.

craft\feedme\helpers\DateHelper::parseString(): Argument #2 ($formatting) must be of type string, null given, called in /var/task/vendor/craftcms/feed-me/src/fields/Time.php on line 57 - DateHelper.php: 24

I don't know if for safety, given there might be other feeds that exist using time fields prior to the specific handling, if the formatting parameter is null coalesced to "auto" to prevent this.

@i-just
Copy link
Contributor Author

i-just commented Feb 10, 2025

Thanks for this! Yes, resaving the feed will get rid of that issue. I raised a PR to default to the "auto" format.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants