devicediagnostics/devdiagapp/src/devdiagutil.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Utility classes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <eikenv.h>
       
    22 #include <bautils.h>
       
    23 #include <collate.h>
       
    24 #include <StringLoader.h>
       
    25 #include <avkon.rsg>
       
    26 
       
    27 
       
    28 #include "devdiagutil.h"
       
    29 
       
    30 
       
    31 
       
    32 /*****************************************************************************
       
    33  * class TDevDiagUtil
       
    34  *****************************************************************************/
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // ConvertUniversalToHomeTime
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 TTime TDevDiagUtil::ConvertUniversalToHomeTime( const TTime& aUniversalTime )
       
    44     {
       
    45     TTime time( aUniversalTime );   // time stores UTC time.
       
    46 
       
    47     TLocale locale;
       
    48     TTimeIntervalSeconds universalTimeOffset( locale.UniversalTimeOffset() );
       
    49     
       
    50     // Add locale's universal time offset to universal time.
       
    51     time += universalTimeOffset;    // time stores Local Time.
       
    52 
       
    53     // If home daylight saving in effect, add one hour offset.
       
    54     if ( locale.QueryHomeHasDaylightSavingOn() )
       
    55         {
       
    56         TTimeIntervalHours daylightSaving(1);
       
    57         time += daylightSaving;
       
    58         }
       
    59 
       
    60     return time;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // IsToDay
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TBool TDevDiagUtil::IsToday(TTime aTime)
       
    68 	{	
       
    69 	TTime now;
       
    70 	now.UniversalTime();
       
    71 	TInt day1 = now.DayNoInYear();
       
    72 	TInt day2 = aTime.DayNoInYear();
       
    73 	TTimeIntervalDays daysBetween = now.DaysFrom( aTime );
       
    74 	
       
    75 	if ( day1 != day2 )
       
    76 		{
       
    77 		return EFalse;
       
    78 		}
       
    79 		
       
    80 	if ( daysBetween.Int() > 0 )
       
    81 		{
       
    82 		return EFalse;
       
    83 		}
       
    84 
       
    85 	return ETrue; 
       
    86 	}
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // TDevDiagUtil::GetDateTextL (not done today)
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void TDevDiagUtil::GetDateTextL(TDes& aText, TTime aDateTime)
       
    94 	{
       
    95 	TTime homeTime = ConvertUniversalToHomeTime( aDateTime );
       
    96 	HBufC* hBuf = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
    97     homeTime.FormatL( aText, *hBuf );
       
    98     CleanupStack::PopAndDestroy( hBuf );
       
    99 	}
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // TDevDiagUtil::GetTimeTextL (done today)
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void TDevDiagUtil::GetTimeTextL( TDes& aText, TTime aDateTime )
       
   107 	{
       
   108 	TTime homeTime = ConvertUniversalToHomeTime( aDateTime );
       
   109 	HBufC* hBuf = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   110     homeTime.FormatL( aText, *hBuf );
       
   111     CleanupStack::PopAndDestroy( hBuf );
       
   112 	}
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // TDevDiagUtil::GetDateTimeTextL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void TDevDiagUtil::GetDateTimeTextL( TDes& aText, TTime aDateTime )
       
   120 	{
       
   121 	TDateTime dt = aDateTime.DateTime();
       
   122 	aText.Format(_L("%02d.%02d.%04d %02d:%02d:%02d"), dt.Day()+1,
       
   123 	                                                  dt.Month()+1,
       
   124 	                                                  dt.Year(),
       
   125 	                                                  dt.Hour(),
       
   126 	                                                  dt.Minute(),
       
   127 	                                                  dt.Second() );
       
   128 	}
       
   129 
       
   130