View Issue Details

IDProjectCategoryView StatusLast Update
0013526Tine 2.0Calendarpublic2017-10-16 09:26
ReporteringoratsdorfAssigned Topschuele 
PrioritynormalSeverityminorReproducibilityalways
Status gerritResolutionopen 
Platformi386OSlinuxOS Version3.2.0-24
Product Versiongit master 
Target VersionFixed in Version 
Summary0013526: Calendar ICS import ignores local timezone and adds an organizer
DescriptionImported events from a booking calendar do not contain organizers (as there are none) and are in local UTC+12 (NZDT).
The resulting imported events automatically add the current user as organizer (which is wrong, I am not organizing this and I am not booked for this event) plus is gets imported for 12 hours later.

Test data:

BEGIN:VEVENT
SUMMARY:160:Susan
DESCRIPTION: Blabla
DTSTART:20171006T150001
DTEND:20171009T100002
UID:2017-10-06 15:00:01_160@demo.icalendar.org
DTSTAMP:20171006T053151
CREATED:20170804T112346
LAST-MODIFIED:20170804T112346
STATUS:CONFIRMED
END:VEVENT

Gets imported for the 7. October at 4am.
Steps To ReproduceImport calendar.
Import adds current user as organizer and is 12 hours too late.
Since no timezone information is in the event, it gets imported as UTC, which is wrong as server and user timezone is Pacific/Auckland (NZDT / UTC+1200)
Tagscalendar
mwticket

Relationships

related to 0006296 resolvedcweiss Calendar.import shifts dates upon import from ics files 

Activities

ingoratsdorf

ingoratsdorf

2017-10-07 11:21

developer   ~0020890

Timezone issue:
FORM #1: DATE WITH LOCAL TIME

      The date with local time form is simply a DATE-TIME value that
      does not contain the UTC designator nor does it reference a time
      zone. For example, the following represents January 18, 1998, at
      11 PM:

       19980118T230000

      DATE-TIME values of this type are said to be "floating" and are
      not bound to any time zone in particular. They are used to
      represent the same hour, minute, and second value regardless of
      which time zone is currently being observed.

However the Abstract VCalendar converter uses Sabre\VObject\Property\ICalendar\DateTime->getDateTime(); which returns all floating dates with a UTC timezone attached. This should be the local time.
Sabre has always returned floating datetimes as UTC and still does.

Fixed Tinebase->Convert->VCalendar->Abstract.php code snippet:

/**
     * get datetime from sabredav datetime property (user TZ is fallback)
     *
     * @param Sabre\VObject\Property $dateTimeProperty
     * @param boolean $_useUserTZ
     * @return Tinebase_DateTime
     *
     * @todo try to guess some common timezones
     */
    protected function _convertToTinebaseDateTime(\Sabre\VObject\Property $dateTimeProperty, $_useUserTZ = FALSE)
    {
        $defaultTimezone = date_default_timezone_get();
        date_default_timezone_set((string) Tinebase_Core::getUserTimezone());
        
        if ($dateTimeProperty instanceof Sabre\VObject\Property\ICalendar\DateTime) {
            $dateTime = $dateTimeProperty->getDateTime();
            $originalValue = $dateTimeProperty->getValue();
            if (substr(strtoupper($originalValue) , strlen($originalValue)-1, 1 ) != 'Z')
                // floating datetime
                $_useUserTZ = true;
            $tz = ($_useUserTZ || (isset($dateTimeProperty['VALUE']) && strtoupper($dateTimeProperty['VALUE']) == 'DATE')) ?
                (string) Tinebase_Core::getUserTimezone() :
                $dateTime->getTimezone();

            Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Sabre DateTime Value: ' . print_r($originalValue, true));
            $result = new Tinebase_DateTime($dateTime->format(Tinebase_Record_Abstract::ISO8601LONG), $tz);
        } else {
            $result = new Tinebase_DateTime($dateTimeProperty->getValue());
        }
        
        date_default_timezone_set($defaultTimezone);
        
        return $result
}
pschuele

pschuele

2017-10-09 08:26

administrator   ~0020894

thanks for the fix, we'll review that soon. i'll push it to gerrit for verification.
pschuele

pschuele

2017-10-09 09:10

administrator   ~0020900

hm, we have a failing test. it looks like the TZ isn't detected any more ...

Calendar_Convert_Event_VCalendar_GenericTest::testConvertToTine20ModelWithTehranTZ
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Asia/Tehran'
+'Europe/Berlin'

/usr/local/share/tine20.git/tests/tine20/Calendar/Convert/Event/VCalendar/GenericTest.php:169
ingoratsdorf

ingoratsdorf

2017-10-09 11:15

developer   ~0020902

Yeah, I need to do some cross testing with this, plus get the organizer/attendee issue resolved.
Thanks for testing.
weberho

weberho

2017-10-12 16:19

developer   ~0020930

For me this problem has never been solved. I had a patch prepared in 0006296 which fixed the tinezone problem for me. The second patch there is still not integrated. You could give it a try.
pschuele

pschuele

