Problem/Motivation

Feed source has a UTC timestamp but is being converted into the wrong timezone that is configured in the feed and field. Need a way offset the timestamp to be convert properly.

Steps to reproduce

Create a node with a date field with a certain timezone. Create a feed import and map to the date field with the chosen timezone. Feed source datetime should be a UTC timestamp.

Proposed resolution

Create a new tamper to offset time.

Issue fork tamper-3268276

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mmaranao created an issue. See original summary.

mmaranao’s picture

Status: Active » Needs review
StatusFileSize
new3.43 KB

Create a time offset tamper to offset the datetime on import.

mmaranao’s picture

StatusFileSize
new3.29 KB

Update patch path and description.

megachriz’s picture

Project: Feeds Tamper » Tamper
Version: 8.x-2.0-beta2 » 8.x-1.x-dev

This should go into the Tamper project.

The options do look like to be somewhat limited. Also, I think that the use case would already be covered by the Tamper plugin "Math"?
Do know that with Feeds date target you can configure which timezone should be used when interpreting the source value. Or doesn't that work if the input value is a timestamp (numeric value)?

jurgenhaas’s picture

It's interesting as we just had a related discussion in the ECA issue queue about a time zone topic here: #3351165: Example model for working with Dates, Timezones and Daylight Savings Time

Looking into the patch and reading the comment from @mmaranao I wonder if this could be done as a tamper plugin that extends the existing timestamp-to-date plugin with the enhancements, that a time zone can be selected, and the tamper plugin would then do all the necessary math to format the given timestamp for the selected time zone. That could be done by using the DateTime class from PHP and would then also allow all the "strange" timezones like "+4:30" and others too.

sgroundwater’s picture

I worked out an updated patch that may allow for better functionality, This patch adds a Timezone select list.

Status: Needs review » Needs work

The last submitted patch, 6: 0001-Issue-3268276-Reworking-timezones.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jurgenhaas’s picture

This looks great to me, I guess you only need to add this new plugin to the schema file to fix the tests. And maybe the timezone field should be declared required in the config form. Other than that, it is really helpful and much appreciated.

megachriz’s picture

Issue tags: +Needs tests

Thanks for the patch! In order for this to be merged, automated tests are needed as well. And I see some coding standard violations.

sgroundwater’s picture

Thanks for the feedback! I'll work on these items to move things forward.
- clean up for coding standards
- declared timezone field as required in the config form
- add tests

phily’s picture

Patch works for offsetting time only, could it be extended to handle date offset so one can get a date with a '-3 months' offset?

nitrocad’s picture

StatusFileSize
new2.49 KB

Hi, i have created a simple Dateoffset plugin according to TimeOffset.

Base data is timestamp too, and you can use tokens in the offset field like: "+[token] month".

Please review the code, i didn’t had much time, just needed the function.

eswiderski’s picture

@nitrocad your patch failed for me.

starlight-sparkle’s picture

StatusFileSize
new3.07 KB

@nitrocad @eswiderski that's not a patch, that's a PHP source file renamed to .txt
It appears to also have some issues such as missing definition for config name and mixing of tab and space indentation.
I have corrected these issues in a new patch file.

megachriz’s picture

@starlight-sparkle
Thanks for your contribution! Can you put your changes in a MR? The testbot on drupal.org no longer looks at patches, so changes need to be in a MR now if you want that the code eventually gets added to the module.

Also, it needs to have a functional test and a unit test for it to be accepted.

mortona2k’s picture

The offset works, but I need to apply a reverse offset to save the current time in a date field.

With ECA, I can get the current datetime from [current-date]. If my timezone is -8hrs, then the token value is in my time and saving it will make it 8 hours in the past.

I need an offset function to reverse the timezone offset to save the value in UTC.

starlight-sparkle’s picture

@mortona2k for your ECA use-case, you can use [current-date:raw] which is a Unix timestamp, which is timezone-agnostic.

starlight-sparkle’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Converted #6 and #14 into an MR, with added tests.
There are some test failures, but they appear to originate from the base branch (Drupal Core API has changed since last test in 8.x-1.x 3 months ago).

mandclu made their first commit to this issue’s fork.

mandclu’s picture

Thanks for everyone's work here. With the changes merged in from the main branch, the tests output is clean. Merged in.

mandclu’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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