pimappservices/calendar/client/src/calinstanceimpl.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "calinstanceimpl.h"
       
    17 #include <calentry.h>
       
    18 #include "calentryimpl.h"
       
    19 #include "agmentry.h"
       
    20 #include "calinstance.h"
       
    21 
       
    22 CCalInstanceImpl::CCalInstanceImpl(CCalEntry* aEntry, const TCalTime& aTime) :
       
    23 	iCalEntry(*aEntry), iCalTime(aTime)
       
    24 	{
       
    25 	}
       
    26 	
       
    27 CCalInstanceImpl::~CCalInstanceImpl()
       
    28 	{
       
    29 	delete &iCalEntry;
       
    30 	}
       
    31 
       
    32 CCalInstanceImpl* CCalInstanceImpl::NewL(CCalEntry* aEntry, const TCalTime& aTime)
       
    33 	{
       
    34 	CCalInstanceImpl* self = new (ELeave) CCalInstanceImpl(aEntry, aTime);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 CCalEntry& CCalInstanceImpl::Entry() const
       
    39 	{
       
    40 	return iCalEntry;
       
    41 	}
       
    42 
       
    43 TCalTime CCalInstanceImpl::Time() const
       
    44 	{
       
    45 	return iCalTime;
       
    46 	}
       
    47 	
       
    48 TCalTime CCalInstanceImpl::StartTimeL() const
       
    49 	{
       
    50 	TCalTime instanceStartTime;
       
    51 	TTimeIntervalMicroSeconds duration(0);
       
    52 	if (iCalEntry.EntryTypeL() == CCalEntry::ETodo)
       
    53 		{
       
    54 		TTime entryStartTime(iCalEntry.StartTimeL().TimeLocalL());
       
    55 		TTime entryEndTime(iCalEntry.EndTimeL().TimeLocalL());
       
    56 		TTime nullTime = Time::NullTTime();
       
    57 		if (!(nullTime == entryStartTime || nullTime == entryEndTime))
       
    58 			{
       
    59 			duration = entryEndTime.MicroSecondsFrom(entryStartTime);
       
    60 			}
       
    61 		}
       
    62 	if (iCalTime.TimeMode() == TCalTime::EFloating)
       
    63 		{
       
    64 		instanceStartTime.SetTimeLocalFloatingL(iCalTime.TimeLocalL() - duration);
       
    65 		}
       
    66 	else
       
    67 		{
       
    68 		instanceStartTime.SetTimeLocalL(iCalTime.TimeLocalL() - duration);
       
    69 		}
       
    70 	return instanceStartTime;
       
    71 	}
       
    72 
       
    73 TCalTime CCalInstanceImpl::EndTimeL() const
       
    74 	{
       
    75 	TCalTime instanceEndTime;
       
    76 	TTimeIntervalMicroSeconds duration(0);
       
    77 	if (iCalEntry.EntryTypeL() != CCalEntry::ETodo)
       
    78 		{
       
    79 		TTime entryStartTime(iCalEntry.StartTimeL().TimeLocalL());
       
    80 		TTime entryEndTime(iCalEntry.EndTimeL().TimeLocalL());
       
    81 		TTime nullTime = Time::NullTTime();
       
    82 		if (!(nullTime == entryStartTime || nullTime == entryEndTime))
       
    83 			{
       
    84 			duration = entryEndTime.MicroSecondsFrom(entryStartTime);
       
    85 			}
       
    86 		}
       
    87 
       
    88 	if (iCalTime.TimeMode() == TCalTime::EFloating)
       
    89 		{
       
    90 		instanceEndTime.SetTimeLocalFloatingL(iCalTime.TimeLocalL() + duration);
       
    91 		}
       
    92 	else
       
    93 		{
       
    94 		instanceEndTime.SetTimeLocalL(iCalTime.TimeLocalL() + duration);
       
    95 		}
       
    96 	return instanceEndTime;
       
    97 	}
       
    98 
       
    99 TCalInstanceId CCalInstanceImpl::InstanceIdL() const
       
   100 	{
       
   101 	TCalInstanceId instanceId;
       
   102 	instanceId.iEntryLocalId = iCalEntry.LocalUidL();
       
   103 	instanceId.iInstanceTime = Time();
       
   104 	instanceId.iCollectionId = iCalEntry.ShortFileIdL();
       
   105 	return instanceId;
       
   106 	}
       
   107