messagingfw/msgsrvnstore/server/src/MSVTIME.CPP
changeset 62 db3f5fa34ec7
child 35 f8ad95794a08
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-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 "MSVTIME.H"
       
    17 #include "MSVPANIC.H"
       
    18 
       
    19 const TMsvDays KMsvNullDays = 0xffff;
       
    20 
       
    21 TMsvTime::TMsvTime()
       
    22 : iDays(KMsvNullDays)
       
    23 	{
       
    24 	}
       
    25 
       
    26 void TMsvTime::SetTime(const TTime& aTime)
       
    27 	{
       
    28 	if (aTime == Time::NullTTime())
       
    29 		iDays = KMsvNullDays;
       
    30 	else
       
    31 		{
       
    32 		__ASSERT_ALWAYS(aTime >= MinTime() && aTime <= MaxTime(), PanicServer(EMsvDateOutsideValidRange));
       
    33 		iDays = (TMsvDays)aTime.DaysFrom(MinTime()).Int();
       
    34 		iMinutes = (TMsvMinutes)(aTime.DateTime().Hour() * 60 + aTime.DateTime().Minute());
       
    35 		}
       
    36 	}
       
    37 
       
    38 void TMsvTime::GetTime(TTime& aTime) const
       
    39 	{
       
    40 	if (IsNull())
       
    41 		aTime = Time::NullTTime();
       
    42 	else
       
    43 		{
       
    44 		aTime = MinTime();
       
    45 		aTime += TTimeIntervalDays(iDays);
       
    46 		aTime += TTimeIntervalMinutes(iMinutes);
       
    47 		}
       
    48 	}
       
    49 
       
    50 TBool TMsvTime::operator>=(const TTime& aTime) const
       
    51 	{
       
    52 	TTime thisTime;
       
    53 	GetTime(thisTime);
       
    54 
       
    55 	TDateTime dt = aTime.DateTime();
       
    56 	dt.SetSecond(0);
       
    57 	dt.SetMicroSecond(0);
       
    58 
       
    59 	return thisTime >= TTime(dt);
       
    60 	}
       
    61 
       
    62 TBool TMsvTime::IsNull() const
       
    63 	{
       
    64 	return iDays == KMsvNullDays;
       
    65 	}
       
    66 
       
    67 void TMsvTime::InternalizeL(RReadStream& aStream)
       
    68 	{
       
    69 	aStream >> iDays;
       
    70 	aStream >> iMinutes;
       
    71 	}
       
    72 
       
    73 void TMsvTime::ExternalizeL(RWriteStream& aStream) const
       
    74 	{
       
    75 	aStream << iDays;
       
    76 	aStream << iMinutes;
       
    77 	}
       
    78 
       
    79 TTime TMsvTime::MinTime() const
       
    80 	{
       
    81 	return TTime(TDateTime(1900,EJanuary,0,0,0,0,0));
       
    82 	}
       
    83 
       
    84 TTime TMsvTime::MaxTime() const
       
    85 	{
       
    86 	return TTime(TDateTime(2100,EDecember,30,23,59,59,0));
       
    87 	}