os/ossrv/genericservices/taskscheduler/Test/TSUtils/TSetUTCTime.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 <e32std.h>
sl@0
    17
#include <e32debug.h>
sl@0
    18
	
sl@0
    19
// This function is used to update month and day in aBufLocalTime
sl@0
    20
// to actual month and day to be passed to TTime() constructor.
sl@0
    21
// Remember using TTime::FormatL() in thelpers.cpp 
sl@0
    22
// has added extra month and a day to aBufLocalTime.
sl@0
    23
// aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM
sl@0
    24
// see TTime::Set() for aBufLocalTime expected format details.
sl@0
    25
TInt UpdateToActualMonthAndDay(TDes& aBufUTCTime)
sl@0
    26
	{	
sl@0
    27
	TInt mVal 	= 0;
sl@0
    28
	TInt dVal 	= 0;
sl@0
    29
	
sl@0
    30
	TBuf <4> tempBuf;
sl@0
    31
	_LIT(KFormat, "%02d");
sl@0
    32
	
sl@0
    33
	//Get the position of colon separator	
sl@0
    34
	TInt colon 	= aBufUTCTime.Locate(':');
sl@0
    35
		
sl@0
    36
	// Get Month & Day if Present	
sl@0
    37
	switch(colon)
sl@0
    38
		{
sl@0
    39
		case 0: break;
sl@0
    40
		case 8:
sl@0
    41
			{
sl@0
    42
			TLex month 	= aBufUTCTime.Mid(4,2);
sl@0
    43
			TLex day 	= aBufUTCTime.Mid(6,2);
sl@0
    44
			month.Val(mVal);
sl@0
    45
			day.Val(dVal);			
sl@0
    46
			}
sl@0
    47
			break;
sl@0
    48
		default:
sl@0
    49
			{
sl@0
    50
			// If the colon is at the wrong position
sl@0
    51
			return (KErrArgument);
sl@0
    52
			}
sl@0
    53
				
sl@0
    54
		}
sl@0
    55
		
sl@0
    56
		// Deduct extra month and a day and update aBufLocalTime
sl@0
    57
		if(mVal > 0 && dVal > 0)
sl@0
    58
			{
sl@0
    59
			mVal-=1;
sl@0
    60
			dVal-=1;
sl@0
    61
				
sl@0
    62
			tempBuf.Format(KFormat, mVal);
sl@0
    63
			aBufUTCTime.Replace(4,2, tempBuf);
sl@0
    64
				
sl@0
    65
			tempBuf.Format(KFormat, dVal);
sl@0
    66
			aBufUTCTime.Replace(6,2, tempBuf);				
sl@0
    67
			}
sl@0
    68
			
sl@0
    69
		return(KErrNone);		
sl@0
    70
	}
sl@0
    71
	
sl@0
    72
GLDEF_C TInt E32Main()
sl@0
    73
	{
sl@0
    74
	TInt err = KErrNone;	
sl@0
    75
	TBuf<64> bufUTCTime;
sl@0
    76
	
sl@0
    77
	User::CommandLine(bufUTCTime);	
sl@0
    78
	err = UpdateToActualMonthAndDay(bufUTCTime);
sl@0
    79
	
sl@0
    80
	if( err == KErrNone)
sl@0
    81
	{
sl@0
    82
		TTime utcTime(bufUTCTime);	
sl@0
    83
		err = User::SetUTCTime(utcTime);	
sl@0
    84
	}
sl@0
    85
		
sl@0
    86
	return err;
sl@0
    87
	}
sl@0
    88