pimappservices/calendar/shared/src/agmcalendartime.cpp
changeset 0 f979ecb2b13e
child 10 38571fd2a704
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 
       
    17 #include "agmdate.h"
       
    18 #include "agmtlsproxy.h"
       
    19 #include "agmpanic.h"
       
    20 
       
    21 #include <tz.h>
       
    22 #include <tzconverter.h>
       
    23 #include <vtzrules.h>
       
    24 
       
    25 const TInt16  KOffsetUnspecified = KMaxTInt16;
       
    26 const TUint16 KTzIdFloating = 0x8000;
       
    27 const TUint16 KTzIdUnspecified = 0x7fff;
       
    28 
       
    29 const TUint32 KAgnNewCalTimeMask = (1 << 30);
       
    30 const TUint32 KAgmTimeFloatingFlag = 0x01;
       
    31 
       
    32 // TAgnCalendarTime //
       
    33 
       
    34 EXPORT_C TAgnCalendarTime::TAgnCalendarTime() : 
       
    35 	iTime(Time::NullTTime()), 
       
    36 	iLocalOffsetInMinutes(KOffsetUnspecified), 
       
    37 	iTzId(KTzIdUnspecified), 
       
    38 	iTimeZoneAccessor(NULL)
       
    39 	{
       
    40 	}
       
    41 
       
    42 EXPORT_C void TAgnCalendarTime::SetFloatingL(const TTime& aTime)
       
    43 	{
       
    44 	SetDateTimeL(aTime, ETrue, MAgnCalendarTimeMode::ELocal);
       
    45 	}
       
    46 
       
    47 EXPORT_C void TAgnCalendarTime::SetLocalL(const TTime& aTime)
       
    48 	{
       
    49 	SetDateTimeL(aTime, EFalse, MAgnCalendarTimeMode::ELocal);
       
    50 	}
       
    51 	
       
    52 EXPORT_C void TAgnCalendarTime::SetUtcL(const TTime& aTime)
       
    53 	{
       
    54 	SetDateTimeL(aTime, EFalse, MAgnCalendarTimeMode::EUtc);
       
    55 	}
       
    56 
       
    57 void TAgnCalendarTime::SetNull()
       
    58 	{
       
    59 	iTime = Time::NullTTime();
       
    60 	iLocalOffsetInMinutes = KOffsetUnspecified;
       
    61 	}
       
    62 	
       
    63 EXPORT_C TTime TAgnCalendarTime::LocalL() const
       
    64 	{
       
    65 	if (TimeMode() == MAgnCalendarTimeMode::EFixedTimeZone)
       
    66 		{
       
    67 		return DateTimeL(MAgnCalendarTimeMode::EFixedLocal);
       
    68 		}
       
    69 	return DateTimeL(MAgnCalendarTimeMode::ELocal);
       
    70 	}
       
    71 
       
    72 EXPORT_C TTime TAgnCalendarTime::UtcL() const
       
    73 	{
       
    74 	return DateTimeL(MAgnCalendarTimeMode::EUtc);
       
    75 	}
       
    76 
       
    77 void TAgnCalendarTime::SetDateTimeL(const TTime& aTime, TBool aFloating, MAgnCalendarTimeMode::TFormat aFormat)
       
    78 /** Set the time and time mode of the AgnCalendarTime
       
    79 @internalAll
       
    80 
       
    81 @param aTime The time to be stored, can be UTC if aFormat is EUtc, or local if aFormat is ELocal or EFixedLocal
       
    82 @param aMode Reference to a MAgnCalendarTimeMode derived time mode class. This time mode must be retrieved from AgnDateTime or CAgnTlsProxy
       
    83 @param aFormat The time format of aTime
       
    84 */
       
    85 	{
       
    86 	if (!AgnDateTime::IsValidAgendaTTime(aTime))
       
    87 		{
       
    88 		// If the time is outside the range between MinDate and MaxDate, don't 
       
    89 		// convert it, but normalise it to the max or min datetimes as 
       
    90 		// appropriate.
       
    91 		if(aTime == Time::NullTTime())
       
    92 			{
       
    93 			iTime = aTime;	
       
    94 			}
       
    95 		else if(aTime <= AgnDateTime::MinDate())
       
    96 			{
       
    97 			iTime = AgnDateTime::MinDate();
       
    98 			}
       
    99 		else if(aTime >= AgnDateTime::MaxDate())
       
   100 			{
       
   101 			iTime = AgnDateTime::MaxDate();
       
   102 			}
       
   103  		iLocalOffsetInMinutes = KOffsetUnspecified;
       
   104 		}
       
   105 	else
       
   106 		{
       
   107 		if ( ! aFloating)
       
   108 			{
       
   109 			if (aFormat == MAgnCalendarTimeMode::EUtc)
       
   110 				{
       
   111 				// If the time is UTC, just store it. The offset is unknown at this point.
       
   112 				iTime = aTime;
       
   113 				iLocalOffsetInMinutes = KOffsetUnspecified;
       
   114 				}
       
   115 			else
       
   116 				{
       
   117 				// If the time is local, convert it and store the offset as well as the time.
       
   118 				TTime localTime(aTime);
       
   119 				TTime utcTime(aTime);
       
   120 				TimeZoneAccessor()->FixedTimeMode().ToL(aFormat, utcTime);
       
   121 				//In order to ensure UTC time is still within the range of Max and Min time
       
   122 				//after the conversion. Any UTC time that is not within the range is converted
       
   123 				//to Max or Min time.
       
   124 				if (utcTime <= AgnDateTime::MinDate())
       
   125 					{
       
   126 					localTime = utcTime = AgnDateTime::MinDate();
       
   127 					}
       
   128 				else if (utcTime >= AgnDateTime::MaxDate())
       
   129 					{
       
   130 					localTime = utcTime = AgnDateTime::MaxDate();
       
   131 					}
       
   132 				iTime = utcTime;
       
   133 				StoreNewOffset(localTime);
       
   134 				SetTzId(TimeZoneAccessor()->CurrentTzId());
       
   135 				}
       
   136 			SetFloatingFlag(EFalse);
       
   137 			}
       
   138 		else
       
   139 			{
       
   140 			// floating time
       
   141 			if (aFormat == MAgnCalendarTimeMode::EUtc)
       
   142 				{
       
   143 				TTime utcTime(aTime);
       
   144 				TTime localTime(aTime);
       
   145 				TimeZoneAccessor()->FloatingTimeMode().ToL(aFormat, localTime);
       
   146 				iTime = localTime;
       
   147 				StoreNewOffset(utcTime);
       
   148 				SetTzId(TimeZoneAccessor()->CurrentTzId());
       
   149 				}
       
   150 			else
       
   151 				{
       
   152 				iTime = aTime;
       
   153 				iLocalOffsetInMinutes = KOffsetUnspecified;
       
   154 				}
       
   155 			SetFloatingFlag(ETrue);
       
   156 			}
       
   157 		}
       
   158 	__ASSERT_DEBUG(IsValidTime(), User::Invariant());
       
   159 	}
       
   160 
       
   161 EXPORT_C TTime TAgnCalendarTime::DateTimeL(MAgnCalendarTimeMode::TFormat aFormat) const
       
   162 	{
       
   163 	if(iTime <= AgnDateTime::MinDate() || iTime >= AgnDateTime::MaxDate() || iTime == Time::NullTTime())
       
   164 		{
       
   165 		// If the time is outside the range between MinDate and MaxDate, don't convert it. 
       
   166 		// If the time is to be returned in UTC, don't convert it. 
       
   167 		return iTime;
       
   168 		}
       
   169 
       
   170 	if ((TimeMode() == MAgnCalendarTimeMode::EFixedUtc && aFormat == MAgnCalendarTimeMode::EUtc) ||
       
   171 		(TimeMode() == MAgnCalendarTimeMode::EFloating && aFormat == MAgnCalendarTimeMode::ELocal) ||
       
   172 		(TimeMode() == MAgnCalendarTimeMode::EFloating && aFormat == MAgnCalendarTimeMode::EFixedLocal) ||
       
   173 		(TimeMode() == MAgnCalendarTimeMode::EFixedTimeZone && aFormat == MAgnCalendarTimeMode::EFixedLocal))
       
   174 		{
       
   175 		return iTime;
       
   176 		}
       
   177 	
       
   178 	// In this case the time is to be converted
       
   179 	TUint16 tzId = TimeZoneAccessor()->CurrentTzId(); // Check whether or not the time zone has changed. 
       
   180 	
       
   181 	// Note that each TAgnCalendarTime's offset is updated on demand, so there is no need to update all 
       
   182 	// offsets when the local time zone changes.
       
   183 	
       
   184 	if (TimeMode() == MAgnCalendarTimeMode::EFixedUtc)
       
   185 		{
       
   186 		if (iLocalOffsetInMinutes == KOffsetUnspecified ||
       
   187 			TzId() != tzId)
       
   188 			{
       
   189 			// If the offset is unknown or the time zone has changed, recalculate the offset.
       
   190 			TTime newLocalTime(iTime);
       
   191 			CalendarTimeMode()->FromL(aFormat, newLocalTime);
       
   192 			StoreNewOffset(newLocalTime);
       
   193 			SetTzId(tzId);
       
   194 			}
       
   195 		}
       
   196 	else if (TimeMode() == MAgnCalendarTimeMode::EFloating)
       
   197 		{
       
   198 		if (iLocalOffsetInMinutes == KOffsetUnspecified ||
       
   199 			TzId() != tzId)
       
   200 			{
       
   201 			// If the offset is unknown or the time zone has changed, recalculate the offset.
       
   202 			TTime newUtcTime(iTime);
       
   203 			CalendarTimeMode()->FromL(aFormat, newUtcTime);
       
   204 			StoreNewOffset(newUtcTime);
       
   205 			SetTzId(tzId);
       
   206 			}
       
   207 		}
       
   208 	else // using rule time mode
       
   209 		{
       
   210 		User::Leave(KErrNotSupported);
       
   211 		}
       
   212 			
       
   213 	return iTime + TTimeIntervalMinutes(iLocalOffsetInMinutes);
       
   214 	}
       
   215 
       
   216 	
       
   217 void TAgnCalendarTime::StoreNewOffset(const TTime& aTime) const
       
   218 	{
       
   219 	TTimeIntervalMinutes mins;
       
   220 	aTime.MinutesFrom(iTime, mins);
       
   221 	iLocalOffsetInMinutes = mins.Int();
       
   222 	}
       
   223 
       
   224 CAgnTlsProxy* TAgnCalendarTime::TimeZoneAccessor() const
       
   225 	{
       
   226 	if (!iTimeZoneAccessor)
       
   227 		{
       
   228 		iTimeZoneAccessor = static_cast<CAgnTlsProxy*>(Dll::Tls());
       
   229 		__ASSERT_ALWAYS(iTimeZoneAccessor, User::Invariant());
       
   230 		}
       
   231 	return iTimeZoneAccessor;
       
   232 	}
       
   233 
       
   234 EXPORT_C TBool TAgnCalendarTime::IsSet() const
       
   235 	{
       
   236 	return (iTime != Time::NullTTime());
       
   237 	}
       
   238 
       
   239 
       
   240 	
       
   241 EXPORT_C TBool TAgnCalendarTime::operator==(const TAgnCalendarTime& aTime) const
       
   242 	{
       
   243 	if (TimeMode() == aTime.TimeMode() &&
       
   244 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   245 		{
       
   246 		// both times are either floating or fixed, no conversion needed
       
   247 		return (iTime == aTime.iTime);
       
   248 		}
       
   249 	else
       
   250 		{
       
   251 		return (UtcL() == aTime.UtcL());
       
   252 		}
       
   253 	}
       
   254 
       
   255 
       
   256 
       
   257 EXPORT_C TBool TAgnCalendarTime::operator!=(const TAgnCalendarTime& aTime) const
       
   258 	{
       
   259 	if (TimeMode() == aTime.TimeMode() &&
       
   260 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   261 		{
       
   262 		// both times are either floating or fixed, no conversion needed
       
   263 		return (iTime != aTime.iTime);
       
   264 		}
       
   265 	else
       
   266 		{
       
   267 		return (UtcL() != aTime.UtcL());
       
   268 		}
       
   269 	}
       
   270 
       
   271 
       
   272 
       
   273 EXPORT_C TBool TAgnCalendarTime::operator<(const TAgnCalendarTime& aTime) const
       
   274 	{
       
   275 	if (TimeMode() == aTime.TimeMode() &&
       
   276 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   277 		{
       
   278 		// both times are either floating or fixed, no conversion needed
       
   279 		return (iTime < aTime.iTime);
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		return (UtcL() < aTime.UtcL());
       
   284 		}
       
   285 	}
       
   286 
       
   287 
       
   288 
       
   289 EXPORT_C TBool TAgnCalendarTime::operator>(const TAgnCalendarTime& aTime) const
       
   290 	{
       
   291 	if (TimeMode() == aTime.TimeMode() &&
       
   292 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   293 		{
       
   294 		// both times are either floating or fixed, no conversion needed
       
   295 		return (iTime > aTime.iTime);
       
   296 		}
       
   297 	else
       
   298 		{
       
   299 		return (UtcL() > aTime.UtcL());
       
   300 		}
       
   301 	}
       
   302 
       
   303 
       
   304 
       
   305 EXPORT_C TBool TAgnCalendarTime::operator<=(const TAgnCalendarTime& aTime) const
       
   306 	{
       
   307 	if (TimeMode() == aTime.TimeMode() &&
       
   308 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   309 		{
       
   310 		// both times are either floating or fixed, no conversion needed
       
   311 		return (iTime <= aTime.iTime);
       
   312 		}
       
   313 	else
       
   314 		{
       
   315 		return (UtcL() <= aTime.UtcL());
       
   316 		}
       
   317 	}
       
   318 
       
   319 
       
   320 
       
   321 EXPORT_C TBool TAgnCalendarTime::operator>=(const TAgnCalendarTime& aTime) const
       
   322 	{
       
   323 	if (TimeMode() == aTime.TimeMode() &&
       
   324 		(TimeMode() == MAgnCalendarTimeMode::EFixedUtc || TimeMode() == MAgnCalendarTimeMode::EFloating))
       
   325 		{
       
   326 		// both times are either floating or fixed, no conversion needed
       
   327 		return (iTime >= aTime.iTime);
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		return (UtcL() >= aTime.UtcL());
       
   332 		}
       
   333 	}
       
   334 
       
   335 
       
   336 
       
   337 EXPORT_C TBool TAgnCalendarTime::IsValidTime() const
       
   338 	{
       
   339 	TBool isNullTime(iTime == Time::NullTTime());
       
   340 	TBool isWithinValidRange(iTime >= Time::MinTTime() && iTime <= Time::MaxTTime());
       
   341 	return (isNullTime || isWithinValidRange);
       
   342 	}
       
   343 
       
   344 /*
       
   345 In v9.1 time was stored as a TUint64 value of number of microseconds since midnight
       
   346 January 1st, 0 AD nominal Gregorian. 
       
   347 
       
   348 The TAgnCalendarTime count time is a valid if it lay between Midnight, January 1st 1900 and 
       
   349 Midnight, December 31st 2100. It means TUint64 value should be between 0x00D504A2C672E000 and 0x00eb8d745a6fc000. 
       
   350 Also NullTime (0x8000000000000000) is supported.
       
   351 
       
   352 Internalize:
       
   353 1) read low 32 bits
       
   354 2) read high 32 bits
       
   355 3) if 2nd msb bit of high = 1 then: (note the 2nd msb bit is used because the 1st msb bit is used by Time::NullTTime().
       
   356         - must be reading v9.2+ format (iTime values that are either agn null time or between agn min time to agn max time can never have this msb bit set to 1)
       
   357         - flip 2nd msb bit to 0 to create iTime later in step 4
       
   358         - read another 32 bits and if lsb = 1 set to floating mode else must be fixed mode (other 31 bits will be used for TzId in future)
       
   359         - read yet another 32 bits (future padding)
       
   360 4) set iTime = TTime(MAKE_TINT64(high, low))
       
   361 
       
   362 
       
   363 Externalize:
       
   364 1) write low 32 bits of iTime,
       
   365 2) mask the high 32 bits of iTime with (1<<30) to signify a v9.2+ time format
       
   366 3) write masked high bits of iTime
       
   367 4) write another 32 bits (lsb = 0 for fixed time mode, 1 for floating time mode)
       
   368 5) write yet another 32 bits (value = 0 always for future use) 
       
   369 */
       
   370 EXPORT_C void TAgnCalendarTime::InternalizeL(RReadStream& aStream)
       
   371 	{
       
   372 	TUint32 low = aStream.ReadUint32L();
       
   373 	TUint32 high = aStream.ReadUint32L();
       
   374 
       
   375 	if (high & KAgnNewCalTimeMask)
       
   376 		{
       
   377 		// reading v9.2+ format
       
   378 		high = high & ~KAgnNewCalTimeMask;
       
   379 
       
   380 		TUint32 attr = aStream.ReadUint32L(); //read attribute
       
   381 		if (attr & KAgmTimeFloatingFlag)
       
   382 			{
       
   383 			SetFloatingFlag(ETrue);
       
   384 			}
       
   385 		else	
       
   386 			{
       
   387 			SetFloatingFlag(EFalse);
       
   388 			}
       
   389 
       
   390 		aStream.ReadUint32L(); //reserved 32 bits for future use
       
   391 		}
       
   392 	else
       
   393 		{
       
   394 		// for backcompatibility, v9.1 only support fix time mode
       
   395 		iTzId = KTzIdUnspecified;
       
   396 		SetFloatingFlag(EFalse);
       
   397 		}
       
   398 
       
   399 	iTime = TTime(MAKE_TINT64(high, low));  //old data format
       
   400 	__ASSERT_ALWAYS(IsValidTime(), User::Leave(KErrCorrupt));
       
   401 	}
       
   402 
       
   403 void TAgnCalendarTime::ExternalizeL(RWriteStream& aStream) const
       
   404 	{
       
   405 	aStream << 	I64LOW(iTime.Int64());
       
   406 	aStream << 	(I64HIGH(iTime.Int64()) | KAgnNewCalTimeMask);
       
   407 	TUint32 attr(0);
       
   408 	if (TimeMode() == MAgnCalendarTimeMode::EFloating)
       
   409 		{
       
   410 		attr |= KAgmTimeFloatingFlag;
       
   411 		}
       
   412 	
       
   413 	aStream << attr;
       
   414 	aStream.WriteUint32L(0); // reserved 32 bits for future use
       
   415 
       
   416 	}
       
   417 
       
   418 void TAgnCalendarTime::SetFloatingFlag(TBool aFloating) const
       
   419 	{
       
   420 	if (aFloating)
       
   421 		{
       
   422 		iTzId |= KTzIdFloating;
       
   423 		}
       
   424 	else
       
   425 		{
       
   426 		iTzId &= ~KTzIdFloating;
       
   427 		}
       
   428 	}
       
   429 
       
   430 void TAgnCalendarTime::SetTzId(TUint16 aTzId) const
       
   431 	{
       
   432 	iTzId = aTzId | (iTzId & KTzIdFloating);
       
   433 	}
       
   434 
       
   435 TUint16 TAgnCalendarTime::TzId() const
       
   436 	{
       
   437 	return (iTzId & ~KTzIdFloating);
       
   438 	}
       
   439 	
       
   440 const MAgnCalendarTimeMode* TAgnCalendarTime::CalendarTimeMode() const
       
   441 	{
       
   442 	if (iTzId & KTzIdFloating)
       
   443 		{
       
   444 		return &TimeZoneAccessor()->FloatingTimeMode();
       
   445 		}
       
   446 	else
       
   447 		{
       
   448 		// this is needed for alarm info reconsturction
       
   449 		return &TimeZoneAccessor()->FixedTimeMode();
       
   450 		}
       
   451 	}
       
   452 	
       
   453 EXPORT_C MAgnCalendarTimeMode::TTimeMode TAgnCalendarTime::TimeMode() const
       
   454 	{
       
   455 	if (CalendarTimeMode())
       
   456 		{
       
   457 		return CalendarTimeMode()->TimeMode();
       
   458 		}
       
   459 	return MAgnCalendarTimeMode::EFixedUtc;    // default is fixed time mode if not set
       
   460 	}
       
   461 
       
   462 /*static*/ TInt TAgnCalendarTime::Compare(const TAgnCalendarTime& aLeft, const TAgnCalendarTime& aRight)
       
   463 	{
       
   464 	if (aLeft == aRight)
       
   465 		{
       
   466 		return 0;
       
   467 		}
       
   468 	else if (aLeft > aRight)
       
   469 		{
       
   470 		return 1;
       
   471 		}
       
   472 	return -1;
       
   473 	}
       
   474 
       
   475 /*static*/ void TAgnCalendarTime::InsertInOrderL(RArray<TAgnCalendarTime>& aTimeArray, const TAgnCalendarTime& aTimeToInsert)
       
   476 	{
       
   477 	TLinearOrder<TAgnCalendarTime> agnCalTimeOrder(TAgnCalendarTime::Compare);
       
   478 	TInt err = aTimeArray.InsertInOrder(aTimeToInsert, agnCalTimeOrder);
       
   479 	if (err != KErrAlreadyExists)
       
   480 		{
       
   481 		User::LeaveIfError(err);
       
   482 		}
       
   483 	}
       
   484 
       
   485 /*static*/ TBool TAgnCalendarTime::CompareTimeArrays(const RArray<TAgnCalendarTime>* aLeft, const RArray<TAgnCalendarTime>* aRight)
       
   486 	{
       
   487 	if (aLeft == NULL)
       
   488 		{
       
   489 		if (aRight == NULL)
       
   490 			{
       
   491 			return ETrue;
       
   492 			}
       
   493 		return EFalse;
       
   494 		}
       
   495 
       
   496 	// aLeft is non-NULL
       
   497 	if (aRight == NULL)
       
   498 		{
       
   499 		return EFalse;
       
   500 		}
       
   501 	
       
   502 	if (aLeft->Count() != aRight->Count())
       
   503 		{
       
   504 		return EFalse;
       
   505 		}
       
   506 	
       
   507 	const TInt KTimeCount = aLeft->Count();
       
   508 	for (TInt i = 0; i < KTimeCount; ++i)
       
   509 		{
       
   510 		if ((*aLeft)[i] != (*aRight)[i])
       
   511 			{
       
   512 			return EFalse;
       
   513 			}
       
   514 		}
       
   515 	return ETrue;
       
   516 	}
       
   517 
       
   518 /*static*/ void TAgnCalendarTime::InternalizeTimeArrayL(RArray<TAgnCalendarTime>& aArray, RReadStream& aStream)
       
   519 	{
       
   520 	aArray.Reset();
       
   521 	const TInt KCount = aStream.ReadUint16L();
       
   522 	
       
   523 	TAgnCalendarTime time;
       
   524 	for (TInt i = 0; i < KCount; ++i)
       
   525 		{
       
   526 		aStream >> time;
       
   527 		aArray.AppendL(time);
       
   528 		}
       
   529 	}
       
   530 
       
   531 /*static*/ void TAgnCalendarTime::ExternalizeTimeArrayL(RArray<TAgnCalendarTime>& aArray, RWriteStream& aStream)
       
   532 	{
       
   533 	const TInt KCount = aArray.Count();
       
   534 	aStream.WriteUint16L(KCount);
       
   535 	
       
   536 	for (TInt i = 0; i < KCount; ++i)
       
   537 		{
       
   538 		aStream << aArray[i];
       
   539 		}
       
   540 	}
       
   541 
       
   542 // TAgnCalendarFixedTimeMode //
       
   543 
       
   544 TAgnCalendarFixedTimeMode::TAgnCalendarFixedTimeMode(CTzConverter& aTimeConverter) :
       
   545 	iTimeConverter(aTimeConverter)
       
   546 	{
       
   547 	}
       
   548 
       
   549 void TAgnCalendarFixedTimeMode::ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   550 	{
       
   551 	switch (aFormat)
       
   552 		{
       
   553 		case ELocal: 
       
   554 		case EFixedLocal: 
       
   555 			{
       
   556 			User::LeaveIfError(iTimeConverter.ConvertToUniversalTime(aTime));
       
   557 			}
       
   558 		case EUtc:
       
   559 			{
       
   560 			// do nothing - no conversion necessary
       
   561 			break;
       
   562 			}
       
   563 		default: 
       
   564 			{
       
   565 			Panic(EAgmErrUnsupportedTimeMode);
       
   566 			}
       
   567 		};
       
   568 	}
       
   569 
       
   570 void TAgnCalendarFixedTimeMode::FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   571 	{
       
   572 	switch (aFormat)
       
   573 		{
       
   574 		case ELocal: 
       
   575 		case EFixedLocal: 
       
   576 			{
       
   577 			User::LeaveIfError(iTimeConverter.ConvertToLocalTime(aTime));
       
   578 			break;
       
   579 			}
       
   580 		case EUtc:
       
   581 			{
       
   582 			// do nothing - no conversion necessary
       
   583 			break;
       
   584 			}
       
   585 		default: 
       
   586 			{
       
   587 			Panic(EAgmErrUnsupportedTimeMode);
       
   588 			}
       
   589 		}
       
   590 	}
       
   591 
       
   592 MAgnCalendarTimeMode::TTimeMode TAgnCalendarFixedTimeMode::TimeMode() const
       
   593 	{
       
   594 	return MAgnCalendarTimeMode::EFixedUtc;
       
   595 	}
       
   596 
       
   597 // TAgnCalendarFixedUsingRulesTimeMode //
       
   598 
       
   599 TAgnCalendarFixedUsingRulesTimeMode::TAgnCalendarFixedUsingRulesTimeMode(CTzRules& aTimeZoneRules, CTzConverter& aTimeConverter) :
       
   600 	iTimeZoneRules(aTimeZoneRules), iTimeConverter(aTimeConverter)
       
   601 	{
       
   602 	}
       
   603 
       
   604 const CTzRules& TAgnCalendarFixedUsingRulesTimeMode::TzZone() const
       
   605 	{
       
   606 	return iTimeZoneRules;
       
   607 	}
       
   608 
       
   609 void TAgnCalendarFixedUsingRulesTimeMode::ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   610 	{
       
   611 	switch (aFormat)
       
   612 		{
       
   613 		case ELocal:
       
   614 			{
       
   615 			User::LeaveIfError(iTimeConverter.ConvertToLocalTime(aTime));
       
   616 			break;
       
   617 			}
       
   618 		case EUtc:
       
   619 			{
       
   620 			iTimeZoneRules.ConvertToLocalL(aTime);
       
   621 			break;
       
   622 			}
       
   623 		case EFixedLocal: 
       
   624 			{
       
   625 			// do nothing - no conversion necessary
       
   626 			break;
       
   627 			}
       
   628 		default: 
       
   629 			{
       
   630 			Panic(EAgmErrUnsupportedTimeMode);
       
   631 			}
       
   632 		};
       
   633 	}
       
   634 
       
   635 void TAgnCalendarFixedUsingRulesTimeMode::FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   636 	{
       
   637 	switch (aFormat)
       
   638 		{
       
   639 		case EUtc: 
       
   640 			{
       
   641 			iTimeZoneRules.ConvertToUtcL(aTime);
       
   642 			break;
       
   643 			}
       
   644 		case ELocal:
       
   645 			{
       
   646 			User::LeaveIfError(iTimeConverter.ConvertToUniversalTime(aTime));
       
   647 			break;
       
   648 			}
       
   649 		case EFixedLocal: 
       
   650 			{
       
   651 			// do nothing - no conversion necessary
       
   652 			break;
       
   653 			}
       
   654 		default: 
       
   655 			{
       
   656 			Panic(EAgmErrUnsupportedTimeMode);
       
   657 			}
       
   658 		}
       
   659 	}
       
   660 
       
   661 MAgnCalendarTimeMode::TTimeMode TAgnCalendarFixedUsingRulesTimeMode::TimeMode() const
       
   662 	{
       
   663 	return MAgnCalendarTimeMode::EFixedTimeZone;
       
   664 	}
       
   665 
       
   666 // TAgnCalendarFloatingTimeMode //
       
   667 
       
   668 TAgnCalendarFloatingTimeMode::TAgnCalendarFloatingTimeMode(CTzConverter& aTimeConverter) :
       
   669 	iTimeConverter(aTimeConverter)
       
   670 	{
       
   671 	}
       
   672 
       
   673 void TAgnCalendarFloatingTimeMode::ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   674 	{
       
   675 	switch (aFormat)
       
   676 		{
       
   677 		case ELocal: 
       
   678 		case EFixedLocal: 
       
   679 			{
       
   680 			// do nothing - no conversion necessary
       
   681 			break;
       
   682 			}
       
   683 		case EUtc:
       
   684 			{
       
   685 			User::LeaveIfError(iTimeConverter.ConvertToLocalTime(aTime));
       
   686 			break;
       
   687 			}
       
   688 		default: 
       
   689 			{
       
   690 			Panic(EAgmErrUnsupportedTimeMode);
       
   691 			}
       
   692 		};
       
   693 	}
       
   694 
       
   695 void TAgnCalendarFloatingTimeMode::FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const
       
   696 	{
       
   697 	switch (aFormat)
       
   698 		{
       
   699 		case ELocal: 
       
   700 		case EFixedLocal: 
       
   701 			{
       
   702 			// do nothing - no conversion necessary
       
   703 			break;
       
   704 			}
       
   705 		case EUtc:
       
   706 			{
       
   707 			User::LeaveIfError(iTimeConverter.ConvertToUniversalTime(aTime));
       
   708 			break;
       
   709 			}
       
   710 		default: 
       
   711 			{
       
   712 			Panic(EAgmErrUnsupportedTimeMode);
       
   713 			}
       
   714 		};
       
   715 	}
       
   716 
       
   717 MAgnCalendarTimeMode::TTimeMode TAgnCalendarFloatingTimeMode::TimeMode() const
       
   718 	{
       
   719 	return MAgnCalendarTimeMode::EFloating;
       
   720 	}