os/ossrv/genericservices/taskscheduler/SCHSVR/SCHTIME.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32def.h>
sl@0
    17
#include <s32strm.h>
sl@0
    18
#include "SCHTIME.H"
sl@0
    19
#include "SCHEXEC.H"
sl@0
    20
sl@0
    21
/**
sl@0
    22
UTC/Local Time flag value
sl@0
    23
@internalComponent
sl@0
    24
*/
sl@0
    25
const TUint32 KIsUtc = 0x00000001;
sl@0
    26
sl@0
    27
/** 
sl@0
    28
Default constructor for TTsTime.
sl@0
    29
This constructor initialises its member data to zero.
sl@0
    30
By default this sets it to be UTC based.
sl@0
    31
*/ 
sl@0
    32
EXPORT_C TTsTime::TTsTime():
sl@0
    33
	iUtcTime(0), 
sl@0
    34
	iOffset(0), 
sl@0
    35
	iFlags(KIsUtc)
sl@0
    36
	{
sl@0
    37
	}
sl@0
    38
sl@0
    39
/**
sl@0
    40
Copy constructor for TTsTime
sl@0
    41
@param aTTsTime value to duplicate
sl@0
    42
*/	
sl@0
    43
EXPORT_C TTsTime::TTsTime(const TTsTime& aTTsTime)
sl@0
    44
	{
sl@0
    45
	*this = aTTsTime;
sl@0
    46
	}
sl@0
    47
		
sl@0
    48
/** 
sl@0
    49
Constructs a TTsTime with a TTime. 
sl@0
    50
If the iIsUtc is ETrue, then TTsTime is UTC based time, if iIsUtc is EFalse 
sl@0
    51
then TTsTime is local time based. This constructor will update all the member data as appropriate.	
sl@0
    52
@param aTime The TTime value
sl@0
    53
@param aIsUtc is Etrue when aTime is UTC and EFalse when aTime is local time.
sl@0
    54
*/	
sl@0
    55
EXPORT_C TTsTime::TTsTime(const TTime& aTime, TBool aIsUtc)
sl@0
    56
	{
sl@0
    57
	// if the time passed as argument is UTC based
sl@0
    58
	if(aIsUtc)
sl@0
    59
		SetUtcTime(aTime);
sl@0
    60
		
sl@0
    61
	// if the time passed is local time	
sl@0
    62
	else
sl@0
    63
		SetLocalTime(aTime);
sl@0
    64
	}
sl@0
    65
	
sl@0
    66
/**
sl@0
    67
Sets this object to a local time based value updating its parameters as appropriate.
sl@0
    68
@param aLocalTime The local time to be set. 
sl@0
    69
*/
sl@0
    70
EXPORT_C void TTsTime::SetLocalTime(const TTime& aLocalTime)
sl@0
    71
	{
sl@0
    72
	iOffset = User::UTCOffset(); // sets the current UTC offset to iOffset
sl@0
    73
	iUtcTime = aLocalTime - iOffset; // converts the given aLocalTime to a UTC time value
sl@0
    74
	iFlags &= ~KIsUtc;    //set the Bit 0 to zero for Local Time
sl@0
    75
	}
sl@0
    76
		
sl@0
    77
/** 
sl@0
    78
Sets this object to a UTC time based value updating its parameters as appropriate.
sl@0
    79
@param aUtcTime The UTC time to be set
sl@0
    80
*/
sl@0
    81
EXPORT_C void TTsTime::SetUtcTime(const TTime& aUtcTime)
sl@0
    82
	{
sl@0
    83
	iUtcTime = aUtcTime; 
sl@0
    84
	iOffset = 0; 
sl@0
    85
	iFlags |= KIsUtc;    //set the Bit 0 to one as TTsTime is UTC
sl@0
    86
	}
sl@0
    87
		
sl@0
    88
/** 
sl@0
    89
This function returns a home time value.
sl@0
    90
@return Retrieves time from object in local time
sl@0
    91
*/
sl@0
    92
EXPORT_C const TTime TTsTime::GetLocalTime()
sl@0
    93
	{
sl@0
    94
	return DetermineLocalTime();
sl@0
    95
	}
sl@0
    96
	
sl@0
    97
/** 
sl@0
    98
This function returns a home time value.
sl@0
    99
@return Retrieves time from object in local time
sl@0
   100
*/
sl@0
   101
EXPORT_C TTime TTsTime::GetLocalTime() const
sl@0
   102
	{
sl@0
   103
	return DetermineLocalTime();
sl@0
   104
	}	
sl@0
   105
		
sl@0
   106
/**
sl@0
   107
This function returns a UTC value.
sl@0
   108
@return Returns the UTC time value.
sl@0
   109
*/ 
sl@0
   110
EXPORT_C const TTime& TTsTime::GetUtcTime()
sl@0
   111
	{
sl@0
   112
	return iUtcTime;
sl@0
   113
	}
sl@0
   114
	
sl@0
   115
