messagingfw/msgsrvnstore/server/src/MSVTIME.CPP
author hgs
Wed, 03 Nov 2010 22:41:46 +0530
changeset 62 db3f5fa34ec7
child 35 f8ad95794a08
permissions -rw-r--r--
201044_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     1
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     2
// All rights reserved.
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     7
//
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     8
// Initial Contributors:
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    10
//
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    11
// Contributors:
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    12
//
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    13
// Description:
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    14
//
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    15
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    16
#include "MSVTIME.H"
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    17
#include "MSVPANIC.H"
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    18
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    19
const TMsvDays KMsvNullDays = 0xffff;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    20
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    21
TMsvTime::TMsvTime()
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    22
: iDays(KMsvNullDays)
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    23
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    24
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    25
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    26
void TMsvTime::SetTime(const TTime& aTime)
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    27
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    28
	if (aTime == Time::NullTTime())
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    29
		iDays = KMsvNullDays;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    30
	else
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    31
		{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    32
		__ASSERT_ALWAYS(aTime >= MinTime() && aTime <= MaxTime(), PanicServer(EMsvDateOutsideValidRange));
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    33
		iDays = (TMsvDays)aTime.DaysFrom(MinTime()).Int();
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    34
		iMinutes = (TMsvMinutes)(aTime.DateTime().Hour() * 60 + aTime.DateTime().Minute());
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    35
		}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    36
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    37
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    38
void TMsvTime::GetTime(TTime& aTime) const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    39
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    40
	if (IsNull())
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    41
		aTime = Time::NullTTime();
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    42
	else
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    43
		{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    44
		aTime = MinTime();
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    45
		aTime += TTimeIntervalDays(iDays);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    46
		aTime += TTimeIntervalMinutes(iMinutes);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    47
		}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    48
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    49
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    50
TBool TMsvTime::operator>=(const TTime& aTime) const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    51
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    52
	TTime thisTime;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    53
	GetTime(thisTime);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    54
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    55
	TDateTime dt = aTime.DateTime();
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    56
	dt.SetSecond(0);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    57
	dt.SetMicroSecond(0);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    58
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    59
	return thisTime >= TTime(dt);
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    60
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    61
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    62
TBool TMsvTime::IsNull() const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    63
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    64
	return iDays == KMsvNullDays;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    65
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    66
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    67
void TMsvTime::InternalizeL(RReadStream& aStream)
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    68
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    69
	aStream >> iDays;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    70
	aStream >> iMinutes;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    71
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    72
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    73
void TMsvTime::ExternalizeL(RWriteStream& aStream) const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    74
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    75
	aStream << iDays;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    76
	aStream << iMinutes;
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    77
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    78
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    79
TTime TMsvTime::MinTime() const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    80
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    81
	return TTime(TDateTime(1900,EJanuary,0,0,0,0,0));
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    82
	}
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    83
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    84
TTime TMsvTime::MaxTime() const
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    85
	{
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    86
	return TTime(TDateTime(2100,EDecember,30,23,59,59,0));
db3f5fa34ec7 201044_02
hgs
parents:
diff changeset
    87
	}