Skip to Content
0
Former Member
May 08, 2008 at 07:26 AM

Calendar shows task always in user-timezone

46 Views

Hi,

First a short introduction in my problem:

I've implemented a calendar which should view these 3 Tasks:

- 6.5.2008 00:00 - 6.5.2008 23:59 Task 1 (1 day duration) in UTC

- 7.5.2008 00:00 - 8.5.2008 23:59 Task 2 (2 day duration) in UTC

- 5.5.2008 00:00 - 9.5.2008 23:59 Task 3 (5 day duration) in UTC

The Demo User which logs in has TimeZone "Europe/Berlin". The Calendar has a dropdownbox where the user can select either "Facility" or "My TimeZone":

In "Facility" the User should see these 3 Tasks in UTC an not in his own timezone (all tasks from 00:00 to 23:59).

In "my timezone", he should see the 3 Tasks in his TimeZone (Europe/Berlin is UTC+2h at the moment) --> so the tasks are always from 02:00 - 01:59 for him.

The Problem:

When the sap.authentification is enabled and a user logs in, the "Facility" never shows me this Tasks in UTC. The Task is always shown in his timezone (02:00 - 01:59). But I have set UTC anywhere.

In "my timezone", where i load the current user-timezone its shown from 00:00 - 23:59.

I have absolutely no idea why the context element shows this always in user timezone

(_context element "timezone" of the Calendar view is bound to my attribute "zeitzone"_)

Here is the code part - I've debugged already. Everywhere is set UTC, but the Calendar always shows in userTime.

private void fillCalendar(String zeitstring) // 
    {
 
       deleteEntries();

        // check which mode is selected
        if (zeitstring == "Facility")
        {
            // default should be UTC 
            zeitzone = TimeZone.getDefault();
            zeitzone.setID("UTC");
            zeitzone = TimeZone.getTimeZone(zeitzone.getID());
            TimeZone.setDefault(zeitzone);
            // calenderinstanz in UTC
            Calendar calendar = Calendar.getInstance().getInstance(zeitzone);

            CctDate firstVisibleDate = new CctDate(new java.sql.Date(calendar.getTimeInMillis()));
            Time myTime = Time.valueOf("00:00:00");
            CctTime firstVisibleTime = new CctTime(myTime);
            // determine the startdate and starttime for the calendar

            wdContext.currentContextElement().setFirstVisibleDate(firstVisibleDate);
            wdContext.currentContextElement().setFirstVisibleTime(firstVisibleTime);
            TimeZone tz = TimeZone.getDefault();

            IECCalendarInterface calendarInterface = new ExampleCalendarEntrySupplier();

            List calendarEntries = calendarInterface.getCalendarEntries();

            int i = 0;
            zeitzone = TimeZone.getDefault();

            for (Iterator iterator = calendarEntries.iterator(); iterator.hasNext();)
            {
                ECCalendarEntry entry = (ECCalendarEntry) iterator.next();

                CctCode timeZoneCode = new CctCode(tz.getDisplayName(), null, null, null, null, null);

                CctDateTime startDate = new CctDateTime(entry.getMStartDate(), timeZoneCode, new Boolean("false"));
                CctDateTime endDate = new CctDateTime(entry.getMEndDate(), timeZoneCode, new Boolean("false"));

                i++;
                zeitzone = TimeZone.getDefault();
                createEntry(startDate, endDate, entry.getMTitle(), entry.getMDescription(), WDTableCellDesign.valueOf(i));

               
            }
           
        }

        else if (zeitstring == "My TimeZone")
        {
            ISessionContext context = SessionContextFactory.create();

            zeitzone = context.getCurrentUser().getTimeZone();
            TimeZone.setDefault(zeitzone);
            Calendar calendar = Calendar.getInstance().getInstance(zeitzone);

            CctDate firstVisibleDate = new CctDate(new java.sql.Date(calendar.getTimeInMillis()));
            Time myTime = Time.valueOf("00:00:00");
            CctTime firstVisibleTime = new CctTime(myTime);
            // determine the startdate and starttime for the calendar

            wdContext.currentContextElement().setFirstVisibleDate(firstVisibleDate);
            wdContext.currentContextElement().setFirstVisibleTime(firstVisibleTime);
            TimeZone tz = TimeZone.getDefault();

            IECCalendarInterface calendarInterface = new ExampleCalendarEntrySupplier();

            List calendarEntries = calendarInterface.getCalendarEntries();

            deleteEntries();
            int i = 0;

            for (Iterator iterator = calendarEntries.iterator(); iterator.hasNext();)
            {
                ECCalendarEntry entry = (ECCalendarEntry) iterator.next();

                CctCode timeZoneCode1 = new CctCode(tz.getDisplayName(), null, null, null, null, null);

                CctDateTime startDate = new CctDateTime(entry.getMStartDate(), timeZoneCode1, new Boolean("false"));
                CctDateTime endDate = new CctDateTime(entry.getMEndDate(), timeZoneCode1, new Boolean("false"));

                i++;

                createEntry(startDate, endDate, entry.getMTitle(), entry.getMDescription(), WDTableCellDesign.valueOf(i));

            }
        }

      
    }

Thank you,

Daniel

Update:

I've tried to fix the problem nearly the whole day.

I've debugged the fillCalendar()-Method while inserting the first Task:

- Default Timezone is "UTC"!

- zeitzone.ID and tz.ID are always set on "UTC"

- timeZoneCode is "Koordinierte Universalzeit null null null null null" (koordinierte Universalzeit is German for UTC 😉 )

- startDate : "06.05.2008 00:00:00 Koordinierte Universalzeit false"

- endDate: "06.05.2008 23:59:00 Koordinierte Universalzeit false"

- calendar.zone.ID is set to "UTC"

---> The Calendar shows the task from 06.05.2008 02:00 to 07.05.2008 01.59

Somewhere must stand my timezone and the calendar refuses to display the view in UTC!!! But where?

Edited by: Daniel Mler on May 8, 2008 3:31 PM