/**
sl@0
   116
This function returns a UTC value.
sl@0
   117
@return Returns the UTC time value.
sl@0
   118
*/ 
sl@0
   119
EXPORT_C const TTime& TTsTime::GetUtcTime() const
sl@0
   120
	{
sl@0
   121
	return iUtcTime;
sl@0
   122
	}
sl@0
   123
	
sl@0
   124
/** 
sl@0
   125
@return ETrue, if TTsTime object is UTC and EFalse if TTsTime object is local time
sl@0
   126
*/
sl@0
   127
EXPORT_C TBool TTsTime::IsUtc() const
sl@0
   128
	{
sl@0
   129
	return iFlags & KIsUtc ? ETrue: EFalse;
sl@0
   130
	}
sl@0
   131
sl@0
   132
	
sl@0
   133
/**
sl@0
   134
This function returns a home time value.
sl@0
   135
If UTC based returns UTC time + User::UTCOffset(). If local time based returns
sl@0
   136
local time of the object.
sl@0
   137
@internalComponent
sl@0
   138
*/
sl@0
   139
TTime TTsTime::DetermineLocalTime() const
sl@0
   140
	{
sl@0
   141
	TTime localTime;
sl@0
   142
	if(IsUtc())
sl@0
   143
		localTime = iUtcTime+User::UTCOffset();
sl@0
   144
	else
sl@0
   145
		localTime = iUtcTime+iOffset;
sl@0
   146
	
sl@0
   147
	return localTime;
sl@0
   148
	}
sl@0
   149
	
sl@0
   150
/** 
sl@0
   151
This class does not explicitly update iOffSet if the system TimeZone/DST offset changes.
sl@0
   152
When called this API will update the object if the system TimeZone/DST offset has changed. 
sl@0
   153
Keeping the offset in objects of this class correct is the responsibility of the 
sl@0
   154
Task Scheduler server.This applies to local time objects only. UTC objects will be unaffected.
sl@0
   155
@internalComponent
sl@0
   156
*/	
sl@0
   157
void TTsTime::ProcessOffsetEvent() 
sl@0
   158
	{
sl@0
   159
	if(iFlags & KIsUtc)
sl@0
   160
		return;
sl@0
   161
			
sl@0
   162
	TTimeIntervalSeconds kernelOffset = User::UTCOffset();
sl@0
   163
	
sl@0
   164
	// check if there was an offset event happened without TTsTime being updated
sl@0
   165
	// localTime will always be the addition of UTC time and kernel offset
sl@0
   166
	if (iOffset != kernelOffset)
sl@0
   167
		{	
sl@0
   168
		// If TTsTime is home time and there was a time zone change then TTsTime needs to be update.
sl@0
   169
		// If not then TTsTime remains the same, as UTC times are the same everywhere.
sl@0
   170
		iUtcTime = (iUtcTime+iOffset) - kernelOffset; 
sl@0
   171
		iOffset = kernelOffset; 
sl@0
   172
		}
sl@0
   173
	}
sl@0
   174
/** 
sl@0
   175
Overloaded assignment operator for TTsTime
sl@0
   176
@param aTsTime time value to copy
sl@0
   177
*/
sl@0
   178
EXPORT_C TTsTime& TTsTime::operator=(const TTsTime& aTsTime)
sl@0
   179
	{
sl@0
   180
	Mem::Copy(this,&aTsTime,sizeof(*this));
sl@0
   181
	return *this;	
sl@0
   182
	}
sl@0
   183
	
sl@0
   184
/** 
sl@0
   185
Uses the standard template operator>>() to internalize the object from aStream.
sl@0
   186
Additionally this method will ensure that the object is updated in the event that 
sl@0
   187
the system TimeZone/DST offset changed since it was externalised.
sl@0
   188
@internalComponent
sl@0
   189
*/
sl@0
   190
void TTsTime::InternalizeL(RReadStream& aStream)  
sl@0
   191
	{
sl@0
   192
	TInt32 offset;
sl@0
   193
	TInt64 utcTime;
sl@0
   194
	
sl@0
   195
	// Updates TTsTime if local time based and the system Timezone/DST change occurred.
sl@0
   196
	ProcessOffsetEvent();
sl@0
   197
				
sl@0
   198
	aStream >> utcTime;
sl@0
   199
	iUtcTime = TTime(utcTime);
sl@0
   200
	aStream >> offset;
sl@0
   201
	iOffset = offset;
sl@0
   202
	aStream >> iFlags;	
sl@0
   203
	}
sl@0
   204
	
sl@0
   205
/** 
sl@0
   206
Uses the standard template operator>>() to externalize the object to aStream
sl@0
   207
@internalComponent
sl@0
   208
*/
sl@0
   209
void TTsTime::ExternalizeL(RWriteStream& aStream) const
sl@0
   210
	{
sl@0
   211
	aStream << iUtcTime.Int64();
sl@0
   212
	aStream.WriteInt32L(iOffset.Int());
sl@0
   213
	aStream.WriteUint32L(iFlags);
sl@0
   214
	}