2017-10-13 09:12

administrator   ~0020944

ah, this patch might have been overlooked... I'll try to integrate it.
pschuele

pschuele

2017-10-13 09:21

administrator   ~0020946

@Ingo: could you try weberhos patch? maybe it fixes your TZ issue, too.
ingoratsdorf

ingoratsdorf

2017-10-13 11:51

developer   ~0020952

Aus irgendwelchen unerfindlichen GrĂ¼nden habe ich keinen Zugang zu Gerrit mehr. Und da ich mich nicht einloggen kann, kann ich auch nicht mir einen Passwort reset link senden... Oder so.
ingoratsdorf

ingoratsdorf

2017-10-13 11:55

developer   ~0020954

I fixed the timezone issue meanwhile, however struggle big time with the organizer issue.
How do you import a, say, holiday calendar without being added as attendee and organizer and your time shown blocked. That's just plain silly.
I have dug deep in tine calendar for this and tried to trace the auto addition but was not too successful.. Somewhere ended up in Event.php.
ingoratsdorf

ingoratsdorf

2017-10-13 21:41

developer   ~0020966

The patch for the timezone conversion issue, when
- no timezone is specified in the event
- no TZID is noted in the DATETIME values
- times are floating and not in UTC, ie local times

TZConvertFix.patch (1,705 bytes)
--- \\SERVER\tine20-git\tine20\Tinebase\Convert\VCalendar\Abstract.php	Thu Feb 09 22:57:41 2017
+++ \\SERVER\tine20\Tinebase\Convert\VCalendar\Abstract.php	Tue Oct 10 22:26:32 2017
@@ -241,14 +241,23 @@
         $defaultTimezone = date_default_timezone_get();
         date_default_timezone_set((string) Tinebase_Core::getUserTimezone());
         
         if ($dateTimeProperty instanceof Sabre\VObject\Property\ICalendar\DateTime) {
             $dateTime = $dateTimeProperty->getDateTime();
-            $tz = ($_useUserTZ || (isset($dateTimeProperty['VALUE']) && strtoupper($dateTimeProperty['VALUE']) == 'DATE')) ? 
-                (string) Tinebase_Core::getUserTimezone() : 
-                $dateTime->getTimezone();
-            
+            $originalValue = $dateTimeProperty->getValue();
+
+            if ($_useUserTZ || (isset($dateTimeProperty['VALUE']) && strtoupper($dateTimeProperty['VALUE']) == 'DATE')) {
+                $tz = (string) Tinebase_Core::getUserTimezone();
+            }
+            else {
+                $tz = $dateTime->getTimezone();
+                if (substr(strtoupper($originalValue) , strlen($originalValue)-1, 1 ) != 'Z') {
+                    // floating datetime, if UTC then VERY likely a mistake with missing TZID (common)
+                    if (strtoupper(($tz->getName()) == 'UTC'))
+                        $tz = (string) Tinebase_Core::getUserTimezone();
+                }
+            }
             $result = new Tinebase_DateTime($dateTime->format(Tinebase_Record_Abstract::ISO8601LONG), $tz);
         } else {
             $result = new Tinebase_DateTime($dateTimeProperty->getValue());
         }
         
TZConvertFix.patch (1,705 bytes)
pschuele

pschuele

2017-10-16 09:23

administrator   ~0020976

i also uploaded the patches to the community gerrit:

weberhos patch: https://gerrit.tine20.org/tine20/3483
Ingos patch: https://gerrit.tine20.org/tine20/3485

I'll post the results of jenkins when i have them.
pschuele

pschuele

2017-10-16 09:26

administrator   ~0020978

> How do you import a, say, holiday calendar without being added as attendee and organizer and your time shown blocked. That's just plain silly.

I'll ask Cornelius about that, maybe he has a good suggestion how to solve this.

Issue History

Date Modified Username Field Change
2017-10-06 08:03 ingoratsdorf New Issue
2017-10-06 08:03 ingoratsdorf Tag Attached: calendar
2017-10-07 11:21 ingoratsdorf Note Added: 0020890
2017-10-09 08:26 pschuele Assigned To => pschuele
2017-10-09 08:26 pschuele Note Added: 0020894
2017-10-09 08:27 pschuele Status new => gerrit
2017-10-09 09:10 pschuele Note Added: 0020900
2017-10-09 11:15 ingoratsdorf Note Added: 0020902
2017-10-12 16:19 weberho Note Added: 0020930
2017-10-13 09:11 pschuele Relationship added related to 0006296
2017-10-13 09:12 pschuele Note Added: 0020944
2017-10-13 09:21 pschuele Note Added: 0020946
2017-10-13 11:51 ingoratsdorf Note Added: 0020952
2017-10-13 11:55 ingoratsdorf Note Added: 0020954
2017-10-13 21:41 ingoratsdorf File Added: TZConvertFix.patch
2017-10-13 21:41 ingoratsdorf Note Added: 0020966
2017-10-16 09:23 pschuele Note Added: 0020976
2017-10-16 09:26 pschuele Note Added: 0020978