os/kernelhwsrv/kernel/eka/euser/us_time.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/us_time.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2526 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\euser\us_time.cpp
    1.18 +// System date and time functions
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +
    1.23 +#include "us_std.h"
    1.24 +
    1.25 +// Date and time related constants
    1.26 +
    1.27 +static const TInt KMinutesToMicroSeconds = 60000000;
    1.28 +static const TInt KSecondsToMicroSeconds = 1000000;
    1.29 +static const TInt64 KDaysToMicroSeconds = I64LIT(86400000000);
    1.30 +static const TInt64 KHoursToMicroSeconds = I64LIT(3600000000);
    1.31 +
    1.32 +// Days in each month
    1.33 +LOCAL_D const TInt8 mTab[2][12]=
    1.34 +    {
    1.35 +    {31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb
    1.36 +    {31,29,31,30,31,30,31,31,30,31,30,31}  // 29 days in Feb
    1.37 +    };
    1.38 +
    1.39 +// Days in year before 1st of each month
    1.40 +LOCAL_D const TInt cmTab[2][12]=
    1.41 +	{
    1.42 +	{0,31,59,90,120,151,181,212,243,273,304,334},
    1.43 +	{0,31,60,91,121,152,182,213,244,274,305,335}
    1.44 +	};
    1.45 +
    1.46 +//
    1.47 +// Time::FormatL overflow handler
    1.48 +//
    1.49 +#if defined(_UNICODE)
    1.50 +NONSHARABLE_CLASS(TTimeOverflowLeave) : public TDes16Overflow
    1.51 +	{
    1.52 +public:
    1.53 +	virtual void Overflow(TDes16 &aDes);
    1.54 +	};
    1.55 +void TTimeOverflowLeave::Overflow(TDes16 &/*aDes*/)
    1.56 +	{
    1.57 +	User::Leave(KErrOverflow);
    1.58 +	}
    1.59 +#else
    1.60 +NONSHARABLE_CLASS(TTimeOverflowLeave) : public TDes8Overflow
    1.61 +	{
    1.62 +public:
    1.63 +	virtual void Overflow(TDes8 &aDes);
    1.64 +	};
    1.65 +void TTimeOverflowLeave::Overflow(TDes8 &/*aDes*/)
    1.66 +	{
    1.67 +	User::Leave(KErrOverflow);
    1.68 +	}
    1.69 +#endif
    1.70 +//
    1.71 +
    1.72 +EXPORT_C TDateTime::TDateTime(TInt aYear,TMonth aMonth,TInt aDay,TInt aHour,TInt aMinute,TInt aSecond,TInt aMicroSecond)
    1.73 +//
    1.74 +// always panic on a bad date/time field
    1.75 +//
    1.76 +/**
    1.77 +Constructs the TDateTime object with the seven fields which comprise a date 
    1.78 +and time.
    1.79 +
    1.80 +@param aYear        The year. No check is made for validity.
    1.81 +@param aMonth       The month. Range is EJanuary to EDecember.
    1.82 +@param aDay         The day. Range is zero to number of days in month minus one.
    1.83 +@param aHour        The hour. Range is 0 to 23.
    1.84 +@param aMinute      The minute. Range is 0 to 59.
    1.85 +@param aSecond      The second. Range is 0 to 59
    1.86 +@param aMicroSecond The microsecond. Range is 0 to 999999
    1.87 +
    1.88 +@panic USER 3, if an attempt is made to set an invalid value for any of 
    1.89 +       the fields, except for the year. No check is made upon the validity
    1.90 +       of the year.
    1.91 +*/
    1.92 +	{
    1.93 +
    1.94 +	TInt ret=Set(aYear,aMonth,aDay,aHour,aMinute,aSecond,aMicroSecond);
    1.95 +	__ASSERT_ALWAYS(ret==KErrNone,Panic(ETDateTimeBadDateTime));
    1.96 +	}
    1.97 +
    1.98 +EXPORT_C TInt TDateTime::Set(TInt aYear,TMonth aMonth,TInt aDay,TInt aHour,TInt aMinute,TInt aSecond,TInt aMicroSecond)
    1.99 +//
   1.100 +// set the various time fields checking that each is valid
   1.101 +// bomb out as soon as invalid field is set to forestall causing a panic
   1.102 +//
   1.103 +/**
   1.104 +Sets all date and time components.
   1.105 +
   1.106 +Note:
   1.107 +
   1.108 +1. When setting the day and month, subtract one because the ranges are offset 
   1.109 +   from zero. 
   1.110 +
   1.111 +2. If the function returns an error, only those fields preceding the field which 
   1.112 +   caused the error will be changed. For example, if the hour is out of range, 
   1.113 +   the year, month and day will be set, all other components will remain unchanged.
   1.114 +
   1.115 +@param aYear        Year. No check is made on its validity, except that if the
   1.116 +                    date is set to February 29th, the year can only be set to a
   1.117 +                    leap year, otherwise  an error is returned.
   1.118 +@param aMonth       Month. The valid range is EJanuary to EDecember. If an
   1.119 +                    attempt is made to set an invalid month, or if the current
   1.120 +                    day number in the month is greater than or equal to the
   1.121 +                    number of days in the new month, an error is returned.
   1.122 +@param aDay         The number of the day within the month, offset from zero.
   1.123 +                    If greater than or equal to the total number of days in
   1.124 +                    the month,an error is returned.
   1.125 +@param aHour        Hour. Range is 0 to 23.
   1.126 +@param aMinute      Minute. Range is 0 to 59.
   1.127 +@param aSecond      Second. Range is 0 to 59.
   1.128 +@param aMicroSecond Microsecond. Range is 0 to 999999.
   1.129 +
   1.130 +@return KErrNone if successful, KErrGeneral if not.
   1.131 +*/
   1.132 +	{
   1.133 +
   1.134 +	iYear=aYear;
   1.135 +
   1.136 +	if (aMonth<EJanuary || aMonth>EDecember)
   1.137 +		return KErrGeneral;
   1.138 +	iMonth=aMonth;
   1.139 +
   1.140 +	if (aDay<0 || aDay>=Time::DaysInMonth(iYear,iMonth))
   1.141 +		return KErrGeneral;
   1.142 +	iDay=aDay;
   1.143 +
   1.144 +	if (aHour<0 || aHour>=24)
   1.145 +		return KErrGeneral;
   1.146 +	iHour=aHour;
   1.147 +
   1.148 +	if (aMinute<0 || aMinute>=60)
   1.149 +		return KErrGeneral;
   1.150 +	iMinute=aMinute;
   1.151 +
   1.152 +	if (aSecond<0 || aSecond>=60)
   1.153 +		return KErrGeneral;
   1.154 +	iSecond=aSecond;
   1.155 +
   1.156 +	if (aMicroSecond<0 || aMicroSecond>=1000000)
   1.157 +		return KErrGeneral;
   1.158 +	iMicroSecond=aMicroSecond;
   1.159 +
   1.160 +	return KErrNone;
   1.161 +	}
   1.162 +
   1.163 +EXPORT_C TInt TDateTime::SetYear(TInt aYear)
   1.164 +//
   1.165 +// doesnt let you reset 29th February to non-leap year, no check on year range
   1.166 +//
   1.167 +/**
   1.168 +Sets the year without a leap year check.
   1.169 +
   1.170 +No check is made on the validity of the year except that if the current date
   1.171 +is February 29th, the year can only be changed to another leap year, otherwise
   1.172 +an error is returned.
   1.173 +
   1.174 +@param aYear The year.
   1.175 +
   1.176 +@return KErrNone if successful, KErrGeneral if not.
   1.177 +*/
   1.178 +	{
   1.179 +
   1.180 +	if (iDay>=Time::DaysInMonth(aYear,iMonth))
   1.181 +		return KErrGeneral;
   1.182 +	iYear=aYear;
   1.183 +	return KErrNone;
   1.184 +	}
   1.185 +
   1.186 +EXPORT_C TInt TDateTime::SetYearLeapCheck(TInt aYear)
   1.187 +//
   1.188 +// lets you reset 29th February to non-leap year(moves date to 28th/Feb), no check on year range
   1.189 +//
   1.190 +/**
   1.191 +Sets the year with a leap year check.
   1.192 +
   1.193 +Unlike SetYear(), if the date is the 29th February, this function allows
   1.194 +the year to be set to a non-leap year. In this case, the date is reset to
   1.195 +the 28th February.
   1.196 +
   1.197 +@param aYear The year.
   1.198 +
   1.199 +@return KErrNone if successful, KErrGeneral if not.
   1.200 +
   1.201 +@see TDateTime::SetYear
   1.202 +*/
   1.203 +	{
   1.204 +
   1.205 +	if (iDay>=Time::DaysInMonth(aYear,iMonth))
   1.206 +        iDay=27;
   1.207 +    iYear=aYear;
   1.208 +	return KErrNone;
   1.209 +	}
   1.210 +
   1.211 +EXPORT_C TInt TDateTime::SetMonth(TMonth aMonth)
   1.212 +/**
   1.213 +Sets the month component of the date/time.
   1.214 +
   1.215 +@param aMonth The month to be set. The range is from EJanuary to EDecember.
   1.216 +              If an attempt is made to set an invalid month, or if the current
   1.217 +              day number in the month is greater than or equal to the number of
   1.218 +              days in the new month, an error is returned.
   1.219 +              
   1.220 +@return KErrNone if successful, KErrGeneral if not.
   1.221 +*/
   1.222 +	{
   1.223 +
   1.224 +	if (aMonth<EJanuary || aMonth>EDecember || iDay>=Time::DaysInMonth(iYear,aMonth))
   1.225 +		return KErrGeneral;
   1.226 +	iMonth=aMonth;
   1.227 +	return KErrNone;
   1.228 +	}
   1.229 +
   1.230 +EXPORT_C TInt TDateTime::SetDay(TInt aDay)
   1.231 +/**
   1.232 +Sets the day component of the date/time.
   1.233 +
   1.234 +@param aDay The number of the day within the month, offset from zero. If equal 
   1.235 +            to or greater than the total number of days in the month, an error
   1.236 +            is returned.
   1.237 +            
   1.238 +@return KErrNone if successful, KErrGeneral if not.
   1.239 +*/
   1.240 +	{
   1.241 +
   1.242 +	if (aDay<0 || aDay>=Time::DaysInMonth(iYear,iMonth))
   1.243 +		return KErrGeneral;
   1.244 +	iDay=aDay;
   1.245 +	return KErrNone;
   1.246 +	}
   1.247 +
   1.248 +EXPORT_C TInt TDateTime::SetHour(TInt aHour)
   1.249 +/**
   1.250 +Sets the hour component of the date/time.
   1.251 +
   1.252 +@param aHour The hour. Range is 0 to 23.
   1.253 +
   1.254 +@return KErrNone if successful, KErrGeneral if not.
   1.255 +*/
   1.256 +	{
   1.257 +
   1.258 +	if (aHour<0 || aHour>=24) // GC - bug fix
   1.259 +		return KErrGeneral;
   1.260 +	iHour=aHour;
   1.261 +	return KErrNone;
   1.262 +	}
   1.263 +
   1.264 +EXPORT_C TInt TDateTime::SetMinute(TInt aMinute)
   1.265 +/**
   1.266 +Sets the minute component of the date/time.
   1.267 +
   1.268 +@param aMinute The minute. Range is 0 to 59.
   1.269 +
   1.270 +@return KErrNone if successful, KErrGeneral if not.
   1.271 +*/
   1.272 +	{
   1.273 +
   1.274 +	if (aMinute<0 || aMinute>=60)
   1.275 +		return KErrGeneral;
   1.276 +	iMinute=aMinute;
   1.277 +	return KErrNone;
   1.278 +	}
   1.279 +
   1.280 +EXPORT_C TInt TDateTime::SetSecond(TInt aSecond)
   1.281 +/**
   1.282 +Sets the second component of the date/time.
   1.283 +
   1.284 +@param aSecond The second. Range is 0 to 59.
   1.285 +
   1.286 +@return KErrNone if successful, KErrGeneral if not.
   1.287 +*/
   1.288 +	{
   1.289 +
   1.290 +	if (aSecond<0 || aSecond>=60)
   1.291 +		return KErrGeneral;
   1.292 +	iSecond=aSecond;
   1.293 +	return KErrNone;
   1.294 +	}
   1.295 +
   1.296 +EXPORT_C TInt TDateTime::SetMicroSecond(TInt aMicroSecond)
   1.297 +/**
   1.298 +Sets the microsecond component of the date/time.
   1.299 +
   1.300 +@param aMicroSecond The microsecond. Range is 0 to 999999.
   1.301 +
   1.302 +@return KErrNone if successful, KErrGeneral if not.
   1.303 +*/
   1.304 +	{
   1.305 +
   1.306 +	if (aMicroSecond<0 || aMicroSecond>=1000000)
   1.307 +		return KErrGeneral;
   1.308 +	iMicroSecond=aMicroSecond;
   1.309 +	return KErrNone;
   1.310 +	}
   1.311 +
   1.312 +// class TTime
   1.313 +
   1.314 +EXPORT_C TTime::TTime(const TDesC &aString)
   1.315 +/**
   1.316 +Constructs a TTime object with a text string.
   1.317 +
   1.318 +The string consists of up to three components, any or all of which
   1.319 +may be omitted:
   1.320 +
   1.321 +1. year, month and day, followed by a colon
   1.322 +
   1.323 +2. hour, minute and second, followed by a dot
   1.324 +
   1.325 +3. microsecond
   1.326 +
   1.327 +When all three components are present, the string should take the form:
   1.328 +
   1.329 +YYYYMMDD:HHMMSS.MMMMMM
   1.330 +
   1.331 +The conversion from text to time is carried out in the same manner as that 
   1.332 +used in TTime::Set().
   1.333 +
   1.334 +For a list of the range of valid values for date and time components,
   1.335 +see TDateTime::Set().
   1.336 +
   1.337 +@param aString Date and time string for initializing the TTime object. 
   1.338 +
   1.339 +@panic USER 113, if the string is syntactically incorrect, for example, if 
   1.340 +                 neither a colon nor a dot is present, or if any component of
   1.341 +                 the date or time is assigned an invalid value, or the year
   1.342 +                 is negative.
   1.343 +
   1.344 +@see TTime::Set
   1.345 +@see TDateTime::Set
   1.346 +*/
   1.347 +	{
   1.348 +
   1.349 +	__ASSERT_ALWAYS(Set(aString)==KErrNone,Panic(ETTimeValueOutOfRange));
   1.350 +	}
   1.351 +
   1.352 +EXPORT_C TTime::TTime(const TDateTime &aDateTime) : iTime(Convert(aDateTime).Int64())
   1.353 +/**
   1.354 +Constructs a TTime object with the seven fields which comprise a date and time.
   1.355 +
   1.356 +@param aDateTime Date and time to which to initialise the TTime object.
   1.357 +*/
   1.358 +
   1.359 +    {}
   1.360 +
   1.361 +EXPORT_C TInt TTime::Set(const TDesC &aString)
   1.362 +//
   1.363 +// Convert string to time. String is in the format:
   1.364 +//
   1.365 +// YYYYMMDD:HHMMSS.MMMMMM
   1.366 +//
   1.367 +// Any part may be ommitted, but either the
   1.368 +// dot or colon or both must be present
   1.369 +//
   1.370 +/**
   1.371 +Assigns a date and time contained in a descriptor to this TTime object.
   1.372 +
   1.373 +The string consists of up to three components, any or all of which may
   1.374 +be omitted:
   1.375 +
   1.376 +1. year, month and day, followed by a colon 
   1.377 +
   1.378 +2. hour, minute and second, followed by a dot 
   1.379 +
   1.380 +3. microsecond
   1.381 +
   1.382 +When all three components are present, the string should take the form:
   1.383 +
   1.384 +YYYYMMDD:HHMMSS.MMMMMM
   1.385 +
   1.386 +If omitted, the first component is set to January 1st 0 AD nominal Gregorian. 
   1.387 +If either the second or third components are omitted, they are set to zero.
   1.388 +
   1.389 +Notes:
   1.390 +
   1.391 +1. The month and day values are offset from zero.
   1.392 +
   1.393 +2. The only situations in which either the colon or dot may be omitted are as 
   1.394 +   follows:
   1.395 +   
   1.396 +   2.1 If the microsecond component is omitted, the preceding dot may also
   1.397 +       be omitted.
   1.398 +
   1.399 +   2.2 The colon can be omitted only if a dot is located at string position
   1.400 +       zero (indicating that the first two components are missing), or at
   1.401 +       string position six (indicating that the first component only is
   1.402 +       missing).
   1.403 +
   1.404 +@param aString The date and time to be assigned to this TTime object.
   1.405 +       
   1.406 +@return KErrNone if successful,
   1.407 +        KErrGeneral if the string is syntactically incorrect, for example,
   1.408 +        if neither a colon nor a dot is present, or if any component of the
   1.409 +        date or time is given an invalid value, or the year is negative.
   1.410 +        For a list of valid values for date and time components,
   1.411 +        see TDateTime::Set().
   1.412 +        If an error occurs, the date and time will remain unchanged.
   1.413 +*/
   1.414 +	{
   1.415 +
   1.416 +//
   1.417 +// Get position of the colon and dot separators
   1.418 +//
   1.419 +    TInt colon=aString.Locate(':');
   1.420 +    TInt dot=aString.Locate('.');
   1.421 +
   1.422 +    if(colon==KErrNotFound && dot==KErrNotFound)
   1.423 +        return(KErrGeneral);
   1.424 +//
   1.425 +// Zero parts that aren't supplied
   1.426 +//
   1.427 +    TInt yy=0;
   1.428 +    TInt mm=0;
   1.429 +    TInt dd=0;
   1.430 +    TInt hr=0;
   1.431 +    TInt mi=0;
   1.432 +    TInt se=0;
   1.433 +    TInt ms=0;
   1.434 +//
   1.435 +// Convert YYYYMMDD if present
   1.436 +//
   1.437 +    switch(colon)
   1.438 +        {
   1.439 +        case 0:
   1.440 +       	    break;
   1.441 +        case KErrNotFound:
   1.442 +            if(dot!=0 && dot!=6)
   1.443 +                return(KErrGeneral);
   1.444 +            colon=-1;
   1.445 +            break;
   1.446 +        case 8:
   1.447 +	   		{
   1.448 +            TLex y=aString.Left(4);
   1.449 +            TLex m=aString.Mid(4,2);
   1.450 +            TLex d=aString.Mid(6,2);
   1.451 +            y.Val(yy);
   1.452 +            m.Val(mm);
   1.453 +            d.Val(dd);
   1.454 +	    	}
   1.455 +            break;
   1.456 +        default: // Colon in wrong position - return error
   1.457 +            return(KErrGeneral);
   1.458 +        }
   1.459 +//
   1.460 +// Convert HHMMSS if present
   1.461 +//
   1.462 +    if(dot==KErrNotFound)
   1.463 +        dot=aString.Length();
   1.464 +     
   1.465 +    if(dot==colon+7)
   1.466 +        {
   1.467 +        TLex h=aString.Mid(dot-6,2);
   1.468 +        TLex m=aString.Mid(dot-4,2);
   1.469 +        TLex s=aString.Mid(dot-2,2);
   1.470 +        h.Val(hr);
   1.471 +        m.Val(mi);
   1.472 +        s.Val(se);
   1.473 +        }
   1.474 +    else if(dot!=KErrNotFound && dot!=0 && dot!=colon+1)
   1.475 +    	return(KErrGeneral);
   1.476 +
   1.477 +    if(dot!=KErrNotFound)
   1.478 +        {
   1.479 +        if(aString.Length()>dot+7)
   1.480 +            return(KErrGeneral); // microseconds is more than 6 digits
   1.481 +        if(dot<aString.Length())
   1.482 +        	{
   1.483 +        	TLex m=aString.Mid(dot+1);
   1.484 +        	m.Val(ms);
   1.485 +        	}
   1.486 +        }
   1.487 +        
   1.488 +//
   1.489 +// Set the time! Do not construct newtime using the values or
   1.490 +// it may cause TTime::Set() to panic rather than return an error
   1.491 +//
   1.492 +	TDateTime newtime;
   1.493 +	if(newtime.Set(yy,TMonth(mm),dd,hr,mi,se,ms)!=KErrNone)
   1.494 +		return(KErrGeneral);
   1.495 +    (*this)=newtime;
   1.496 +	return KErrNone;
   1.497 +	}
   1.498 +
   1.499 +EXPORT_C TInt TTime::HomeTimeSecure()
   1.500 +/**
   1.501 +Sets the date and time of this TTime to the secure home time. 
   1.502 +Returns KErrNoSecureTime if there is no secure time source
   1.503 +*/
   1.504 +	{
   1.505 +	TInt utOffset=0;
   1.506 +	TInt r = Exec::TimeNowSecure(*(TInt64*)this,utOffset);
   1.507 +    operator+=(TTimeIntervalSeconds(utOffset));
   1.508 +	return r;
   1.509 +	}
   1.510 +
   1.511 +EXPORT_C TInt TTime::UniversalTimeSecure()
   1.512 +/**
   1.513 +Sets the date and time of this TTime to the secure universal time.
   1.514 +*/
   1.515 +	{
   1.516 +	TInt utOffset=0;
   1.517 +	return Exec::TimeNowSecure(*(TInt64*)this,utOffset);
   1.518 +	}
   1.519 +
   1.520 +EXPORT_C void TTime::HomeTime()
   1.521 +/**
   1.522 +Sets the date and time of this TTime to the home time.
   1.523 +*/
   1.524 +	{
   1.525 +	TInt utOffset=0;
   1.526 +	Exec::TimeNow(*(TInt64*)this,utOffset);
   1.527 +    operator+=(TTimeIntervalSeconds(utOffset));
   1.528 +	}
   1.529 +
   1.530 +EXPORT_C void TTime::UniversalTime()
   1.531 +/**
   1.532 +Sets the date and time of this TTime to the universal time.
   1.533 +*/
   1.534 +	{
   1.535 +	TInt utOffset=0;
   1.536 +	Exec::TimeNow(*(TInt64*)this,utOffset);
   1.537 +	}
   1.538 +
   1.539 +EXPORT_C void TTime::RoundUpToNextMinute()
   1.540 +/**
   1.541 +Rounds this TTime up to the next minute.
   1.542 +
   1.543 +Both the seconds and microseconds components are set to zero.
   1.544 +*/
   1.545 +	{
   1.546 +
   1.547 +	if (iTime>0)
   1.548 +		iTime+=59999999;
   1.549 +//*	TInt64 remainder;
   1.550 +//*	Int64().DivMod(60000000,remainder);
   1.551 +//*	iTime-=remainder;	
   1.552 +	iTime-=iTime%60000000;
   1.553 +	}
   1.554 +
   1.555 +TTime TTime::Convert(const TDateTime &aDateTime)
   1.556 +//
   1.557 +// converts TDateTime into a TTime, doesnt check for overflows
   1.558 +//
   1.559 +	{
   1.560 +	
   1.561 +	TInt days=365*aDateTime.Year()+Time::LeapYearsUpTo(aDateTime.Year());
   1.562 +	TBool isleap=Time::IsLeapYear(aDateTime.Year());
   1.563 +	days+=cmTab[isleap][aDateTime.Month()];
   1.564 +	days+=aDateTime.Day();
   1.565 +
   1.566 +	TUint sum=aDateTime.MicroSecond()+aDateTime.Second()*KSecondsToMicroSeconds+aDateTime.Minute()*KMinutesToMicroSeconds;
   1.567 +	return(((TInt64(days*3)<<3)+TInt64(aDateTime.Hour()))*KHoursToMicroSeconds+TInt64(sum));
   1.568 +	}
   1.569 +
   1.570 +EXPORT_C TTime &TTime::operator=(const TDateTime &aDateTime)
   1.571 +/**
   1.572 +Assigns a TDateTime object to this TTime object.
   1.573 +
   1.574 +@param aDateTime The date and time to assign to this TTime object.
   1.575 +
   1.576 +@return This TTime object.
   1.577 +*/
   1.578 +	{
   1.579 +
   1.580 +	iTime=Convert(aDateTime).Int64();
   1.581 +	return(*this);
   1.582 +	}
   1.583 +
   1.584 +EXPORT_C TDateTime TTime::DateTime() const
   1.585 +//
   1.586 +// converts iTime back into its TDateTime components
   1.587 +//
   1.588 +/**
   1.589 +Converts the TTime object into a TDateTime object.
   1.590 +
   1.591 +This conversion must be done before the seven fields which comprise a date
   1.592 +and time can be accessed.
   1.593 +
   1.594 +@return The components of the time, indicating year, month, day, hour, minute, 
   1.595 +        second, microsecond.
   1.596 +*/
   1.597 +	{
   1.598 +
   1.599 +	TInt64 rem;
   1.600 +	TInt64 daysSince0AD64(iTime);
   1.601 +	
   1.602 +	rem = daysSince0AD64 % KDaysToMicroSeconds;
   1.603 +	daysSince0AD64 /= KDaysToMicroSeconds;
   1.604 +
   1.605 +	TInt daysSince0AD = static_cast<TInt>(daysSince0AD64);
   1.606 +
   1.607 +	TInt year;
   1.608 +	TInt daysLeft;
   1.609 +	if (iTime<0)
   1.610 +		{ // -1 to make daysLeft +ve and assume leap year every 4 years
   1.611 +		if (rem!=TInt64(0))
   1.612 +			{
   1.613 +			daysSince0AD--;
   1.614 +			rem=iTime-TInt64(daysSince0AD)*KDaysToMicroSeconds;
   1.615 +			}
   1.616 +		year=(4*daysSince0AD)/((4*365)+1);
   1.617 +		if ((4*daysSince0AD)%((4*365)+1))
   1.618 +			year--;
   1.619 +		daysLeft=daysSince0AD-((year*365)+Time::LeapYearsUpTo(year));
   1.620 +		}
   1.621 +	else
   1.622 +		{ // after 1600 leap years less than every four years
   1.623 +		year=(4*daysSince0AD)/((4*365)+1);
   1.624 +		daysLeft=daysSince0AD-((year*365)+Time::LeapYearsUpTo(year));
   1.625 +		TInt daysInYear=365+Time::IsLeapYear(year);
   1.626 +	    while (daysLeft>=daysInYear)
   1.627 +		    {
   1.628 +			year++;
   1.629 +	        daysLeft-=daysInYear;
   1.630 +			daysInYear=365+Time::IsLeapYear(year);
   1.631 +			}
   1.632 +		}
   1.633 +
   1.634 +	TDateTime result(0,EJanuary,0,0,0,0,0);
   1.635 +	result.SetYear(year);
   1.636 +
   1.637 +   	TBool isleap=Time::IsLeapYear(year);
   1.638 +    TInt month=11;
   1.639 +	const TInt* pCM=&(cmTab[isleap][11])+1;
   1.640 +	while(daysLeft<*--pCM)
   1.641 +		month--;
   1.642 +	daysLeft-=*pCM;
   1.643 +
   1.644 +	result.SetMonth((TMonth)month);
   1.645 +	result.SetDay(daysLeft);
   1.646 +
   1.647 +	TInt hour = static_cast<TInt>(rem >> 10) / 3515625;	// 3515625=KHoursToMicroSeconds/1024
   1.648 +	result.SetHour(hour);
   1.649 +	TUint rem32=I64LOW(rem-(TInt64(hour*3515625)<<10));
   1.650 +	TUint min=rem32/KMinutesToMicroSeconds;
   1.651 +	result.SetMinute((TInt)min);
   1.652 +	rem32-=min*KMinutesToMicroSeconds;
   1.653 +	TUint sec=rem32/KSecondsToMicroSeconds;
   1.654 +	result.SetSecond((TInt)sec);
   1.655 +	rem32-=sec*KSecondsToMicroSeconds;
   1.656 +	result.SetMicroSecond(TInt(rem32));
   1.657 +	return(result);
   1.658 +	}
   1.659 +
   1.660 +EXPORT_C TTimeIntervalMicroSeconds TTime::MicroSecondsFrom(TTime aTime) const
   1.661 +//
   1.662 +// this - aTime
   1.663 +//
   1.664 +/**
   1.665 +Calculates the number of microseconds difference between the specified TTime
   1.666 +and this TTime.
   1.667 +
   1.668 +@param aTime The time to be compared with this TTime.
   1.669 +
   1.670 +@return Difference in microseconds between the two times. If the time specified 
   1.671 +        in the argument is later than this TTime, this value is negative.
   1.672 +*/
   1.673 +	{
   1.674 +
   1.675 +	TInt64 difference=iTime-aTime.Int64();
   1.676 +	return(difference);
   1.677 +	}
   1.678 +
   1.679 +EXPORT_C TInt TTime::SecondsFrom(TTime aTime,TTimeIntervalSeconds &aInterval) const
   1.680 +//
   1.681 +// this - aTime as whole seconds
   1.682 +// this function may fail if difference > no of seconds that can be represented in a TInt
   1.683 +//
   1.684 +/**
   1.685 +Calculates the number of seconds difference between the specified TTime and
   1.686 +this TTime.
   1.687 +
   1.688 +The difference may be positive or negative.
   1.689 +
   1.690 +@param aTime     The time to be compared with this TTime.
   1.691 +@param aInterval On return contains the difference in seconds between the two 
   1.692 +                 times. If the time specified in the first argument is later than
   1.693 +                 this TTime, then this returned value is negative.
   1.694 +                 
   1.695 +@return Error code. KErrNone if successful. 
   1.696 +                    KErrOverflow, if the calculated interval is too large for
   1.697 +                    a 32-bit integer.
   1.698 +*/
   1.699 +	{
   1.700 +	TInt64 diff;
   1.701 +	if (iTime>aTime.Int64())
   1.702 +		{
   1.703 +		diff= TInt64(TUint64(iTime-aTime.Int64())/KSecondsToMicroSeconds);	
   1.704 +		}
   1.705 +	else 
   1.706 +		{
   1.707 +		diff= -TInt64(TUint64(aTime.Int64()-iTime)/KSecondsToMicroSeconds);
   1.708 +		}	
   1.709 +	if (diff>KMaxTInt || diff<KMinTInt)	
   1.710 +	    return KErrOverflow; 
   1.711 +	aInterval = static_cast<TInt>(diff);
   1.712 +	return KErrNone;
   1.713 +	}
   1.714 +	
   1.715 +EXPORT_C TInt TTime::MinutesFrom(TTime aTime,TTimeIntervalMinutes &aInterval) const
   1.716 +//
   1.717 +// iTime - aTime as whole minutes
   1.718 +// function may fail if difference can't be represented as a TInt
   1.719 +//
   1.720 +/**
   1.721 +Calculates the number of minutes difference between the specified TTime and
   1.722 +this TTime.
   1.723 +
   1.724 +The difference may be positive or negative.
   1.725 +
   1.726 +@param aTime     The time to be compared with this TTime.
   1.727 +@param aInterval On return contains the difference in minutes between the two 
   1.728 +                 times. If the time specified in the first argument is later
   1.729 +                 than this TTime, then this returned value is negative.
   1.730 +                 
   1.731 +@return Error code. KErrNone if successful. 
   1.732 +                    KErrOverflow, if the calculated interval is too large for
   1.733 +                    a 32-bit integer.
   1.734 +*/
   1.735 +	{
   1.736 +	TInt64 diff;
   1.737 +	if (iTime>aTime.Int64())
   1.738 +		{
   1.739 +		diff= TInt64(TUint64(iTime-aTime.Int64())/KMinutesToMicroSeconds);	
   1.740 +		}
   1.741 +	else 
   1.742 +		{
   1.743 +		diff= -TInt64(TUint64(aTime.Int64()-iTime)/KMinutesToMicroSeconds);
   1.744 +		}	
   1.745 +	if (diff>KMaxTInt || diff<KMinTInt)	
   1.746 +	    return KErrOverflow; 
   1.747 +	aInterval = static_cast<TInt>(diff);
   1.748 +	return KErrNone; 
   1.749 +	}
   1.750 +
   1.751 +EXPORT_C TInt TTime::HoursFrom(TTime aTime,TTimeIntervalHours &aInterval) const
   1.752 +//
   1.753 +// iTime - aTime as whole hours
   1.754 +// function may fail if difference can't be represented as a TInt
   1.755 +//
   1.756 +/**
   1.757 +Calculates the number of hours difference between the specified TTime and
   1.758 +this TTime. 
   1.759 +
   1.760 +The difference may be positive or negative.
   1.761 +
   1.762 +@param aTime     The time to be compared with this TTime.
   1.763 +@param aInterval On return contains the difference in hours between the two 
   1.764 +                 times. If the time specified in the first argument is later
   1.765 +                 than this TTime, then this returned value is negative.
   1.766 +                 
   1.767 +@return Error code. KErrNone if successful. 
   1.768 +                    KErrOverflow, if the calculated interval is too large for
   1.769 +                    a 32-bit integer.
   1.770 +*/
   1.771 +	{
   1.772 +	TInt64 diff;
   1.773 +	if (iTime>aTime.Int64())
   1.774 +		{
   1.775 +		diff= TInt64(TUint64(iTime-aTime.Int64())/KHoursToMicroSeconds);	
   1.776 +		}
   1.777 +	else 
   1.778 +		{
   1.779 +		diff= -TInt64(TUint64(aTime.Int64()-iTime)/KHoursToMicroSeconds);
   1.780 +		}
   1.781 +	if (diff>KMaxTInt || diff<KMinTInt)	
   1.782 +	    return KErrOverflow; 
   1.783 +	aInterval = static_cast<TInt>(diff);
   1.784 +	return KErrNone;
   1.785 +	}  
   1.786 +
   1.787 +
   1.788 +EXPORT_C TTimeIntervalDays TTime::DaysFrom(TTime aTime) const
   1.789 +//
   1.790 +// iTime - aTime as whole days
   1.791 +//
   1.792 +/**
   1.793 +Calculates the number of days difference between the specified TTime and
   1.794 +this TTime. 
   1.795 +
   1.796 +The difference may be positive or negative.
   1.797 +
   1.798 +@param aTime  The time to be compared with this TTime.
   1.799 +
   1.800 +@return Difference in days between the two times. If the time specified in 
   1.801 +        aTime is later than this TTime, the returned value will be negative.
   1.802 +*/
   1.803 +	{
   1.804 +	if (iTime>aTime.Int64())
   1.805 +		{
   1.806 +		return TInt(TUint64(iTime-aTime.Int64())/KDaysToMicroSeconds);	
   1.807 +		}
   1.808 +	else 
   1.809 +		{
   1.810 +		return -TInt(TUint64(aTime.Int64()-iTime)/KDaysToMicroSeconds);
   1.811 +		}	
   1.812 +	}
   1.813 +
   1.814 +EXPORT_C TTimeIntervalMonths TTime::MonthsFrom(TTime aTime) const
   1.815 +//
   1.816 +// iTime - aTime as whole months - ie aTime must be on a later day in the month and later in that day
   1.817 +// except for last days etc eg 31st October - 30 November is one month to be consistent with other
   1.818 +// functions
   1.819 +//
   1.820 +/**
   1.821 +Calculates the number of months between the specified TTime and this TTime.
   1.822 +
   1.823 +The result may be positive or negative.
   1.824 +
   1.825 +The interval in months between two TTimes is calculated by incrementing it 
   1.826 +by one each time the same day number and time in the previous or following 
   1.827 +month has been reached. Exceptions to this rule occur when this TTime is on 
   1.828 +the last day of the month. In this case, the following rules apply:
   1.829 +
   1.830 +When comparing this TTime with a later time:
   1.831 +
   1.832 +1. if the following month is shorter, one month is deemed to separate the times 
   1.833 +   when the same time on the last day of the following month is reached. In this 
   1.834 +   case, the two day numbers are not the same.
   1.835 +
   1.836 +When comparing this TTime with an earlier time:
   1.837 +
   1.838 +1. if the previous month is shorter, one month is deemed to separate the times 
   1.839 +   when the last microsecond of the previous month is reached (23:59:59.999999 
   1.840 +   on the last day of the month).
   1.841 +
   1.842 +2. if the previous month is longer, one month is deemed to separate the times 
   1.843 +   when the same time on the last day of previous month is reached. In this case, 
   1.844 +   the two day numbers are not the same.
   1.845 +
   1.846 +@param aTime The time to be compared with this TTime.
   1.847 +
   1.848 +@return Difference in months between the two times. If the time specified in 
   1.849 +        the argument is later than this TTime, the interval is negative.
   1.850 +*/
   1.851 +	{
   1.852 +
   1.853 +	TDateTime dateTimei=DateTime();
   1.854 +	TDateTime dateTimea=aTime.DateTime();
   1.855 +	
   1.856 +	TInt monthsDifference=(dateTimei.Year()-dateTimea.Year())*12+(dateTimei.Month()-dateTimea.Month());
   1.857 +
   1.858 +	if (monthsDifference>0)
   1.859 +		{
   1.860 +		if (dateTimei.Day()<=dateTimea.Day())
   1.861 +			{
   1.862 +			if (iTime%KDaysToMicroSeconds<aTime.Int64()%KDaysToMicroSeconds || (dateTimei.Day()!=dateTimea.Day() && dateTimei.Day()!=DaysInMonth()-1))
   1.863 +				monthsDifference--;
   1.864 +			}
   1.865 +		}
   1.866 +	else
   1.867 +		if (monthsDifference!=0)//monthsDifference<0
   1.868 +			{
   1.869 +			if (dateTimei.Day()>=dateTimea.Day())
   1.870 +				{
   1.871 +				if (iTime%KDaysToMicroSeconds>aTime.Int64()%KDaysToMicroSeconds || (dateTimei.Day()!=dateTimea.Day() && dateTimea.Day()!=aTime.DaysInMonth()-1))
   1.872 +					monthsDifference++;
   1.873 +				}
   1.874 +			}
   1.875 +
   1.876 +	return(monthsDifference);			
   1.877 +	}
   1.878 +
   1.879 +EXPORT_C TTimeIntervalYears TTime::YearsFrom(TTime aTime) const
   1.880 +//
   1.881 +// as above,but for twelve months
   1.882 +//
   1.883 +/**
   1.884 +Calculates the number of years between the specified TTime and this TTime.
   1.885 +
   1.886 +The result may be positive or negative.
   1.887 +
   1.888 +Note that the interval in years between two TTimes is calculated by
   1.889 +incrementing it by one each time the same day number and time in the previous
   1.890 +or following year has been reached. The exception to this rule occurs when this
   1.891 +TTime is the last day in February in a leap year. In this case, one year is
   1.892 +deemed to have passed when the same time of day on the last day in the preceding 
   1.893 +or following February has been reached.
   1.894 +
   1.895 +@param aTime The time to be compared with this TTime.
   1.896 +
   1.897 +@return Difference in years between the two times. If the time specified in 
   1.898 +        the argument is later than this TTime, the interval is negative.
   1.899 +*/
   1.900 +	{
   1.901 +
   1.902 +	TTimeIntervalMonths mos= TTime::MonthsFrom(aTime);
   1.903 +	TTimeIntervalYears ret=mos.Int()/12;
   1.904 +	return(ret);			
   1.905 +	}
   1.906 +
   1.907 +EXPORT_C TTime TTime::operator+(TTimeIntervalYears aYear) const
   1.908 +/**
   1.909 +Adds a time interval to this TTime, returning the result
   1.910 +as a TTime.
   1.911 +
   1.912 +Note that in a leap year, when adding one year to the 29th February, the result
   1.913 +is the 28th February in the following year.
   1.914 +
   1.915 +Note also that this TTime object is not changed.
   1.916 +
   1.917 +@param aYear A time interval in years. The argument is stored as a 32 bit
   1.918 +             signed integer. The maximum value which it can represent is
   1.919 +             2147483647. Any attempt to add more than this amount will
   1.920 +             produce incorrect results.
   1.921 +
   1.922 +@return The new time.
   1.923 +*/
   1.924 +	{
   1.925 +
   1.926 +	return((*this)+TTimeIntervalMonths(aYear.Int()*12));
   1.927 +	}
   1.928 +
   1.929 +EXPORT_C TTime TTime::operator+(TTimeIntervalMonths aMonth) const
   1.930 +/**
   1.931 +Adds a time interval to this TTime, returning the result
   1.932 +as a TTime.
   1.933 +
   1.934 +Note that when adding one month to the last day in the month, if the following
   1.935 +month is shorter, the result is the last day in the following month.
   1.936 +For example, when adding one month to 31st August, the result is
   1.937 +the 30th September.
   1.938 +
   1.939 +Note also that this TTime object is not changed.
   1.940 +
   1.941 +@param aMonth A time interval in months. The argument is stored as a 32 bit
   1.942 +              signed integer. The maximum value which it can represent is
   1.943 +              2147483647. Any attempt to add more than this amount will
   1.944 +              produce incorrect results.
   1.945 +
   1.946 +@return The new time.
   1.947 +*/
   1.948 +	{
   1.949 +
   1.950 +	TDateTime dateTime=DateTime();
   1.951 +	TInt month=dateTime.Month()+(dateTime.Year()*12)+aMonth.Int();
   1.952 +	TInt day=dateTime.Day();
   1.953 +	TInt year=month/12;
   1.954 +	month%=12;
   1.955 +	if (month<0)
   1.956 +		{
   1.957 +		year--;
   1.958 +		month+=12;
   1.959 +		}
   1.960 +	TInt daysInMonth=(mTab[Time::IsLeapYear(year)][month]-1); 
   1.961 +	if (day>=daysInMonth)
   1.962 +		day=daysInMonth;
   1.963 +	__ASSERT_ALWAYS(dateTime.Set(year,TMonth(month),day,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond())==KErrNone,Panic(ETDateTimeBadDateTime));
   1.964 +	return(dateTime);
   1.965 +	}
   1.966 +							 
   1.967 +EXPORT_C TTime TTime::operator+(TTimeIntervalDays aDay) const
   1.968 +/**
   1.969 +Adds a time interval to this TTime, returning the result
   1.970 +as a TTime.
   1.971 +
   1.972 +Note that this TTime object is not changed.
   1.973 +
   1.974 +@param aDay A time interval in days. The argument is stored as a 32 bit
   1.975 +            signed integer. The maximum value which it can represent is
   1.976 +            2147483647. Any attempt to add more than this amount will
   1.977 +            produce incorrect results.
   1.978 +
   1.979 +@return The new time.
   1.980 +*/
   1.981 +	{ 
   1.982 +
   1.983 +	return(iTime+TInt64(aDay.Int())*KDaysToMicroSeconds);
   1.984 +	}
   1.985 +
   1.986 +EXPORT_C TTime TTime::operator+(TTimeIntervalHours aHour) const
   1.987 +/**
   1.988 +Adds a time interval to this TTime, returning the result
   1.989 +as a TTime.
   1.990 +
   1.991 +Note that this TTime object is not changed.
   1.992 +
   1.993 +@param aHour A time interval in hours. The argument is stored as a 32 bit
   1.994 +             signed integer. The maximum value which it can represent is
   1.995 +             2147483647. Any attempt to add more than this amount will
   1.996 +             produce incorrect results.
   1.997 +
   1.998 +@return The new time.
   1.999 +*/
  1.1000 +	{
  1.1001 +
  1.1002 +	return(iTime+TInt64(aHour.Int())*KHoursToMicroSeconds);
  1.1003 +	}
  1.1004 +
  1.1005 +EXPORT_C TTime TTime::operator+(TTimeIntervalMinutes aMinute) const
  1.1006 +/**
  1.1007 +Adds a time interval to this TTime, returning the result
  1.1008 +as a TTime.
  1.1009 +
  1.1010 +Note that this TTime object is not changed.
  1.1011 +
  1.1012 +@param aMinute A time interval in minutes. The argument is stored as a 32 bit
  1.1013 +               signed integer. The maximum value which it can represent is
  1.1014 +               2147483647. Any attempt to add more than this amount will
  1.1015 +               produce incorrect results.
  1.1016 +
  1.1017 +@return The new time.
  1.1018 +*/
  1.1019 +	{
  1.1020 +
  1.1021 +	return(iTime+TInt64(aMinute.Int())*KMinutesToMicroSeconds);
  1.1022 +	}
  1.1023 +
  1.1024 +EXPORT_C TTime TTime::operator+(TTimeIntervalSeconds aSecond) const
  1.1025 +/**
  1.1026 +Adds a time interval to this TTime, returning the result
  1.1027 +as a TTime.
  1.1028 +
  1.1029 +Note that this TTime object is not changed.
  1.1030 +
  1.1031 +@param aSecond A time interval in seconds. The argument is stored as a 32 bit
  1.1032 +               signed integer. The maximum value which it can represent is
  1.1033 +               2147483647. Any attempt to add more than this amount will
  1.1034 +               produce incorrect results.
  1.1035 +
  1.1036 +@return The new time.
  1.1037 +*/
  1.1038 +	{
  1.1039 +
  1.1040 +	return(iTime+TInt64(aSecond.Int())*KSecondsToMicroSeconds);
  1.1041 +	}
  1.1042 +
  1.1043 + 
  1.1044 +EXPORT_C TTime TTime::operator+(TTimeIntervalMicroSeconds aMicroSecond) const
  1.1045 +/**
  1.1046 +Adds a time interval to this TTime, returning the result
  1.1047 +as a TTime.
  1.1048 +
  1.1049 +Note that this TTime object is not changed.
  1.1050 +
  1.1051 +@param aMicroSecond A time interval in microseconds.
  1.1052 +
  1.1053 +@return The new time.
  1.1054 +*/
  1.1055 +	{
  1.1056 +
  1.1057 +	return(iTime+(aMicroSecond.Int64()));
  1.1058 +	}
  1.1059 +
  1.1060 +EXPORT_C TTime TTime::operator+(TTimeIntervalMicroSeconds32 aMicroSecond) const
  1.1061 +/**
  1.1062 +Adds a time interval to this TTime, returning the result
  1.1063 +as a TTime.
  1.1064 +
  1.1065 +Note that this TTime object is not changed.
  1.1066 +
  1.1067 +@param aMicroSecond A time interval in microseconds. The argument is stored as
  1.1068 +                    a 32 bit signed integer. The maximum value which it can
  1.1069 +                    represent is 2147483647. Any attempt to add more than this
  1.1070 +                    amount will produce incorrect results.
  1.1071 +
  1.1072 +@return The new time.
  1.1073 +*/
  1.1074 +	{
  1.1075 +
  1.1076 +	return(iTime+aMicroSecond.Int());
  1.1077 +	}
  1.1078 +
  1.1079 +EXPORT_C TTime TTime::operator-(TTimeIntervalYears aYear) const
  1.1080 +/**
  1.1081 +Substracts a time interval from this TTime, returning the result
  1.1082 +as a TTime.
  1.1083 +
  1.1084 +Note that in a leap year, when subtracting one year from the 29th February,
  1.1085 +the result is 28th February in the preceding year.
  1.1086 +
  1.1087 +Note also that this TTime object is not changed.
  1.1088 +
  1.1089 +@param aYear A time interval in years. The argument is stored as
  1.1090 +             a 32 bit signed integer. The maximum value which it can
  1.1091 +             represent is 2147483647. Any attempt to subtract more than this
  1.1092 +             amount will produce incorrect results.
  1.1093 +
  1.1094 +@return The new time.
  1.1095 +*/
  1.1096 +	{
  1.1097 +
  1.1098 +	return((*this)-TTimeIntervalMonths(aYear.Int()*12));
  1.1099 +	}
  1.1100 +
  1.1101 +EXPORT_C TTime TTime::operator-(TTimeIntervalMonths aMonth) const
  1.1102 +/**
  1.1103 +Substracts a time interval from this TTime, returning the result
  1.1104 +as a TTime.
  1.1105 +
  1.1106 +Note that when subtracting one month from the last day in the month, if the
  1.1107 +preceding month is shorter, the result is the last day in the preceding month.
  1.1108 +For example, when subtracting 1 month from 31st October, the result is
  1.1109 +the 30th September.
  1.1110 +
  1.1111 +Note also that this TTime object is not changed.
  1.1112 +
  1.1113 +@param aMonth A time interval in months. The argument is stored as
  1.1114 +              a 32 bit signed integer. The maximum value which it can
  1.1115 +              represent is 2147483647. Any attempt to subtract more than this
  1.1116 +              amount will produce incorrect results.
  1.1117 +
  1.1118 +@return The new time.
  1.1119 +*/
  1.1120 +	{
  1.1121 +
  1.1122 +	return((*this)+TTimeIntervalMonths(aMonth.Int()*-1));
  1.1123 +	}
  1.1124 +							 
  1.1125 +EXPORT_C TTime TTime::operator-(TTimeIntervalDays aDay) const
  1.1126 +/**
  1.1127 +Substracts a time interval from this TTime, returning the result
  1.1128 +as a TTime.
  1.1129 +
  1.1130 +Note that this TTime object is not changed.
  1.1131 +
  1.1132 +@param aDay A time interval in days. The argument is stored as
  1.1133 +            a 32 bit signed integer. The maximum value which it can
  1.1134 +            represent is 2147483647. Any attempt to subtract more than this
  1.1135 +            amount will produce incorrect results.
  1.1136 +
  1.1137 +@return The new time.
  1.1138 +*/
  1.1139 +	{ 
  1.1140 +
  1.1141 +	return(iTime-TInt64(aDay.Int())*KDaysToMicroSeconds);
  1.1142 +	}
  1.1143 +
  1.1144 +EXPORT_C TTime TTime::operator-(TTimeIntervalHours aHour) const
  1.1145 +/**
  1.1146 +Substracts a time interval from this TTime, returning the result
  1.1147 +as a TTime.
  1.1148 +
  1.1149 +Note that this TTime object is not changed.
  1.1150 +
  1.1151 +@param aHour A time interval in hours. The argument is stored as
  1.1152 +             a 32 bit signed integer. The maximum value which it can
  1.1153 +             represent is 2147483647. Any attempt to subtract more than this
  1.1154 +             amount will produce incorrect results.
  1.1155 +
  1.1156 +@return The new time.
  1.1157 +*/
  1.1158 +	{
  1.1159 +
  1.1160 +	return(iTime-TInt64(aHour.Int())*KHoursToMicroSeconds);
  1.1161 +	}
  1.1162 +
  1.1163 +EXPORT_C TTime TTime::operator-(TTimeIntervalMinutes aMinute) const
  1.1164 +/**
  1.1165 +Substracts a time interval from this TTime, returning the result
  1.1166 +as a TTime.
  1.1167 +
  1.1168 +Note that this TTime object is not changed.
  1.1169 +
  1.1170 +@param aMinute A time interval in minutes. The argument is stored as
  1.1171 +               a 32 bit signed integer. The maximum value which it can
  1.1172 +               represent is 2147483647. Any attempt to subtract more than this
  1.1173 +               amount will produce incorrect results.
  1.1174 +
  1.1175 +@return The new time.
  1.1176 +*/
  1.1177 +	{
  1.1178 +
  1.1179 +	return(iTime-TInt64(aMinute.Int())*KMinutesToMicroSeconds);
  1.1180 +	}
  1.1181 +
  1.1182 +EXPORT_C TTime TTime::operator-(TTimeIntervalSeconds aSecond) const
  1.1183 +/**
  1.1184 +Substracts a time interval from this TTime, returning the result
  1.1185 +as a TTime.
  1.1186 +
  1.1187 +Note that this TTime object is not changed.
  1.1188 +
  1.1189 +@param aSecond A time interval in seconds. The argument is stored as
  1.1190 +               a 32 bit signed integer. The maximum value which it can
  1.1191 +               represent is 2147483647. Any attempt to subtract more than this
  1.1192 +               amount will produce incorrect results.
  1.1193 +
  1.1194 +@return The new time.
  1.1195 +*/
  1.1196 +	{
  1.1197 +
  1.1198 +	return(iTime-TInt64(aSecond.Int())*KSecondsToMicroSeconds);
  1.1199 +	}
  1.1200 +
  1.1201 +EXPORT_C TTime TTime::operator-(TTimeIntervalMicroSeconds aMicroSecond) const
  1.1202 +/**
  1.1203 +Substracts a time interval from this TTime, returning the result
  1.1204 +as a TTime.
  1.1205 +
  1.1206 +Note that this TTime object is not changed.
  1.1207 +
  1.1208 +@param aMicroSecond A time interval in microseconds.
  1.1209 +
  1.1210 +@return The new time.
  1.1211 +*/
  1.1212 +	{
  1.1213 +
  1.1214 +	return(iTime-(aMicroSecond.Int64()));
  1.1215 +	}
  1.1216 +
  1.1217 +EXPORT_C TTime TTime::operator-(TTimeIntervalMicroSeconds32 aMicroSecond) const
  1.1218 +/**
  1.1219 +Substracts a time interval from this TTime, returning the result
  1.1220 +as a TTime.
  1.1221 +
  1.1222 +Note that this TTime object is not changed.
  1.1223 +
  1.1224 +@param aMicroSecond A time interval in microseconds. The argument is stored as
  1.1225 +                    a 32 bit signed integer. The maximum value which it can
  1.1226 +                    represent is 2147483647. Any attempt to subtract more than
  1.1227 +                    this amount will produce incorrect results.
  1.1228 +
  1.1229 +@return The new time.
  1.1230 +*/
  1.1231 +	{
  1.1232 +
  1.1233 +	return(iTime-aMicroSecond.Int());
  1.1234 +	}
  1.1235 +
  1.1236 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalYears aYear)
  1.1237 +/**
  1.1238 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1239 +
  1.1240 +@param aYear A time interval in years.
  1.1241 +
  1.1242 +@return A reference to this TTime.
  1.1243 +*/
  1.1244 +	{	
  1.1245 +
  1.1246 +	TTime tim=(*this)+aYear;
  1.1247 +	iTime=tim.Int64();
  1.1248 +	return(*this);
  1.1249 +	}
  1.1250 +
  1.1251 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalMonths aMonth)
  1.1252 +/**
  1.1253 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1254 +
  1.1255 +@param aMonth A time interval in months.
  1.1256 +
  1.1257 +@return A reference to this TTime.
  1.1258 +*/
  1.1259 +	{
  1.1260 +
  1.1261 +	TTime tim=(*this)+aMonth;
  1.1262 +	iTime=tim.Int64();
  1.1263 +	return(*this);
  1.1264 +	}
  1.1265 +
  1.1266 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalDays aDay)
  1.1267 +/**
  1.1268 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1269 +
  1.1270 +@param aDay A time interval in days.
  1.1271 +
  1.1272 +@return A reference to this TTime.
  1.1273 +*/
  1.1274 +	{
  1.1275 +
  1.1276 +	iTime+=TInt64(aDay.Int())*KDaysToMicroSeconds;
  1.1277 +	return(*this);
  1.1278 +	}
  1.1279 +
  1.1280 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalHours aHour)
  1.1281 +/**
  1.1282 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1283 +
  1.1284 +@param aHour A time interval in hours.
  1.1285 +
  1.1286 +@return A reference to this TTime.
  1.1287 +*/
  1.1288 +	{
  1.1289 +
  1.1290 +	iTime+=TInt64(aHour.Int())*KHoursToMicroSeconds;
  1.1291 +	return(*this);
  1.1292 +	}
  1.1293 +
  1.1294 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalMinutes aMinute)
  1.1295 +/**
  1.1296 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1297 +
  1.1298 +@param aMinute A time interval in minutes.
  1.1299 +
  1.1300 +@return A reference to this TTime.
  1.1301 +*/
  1.1302 +	{
  1.1303 +
  1.1304 +	iTime+=TInt64(aMinute.Int())*KMinutesToMicroSeconds;
  1.1305 +	return(*this);
  1.1306 +	}
  1.1307 +
  1.1308 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalSeconds aSecond)
  1.1309 +/**
  1.1310 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1311 +
  1.1312 +@param aSecond A time interval in seconds.
  1.1313 +
  1.1314 +@return A reference to this TTime.
  1.1315 +*/
  1.1316 +	{
  1.1317 +
  1.1318 +	iTime+=TInt64(aSecond.Int())*KSecondsToMicroSeconds;
  1.1319 +	return(*this);
  1.1320 +	}
  1.1321 +
  1.1322 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalMicroSeconds aMicroSecond)
  1.1323 +/**
  1.1324 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1325 +
  1.1326 +@param aMicroSecond A time interval in microseconds.
  1.1327 +
  1.1328 +@return A reference to this TTime.
  1.1329 +*/
  1.1330 +	{
  1.1331 +
  1.1332 +	iTime+=aMicroSecond.Int64();
  1.1333 +	return(*this);
  1.1334 +	}
  1.1335 + 
  1.1336 +EXPORT_C TTime &TTime::operator+=(TTimeIntervalMicroSeconds32 aMicroSecond)
  1.1337 +/**
  1.1338 +Adds a time interval to this TTime, returning a reference to this TTime.
  1.1339 +
  1.1340 +@param aMicroSecond A time interval in microseconds, as a 32-bit integer.
  1.1341 +
  1.1342 +@return A reference to this TTime.
  1.1343 +*/
  1.1344 +	{
  1.1345 +
  1.1346 +	iTime+=aMicroSecond.Int();
  1.1347 +	return(*this);
  1.1348 +	}
  1.1349 + 
  1.1350 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalYears aYear)
  1.1351 +/**
  1.1352 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1353 +
  1.1354 +@param aYear A time interval in years.
  1.1355 +
  1.1356 +@return A reference to this TTime.
  1.1357 +*/
  1.1358 +	{	
  1.1359 +
  1.1360 +	TTime tim=(*this)-aYear;
  1.1361 +	iTime=tim.Int64();
  1.1362 +	return(*this);
  1.1363 +	}
  1.1364 +
  1.1365 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalMonths aMonth)
  1.1366 +/**
  1.1367 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1368 +
  1.1369 +@param aMonth A time interval in months.
  1.1370 +
  1.1371 +@return A reference to this TTime.
  1.1372 +*/
  1.1373 +	{
  1.1374 +
  1.1375 +	TTime tim=(*this)-aMonth;
  1.1376 +	iTime=tim.Int64();
  1.1377 +	return(*this);
  1.1378 +	}
  1.1379 +
  1.1380 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalDays aDay)
  1.1381 +/**
  1.1382 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1383 +
  1.1384 +@param aDay A time interval in days.
  1.1385 +
  1.1386 +@return A reference to this TTime.
  1.1387 +*/
  1.1388 +	{
  1.1389 +
  1.1390 +	iTime-=TInt64(aDay.Int())*KDaysToMicroSeconds;
  1.1391 +	return(*this);
  1.1392 +	}
  1.1393 +
  1.1394 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalHours aHour)
  1.1395 +/**
  1.1396 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1397 +
  1.1398 +@param aHour A time interval in hours.
  1.1399 +
  1.1400 +@return A reference to this TTime.
  1.1401 +*/
  1.1402 +	{
  1.1403 +
  1.1404 +	iTime-=TInt64(aHour.Int())*KHoursToMicroSeconds;
  1.1405 +	return(*this);
  1.1406 +	}
  1.1407 +
  1.1408 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalMinutes aMinute)
  1.1409 +/**
  1.1410 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1411 +
  1.1412 +@param aMinute A time interval in minutes.
  1.1413 +
  1.1414 +@return A reference to this TTime.
  1.1415 +*/
  1.1416 +	{
  1.1417 +
  1.1418 +	iTime-=TInt64(aMinute.Int())*KMinutesToMicroSeconds;
  1.1419 +	return(*this);
  1.1420 +	}
  1.1421 +
  1.1422 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalSeconds aSecond)
  1.1423 +/**
  1.1424 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1425 +
  1.1426 +@param aSecond A time interval in seconds.
  1.1427 +
  1.1428 +@return A reference to this TTime.
  1.1429 +*/
  1.1430 +	{
  1.1431 +
  1.1432 +	iTime-=TInt64(aSecond.Int())*KSecondsToMicroSeconds;
  1.1433 +	return(*this);
  1.1434 +	}
  1.1435 +
  1.1436 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalMicroSeconds aMicroSecond)
  1.1437 +/**
  1.1438 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1439 +
  1.1440 +@param aMicroSecond A time interval in microseconds.
  1.1441 +
  1.1442 +@return A reference to this TTime.
  1.1443 +*/
  1.1444 +	{
  1.1445 +
  1.1446 +	iTime-=aMicroSecond.Int64();
  1.1447 +	return(*this);
  1.1448 +	}
  1.1449 +
  1.1450 +EXPORT_C TTime &TTime::operator-=(TTimeIntervalMicroSeconds32 aMicroSecond)
  1.1451 +/**
  1.1452 +Subtracts a time interval from this TTime, returning a reference to this TTime.
  1.1453 +
  1.1454 +@param aMicroSecond A time interval in microseconds, as a 32-bit integer.
  1.1455 +
  1.1456 +@return A reference to this TTime.
  1.1457 +*/
  1.1458 +	{
  1.1459 +
  1.1460 +	iTime-=aMicroSecond.Int();
  1.1461 +	return(*this);
  1.1462 +	}
  1.1463 + 
  1.1464 +EXPORT_C TInt TTime::DaysInMonth() const
  1.1465 +/**
  1.1466 +Gets the number of days in the current month.
  1.1467 +
  1.1468 +@return The number of days in the month.
  1.1469 +*/
  1.1470 +	{
  1.1471 +
  1.1472 +	TDateTime dateTime=DateTime();
  1.1473 +	return(Time::DaysInMonth(dateTime.Year(),dateTime.Month()));
  1.1474 +	}
  1.1475 +
  1.1476 +EXPORT_C TDay TTime::DayNoInWeek() const
  1.1477 +//
  1.1478 +// 1st January 0AD was a Monday
  1.1479 +//
  1.1480 +/**
  1.1481 +Gets the day number within the current week.
  1.1482 +
  1.1483 +This is a value in the range zero to six inclusive, and honours the 
  1.1484 +setting specified in TLocale::SetStartOfWeek().
  1.1485 +
  1.1486 +By default the first day in the week is Monday.
  1.1487 +
  1.1488 +@return The number of the day within the week. The range is EMonday to ESunday.
  1.1489 +
  1.1490 +@see TLocale::SetStartOfWeek
  1.1491 +*/
  1.1492 +	{
  1.1493 +
  1.1494 +
  1.1495 +	TInt64 fullDays=iTime/KDaysToMicroSeconds;
  1.1496 +	TInt day = static_cast<TInt>(fullDays) % 7;
  1.1497 +	if (iTime<0)
  1.1498 +		{
  1.1499 +		if (fullDays*KDaysToMicroSeconds!=iTime)
  1.1500 +			day+=6;
  1.1501 +		else
  1.1502 +			if (day!=0)
  1.1503 +				day+=7;
  1.1504 +		}
  1.1505 +	return((TDay)day);
  1.1506 +	}
  1.1507 +
  1.1508 +EXPORT_C TInt TTime::DayNoInMonth() const
  1.1509 +/**
  1.1510 +Gets the day number in the month.
  1.1511 +
  1.1512 +@return The day number in the month. The first day in the month is numbered 
  1.1513 +        zero.
  1.1514 +*/
  1.1515 +	{
  1.1516 +
  1.1517 +	return(DateTime().Day());
  1.1518 +	}
  1.1519 +
  1.1520 +EXPORT_C TInt TTime::DayNoInYear() const
  1.1521 +//
  1.1522 +// day number in comparison to 1st January
  1.1523 +//
  1.1524 +/**
  1.1525 +Gets the day number in the year. 
  1.1526 +
  1.1527 +@return The day number in the year. The first day in the year is day one.
  1.1528 +*/
  1.1529 +	{
  1.1530 +
  1.1531 +	TDateTime dateTime=DateTime();
  1.1532 +	TTime jan1st=TDateTime(dateTime.Year(),EJanuary,0,0,0,0,0);
  1.1533 +	return(DayNoInYear(jan1st));
  1.1534 +	}
  1.1535 +
  1.1536 +EXPORT_C TInt TTime::DayNoInYear(TTime aStartDate) const
  1.1537 +//
  1.1538 +// day number in comparison to given date, check is made to ensure first day is within a year before aDay
  1.1539 +//
  1.1540 +/**
  1.1541 +Gets the day number in the year when the start of the year is aStartDate. 
  1.1542 +
  1.1543 +If no start date is specified, the default is January 1st.
  1.1544 +
  1.1545 +@param aStartDate Indicates the date which is to be considered the start of 
  1.1546 +                  the year. Default is 1st January.
  1.1547 +                  
  1.1548 +@return The day number in the year. The first day in the year is day one.
  1.1549 +*/
  1.1550 +	{
  1.1551 +
  1.1552 +	TInt y=DateTime().Year();
  1.1553 +	TMonth m=aStartDate.DateTime().Month();
  1.1554 +	TInt d=aStartDate.DateTime().Day();
  1.1555 +    if (d>=Time::DaysInMonth(y,m))
  1.1556 +        d=27;
  1.1557 +    TDateTime yearStart(y,m,d,0,0,0,0);              // LEAP YEAR PROBLEMS ???
  1.1558 +	aStartDate=yearStart;
  1.1559 +	if (aStartDate>*this)
  1.1560 +		{
  1.1561 +		yearStart.SetYearLeapCheck(y-1);
  1.1562 +		aStartDate=yearStart;
  1.1563 +		}
  1.1564 +    return((DaysFrom(aStartDate).Int())+1) ;
  1.1565 +    }
  1.1566 +
  1.1567 +EXPORT_C TInt TTime::WeekNoInYear() const
  1.1568 +/**
  1.1569 +Gets the number of the current week in the year.
  1.1570 +
  1.1571 +@return Week number in the year.
  1.1572 +*/
  1.1573 +	{
  1.1574 +
  1.1575 +	return(WeekNoInYear(EFirstFourDayWeek));
  1.1576 +	}
  1.1577 +
  1.1578 +EXPORT_C TInt TTime::WeekNoInYear(TTime aStartDate) const
  1.1579 +/**
  1.1580 +Gets the number of the current week in the year when the year starts
  1.1581 +on aStartDate. 
  1.1582 +
  1.1583 +@param aStartDate If specified, indicates the date which is to be considered 
  1.1584 +                  the start of the year. Default is 1st January.
  1.1585 +                  
  1.1586 +@return Week number in the year.
  1.1587 +*/
  1.1588 +	{
  1.1589 +    
  1.1590 +    return(WeekNoInYear(aStartDate,EFirstFourDayWeek));
  1.1591 +	}
  1.1592 +
  1.1593 +EXPORT_C TInt TTime::WeekNoInYear(TFirstWeekRule aRule) const
  1.1594 +/**
  1.1595 +Finds the number of the current week in the year using the first week rule 
  1.1596 +specified in aRule. 
  1.1597 +
  1.1598 +@param aRule Determines how the first week in the year is to be calculated. 
  1.1599 +             By default EFirstFourDayWeek.
  1.1600 +             
  1.1601 +@return Week number in the year.
  1.1602 +*/
  1.1603 +	{
  1.1604 +	
  1.1605 +	TInt year=DateTime().Year();
  1.1606 +	TTime startDate=TDateTime(year,EJanuary,0,0,0,0,0);
  1.1607 +	return(WeekNoInYear(startDate,aRule));
  1.1608 +	}
  1.1609 +
  1.1610 +EXPORT_C TInt TTime::WeekNoInYear(TTime aStartDate,TFirstWeekRule aRule) const
  1.1611 +//
  1.1612 +// number of weeks between aTime and aStartDate according to given rule
  1.1613 +// the first week starts either on the week containing the first day (EFirstWeek), 
  1.1614 +// the first week having at least four days within the new year (EFirstFourDayWeek,
  1.1615 +//  default) or the first full week in the year (EFirstFullWeek)
  1.1616 +//
  1.1617 +/**
  1.1618 +Finds the number of the current week in the year when the year starts from 
  1.1619 +aStartDate and when using the start week rule aRule.
  1.1620 +
  1.1621 +@param aStartDate If specified, indicates the date which is to be considered 
  1.1622 +                  the start of the year. Default is 1st January.
  1.1623 +@param aRule      Determines how the first week in the year is to be
  1.1624 +                  calculated. By default EFirstFourDayWeek.
  1.1625 +                  
  1.1626 +@return Week number in the year.
  1.1627 +*/
  1.1628 +	{                    
  1.1629 +	TInt dayNoInWeek=DayNoInWeek();
  1.1630 +	TInt dayNoInYear=(DayNoInYear(aStartDate))-1;    // puts start into correct year
  1.1631 +	TDateTime startDateTime(aStartDate.DateTime());
  1.1632 +	TDateTime nextYearStartDate(startDateTime);
  1.1633 +	nextYearStartDate.SetYearLeapCheck(DateTime().Year());    // find start of next year
  1.1634 +	TTime nextYearStartTime(nextYearStartDate);            // makes sure start date for year
  1.1635 +	if (*this>nextYearStartTime)                           // is in the very next year
  1.1636 +		{
  1.1637 +		nextYearStartDate.SetYearLeapCheck(nextYearStartDate.Year()+1);
  1.1638 +		nextYearStartTime=nextYearStartDate;
  1.1639 +		}
  1.1640 +	nextYearStartTime+=TTimeIntervalMicroSeconds(KDaysToMicroSeconds-1); // avoid problems if the time is not midnight
  1.1641 +	TLocale local;
  1.1642 +	TDay startOfFirstWeek=local.StartOfWeek();
  1.1643 +	// calculate the day-in-week number (0 to 6) based on the locale start-of-week
  1.1644 +	dayNoInWeek -= startOfFirstWeek;
  1.1645 +	if (dayNoInWeek < 0)
  1.1646 +		dayNoInWeek += 7;
  1.1647 +	// calculate the days from the start-of-week to the start-of-next-year
  1.1648 +	TInt daysFrom=nextYearStartTime.DaysFrom(*this).Int()+dayNoInWeek;
  1.1649 +	// calculate the days from start-of-year to start-of-week (note this may be negative, but never < -6)
  1.1650 +	TInt days=dayNoInYear-dayNoInWeek;
  1.1651 +
  1.1652 +	// the rule allows a certain number of week-1 days to lie in the previous year
  1.1653 +	TInt prevyeardays;
  1.1654 +	switch (aRule)
  1.1655 +		{
  1.1656 +	default:
  1.1657 +		return -1;
  1.1658 +	case EFirstWeek:
  1.1659 +		prevyeardays = 6;
  1.1660 +		break;
  1.1661 +	case EFirstFourDayWeek:
  1.1662 +		prevyeardays = 3;
  1.1663 +		break;
  1.1664 +	case EFirstFullWeek:
  1.1665 +		prevyeardays = 0;
  1.1666 +		break;
  1.1667 +		}
  1.1668 +
  1.1669 +	// check for a week which belongs to last year
  1.1670 +	if (days + prevyeardays < 0)
  1.1671 +		{
  1.1672 +		// in week 52 or 53 of last year, find the week # of the first day in the week
  1.1673 +		startDateTime.SetYearLeapCheck(startDateTime.Year()-1);
  1.1674 +		return (*this-TTimeIntervalDays(dayNoInWeek)).WeekNoInYear(TTime(startDateTime),aRule);
  1.1675 +		}
  1.1676 +
  1.1677 +	// check for a week which belongs to next year
  1.1678 +	if (daysFrom <= prevyeardays)
  1.1679 +		return 1;
  1.1680 +
  1.1681 +	// calculate the week number, accounting for the requested week-1 rule
  1.1682 +	return (days + 7 + prevyeardays)/7;
  1.1683 +	}
  1.1684 +
  1.1685 +EXPORT_C void TTime::FormatL(TDes &aDes,const TDesC &aFormat) const
  1.1686 +//
  1.1687 +// Fill aString with current Date and Time according to given aFormat string
  1.1688 +//
  1.1689 +/**
  1.1690 +Puts this TTime into a descriptor and formats it according to the format string 
  1.1691 +specified in the second argument.
  1.1692 +
  1.1693 +Many of the formatting commands use the 
  1.1694 +system's locale settings for the date and time, for example the characters 
  1.1695 +used to separate components of the date and time and the ordering of day, 
  1.1696 +month and year. The list of formatting commands below is divided into two 
  1.1697 +sections, the first of which lists the commands which operate without reference 
  1.1698 +to the locale's date and time settings (see class TLocale) and the second 
  1.1699 +table lists the commands which do use these settings.
  1.1700 +
  1.1701 +The following formatting commands do not honour the locale-specific system 
  1.1702 +settings:
  1.1703 +
  1.1704 +\%\% : Include a single '%' character in the string
  1.1705 +
  1.1706 +\%* : Abbreviate following item (the following item should not be preceded 
  1.1707 +by a '%' character).
  1.1708 +
  1.1709 +\%C : Interpret the argument as the six digit microsecond component of the 
  1.1710 +time. In its abbreviated form, ('%*C') this should be followed by an integer 
  1.1711 +between zero and six, where the integer indicates the number of digits to display.
  1.1712 +
  1.1713 +\%D : Interpret the argument as the two digit day number in the month. Abbreviation 
  1.1714 +suppresses leading zero.
  1.1715 +
  1.1716 +\%E : Interpret the argument as the day name. Abbreviation is language-specific 
  1.1717 +(e.g. English uses the first three letters).
  1.1718 +
  1.1719 +\%F : Use this command for locale-independent ordering of date components. 
  1.1720 +This orders the following day/month/year component(s) (\%D, \%M, \%Y for example) 
  1.1721 +according to the order in which they are specified in the string. This removes 
  1.1722 +the need to use \%1 to \%5 (described below).
  1.1723 +
  1.1724 +\%H : Interpret the argument as the one or two digit hour component of the 
  1.1725 +time in 24 hour time format. Abbreviation suppresses leading zero. For locale-dependent 
  1.1726 +hour formatting, use \%J.
  1.1727 +
  1.1728 +\%I : Interpret the argument as the one or two digit hour component of the 
  1.1729 +time in 12 hour time format. The leading zero is automatically suppressed 
  1.1730 +so that abbreviation has no effect. For locale-dependent hour formatting, 
  1.1731 +use \%J.
  1.1732 +
  1.1733 +\%M : Interpret the argument as the one or two digit month number. Abbreviation 
  1.1734 +suppresses leading zero.
  1.1735 +
  1.1736 +\%N : Interpret the argument as the month name. Abbreviation is language specific, e.g. 
  1.1737 +English uses the first three letters only. When using locale-dependent formatting, 
  1.1738 +(that is, \%F has not previously been specified), specifying \%N causes any 
  1.1739 +subsequent occurrence of a month specifier in the string to insert the month 
  1.1740 +as text rather than in numeric form. When using locale-independent formatting, 
  1.1741 +specifying \%N causes the month to be inserted as text at that position, but 
  1.1742 +any subsequent occurrence of \%M will cause the month to be inserted in numeric 
  1.1743 +form.
  1.1744 +
  1.1745 +\%S : Interpret the argument as the one or two digit seconds component of the 
  1.1746 +time. Abbreviation suppresses leading zero.
  1.1747 +
  1.1748 +\%T : Interpret the argument as the one or two digit minutes component of the 
  1.1749 +time. Abbreviation suppresses leading zero.
  1.1750 +
  1.1751 +\%W : Interpret the argument as the one or two digit week number in year. Abbreviation 
  1.1752 +suppresses leading zero.
  1.1753 +
  1.1754 +\%X : Interpret the argument as the date suffix. Cannot be abbreviated. When 
  1.1755 +using locale-dependent formatting (that is, \%F has not previously been specified), 
  1.1756 +\%X causes all further occurrences of the day number to be displayed with the 
  1.1757 +date suffix. When using locale-independent formatting, a date suffix will 
  1.1758 +be inserted only after the occurrence of the day number which \%X follows in 
  1.1759 +the format string. Any further occurrence of \%D without a following \%X will 
  1.1760 +insert the day number without a suffix.
  1.1761 +
  1.1762 +\%Y : Interpret the argument as the four digit year number. Abbreviation suppresses 
  1.1763 +the first two digits.
  1.1764 +
  1.1765 +\%Z : Interpret the argument as the one, two or three digit day number in the 
  1.1766 +year. Abbreviation suppresses leading zeros.
  1.1767 +
  1.1768 +The following formatting commands do honour the locale-specific system settings:
  1.1769 +
  1.1770 +\%. : Interpret the argument as the decimal separator character (as set by 
  1.1771 +TLocale::SetDecimalSeparator()). The decimal separator is used to separate 
  1.1772 +seconds and microseconds, if present.
  1.1773 +
  1.1774 +\%: : Interpret the argument as one of the four time separator characters (as 
  1.1775 +set by TLocale::SetTimeSeparator()). Must be followed by an integer between 
  1.1776 +zero and three inclusive to indicate which time separator character is being 
  1.1777 +referred to.
  1.1778 +
  1.1779 +\%/ : Interpret the argument as one of the four date separator characters (as 
  1.1780 +set by TLocale::SetDateSeparator()). Must be followed by an integer between 
  1.1781 +zero and three inclusive to indicate which date separator character is being 
  1.1782 +referred to.
  1.1783 +
  1.1784 +\%1 : Interpret the argument as the first component of a three component date 
  1.1785 +(i.e. day, month or year) where the order has been set by TLocale::SetDateFormat(). 
  1.1786 +When the date format is EDateEuropean, this is the day, when EDateAmerican, 
  1.1787 +the month, and when EDateJapanese, the year. For more information on this 
  1.1788 +and the following four formatting commands, see the Notes section immediately 
  1.1789 +below.
  1.1790 +
  1.1791 +\%2 : Interpret the argument as the second component of a three component date 
  1.1792 +where the order has been set by TLocale::SetDateFormat(). When the date format 
  1.1793 +is EDateEuropean, this is the month, when EDateAmerican, the day and when 
  1.1794 +EDateJapanese, the month.
  1.1795 +
  1.1796 +\%3 : Interpret the argument as the third component of a three component date 
  1.1797 +where the order has been set by TLocale::SetDateFormat(). When the date format 
  1.1798 +is EDateEuropean, or EDateAmerican this is the year and when EDateJapanese, 
  1.1799 +the day.
  1.1800 +
  1.1801 +\%4 : Interpret the argument as the first component of a two component date 
  1.1802 +(day and month) where the order has been set by TLocale::SetDateFormat(). 
  1.1803 +When the date format is EDateEuropean this is the day, and when EDateAmerican 
  1.1804 +or EDateJapanese, the month.
  1.1805 +
  1.1806 +\%5 : Interpret the argument as the second component of a two component date 
  1.1807 +(day and month) where the order has been set by TLocale::SetDateFormat(). 
  1.1808 +When the date format is EDateEuropean this is the month, and when EDateAmerican 
  1.1809 +or EDateJapanese, the day.
  1.1810 +
  1.1811 +\%A : Interpret the argument as "am" or "pm" text according to the current 
  1.1812 +language and time of day. Unlike the \%B formatting command (described below), 
  1.1813 +\%A disregards the locale's 12 or 24 hour clock setting, so that when used 
  1.1814 +without an inserted + or - sign, am/pm text will always be displayed. Whether 
  1.1815 +a space is inserted between the am/pm text and the time depends on the locale-specific 
  1.1816 +settings. However, if abbreviated (\%*A), no space is inserted, regardless 
  1.1817 +of the locale's settings. The am/pm text appears before or after the time, 
  1.1818 +according to the position of the \%A, regardless of the locale-specific settings. 
  1.1819 +For example, the following ordering of formatting commands causes am/pm text 
  1.1820 +to be printed after the time: \%H \%T \%S \%A. Optionally, a minus or plus sign 
  1.1821 +may be inserted between the "%" and the "A". This operates as follows:
  1.1822 +
  1.1823 +\%-A causes am/pm text to be inserted into the descriptor only if the am/pm 
  1.1824 +symbol position has been set in the locale to ELocaleBefore. Cannot be abbreviated 
  1.1825 +using asterisk.
  1.1826 +
  1.1827 +\%+A causes am/pm text to be inserted into the descriptor only if the am/pm 
  1.1828 +symbol position has been set in the locale to ELocaleAfter. Cannot be abbreviated 
  1.1829 +using asterisk. For example, the following formatting commands will cause 
  1.1830 +am/pm text to be displayed after the time if the am/pm position has been set 
  1.1831 +in the locale to ELocaleAfter or before the time if ELocaleBefore: \%-A \%H 
  1.1832 +\%T \%S \%+A.
  1.1833 +
  1.1834 +\%B Interpret the argument as am or pm text according to the current language 
  1.1835 +and time of day. Unlike the \%A command, when using \%B, am/pm text is displayed 
  1.1836 +only if the clock setting in the locale is 12-hour. Whether a space is inserted 
  1.1837 +between the am/pm text and the time depends on the locale-specific settings. 
  1.1838 +However, if abbreviated (\%*B), no space is inserted, regardless of the locale's 
  1.1839 +settings. The am/pm text appears before or after the time, according to the 
  1.1840 +location of the "%B", regardless of the locale-specific settings. For example, 
  1.1841 +the following formatting commands cause am/pm text to be printed after the 
  1.1842 +time: \%H \%T \%S \%B. Optionally, a minus or plus sign may be inserted between 
  1.1843 +the "%" and the "B". This operates as follows:
  1.1844 +
  1.1845 +\%-B causes am/pm text to be inserted into the descriptor only if using a 12 
  1.1846 +hour clock and the am/pm symbol position has been set in the locale to ELocaleBefore. 
  1.1847 +Cannot be abbreviated using asterisk.
  1.1848 +
  1.1849 +\%+B causes am/pm text to be inserted into the descriptor only if using a 12 
  1.1850 +hour clock and the am/pm symbol position has been set in the locale to ELocaleAfter. 
  1.1851 +Cannot be abbreviated using asterisk. For example, the following formatting 
  1.1852 +commands cause am/pm text to be printed after the time if the am/pm position 
  1.1853 +has been set in the locale to ELocaleAfter or before the time if ELocaleBefore: 
  1.1854 +\%-B \%H \%T \%S \%+B.
  1.1855 +
  1.1856 +\%J Interpret the argument as the hour component of the time in either 12 or 
  1.1857 +24 hour clock format depending on the locale's clock format setting. When 
  1.1858 +the clock format has been set to 12 hour, leading zeros are automatically 
  1.1859 +suppressed so that abbreviation has no effect. Abbreviation suppresses leading 
  1.1860 +zero only when using a 24 hour clock.
  1.1861 +
  1.1862 +Notes:
  1.1863 +
  1.1864 +The \%1, \%2, \%3, \%4 and \%5 formatting commands are used in conjunction with 
  1.1865 +\%D, \%M and \%Y to format the date locale-dependently. When formatting the date 
  1.1866 +locale-dependently, the order of the day, month and year components within 
  1.1867 +the string is determined by the order of the \%1 to \%5 formatting commands, 
  1.1868 +not that of \%D, \%M, \%Y.
  1.1869 +
  1.1870 +When formatting the date locale-independently (that is, \%F has been specified 
  1.1871 +in the format string), the \%1 to \%5 formatting commands are not required, 
  1.1872 +and should be omitted. In this case, the order of the date components is determined 
  1.1873 +by the order of the \%D, \%M, \%Y format commands within aFormat.
  1.1874 +
  1.1875 +Up to four date separators and up to four time separators can be used to separate 
  1.1876 +the components of a date or time. When formatting a numerical date consisting 
  1.1877 +of the day, month and year or a time containing hours, minutes and seconds, 
  1.1878 +all four separators should always be specified in the format command string. 
  1.1879 +Usually, the leading and trailing separators should not be displayed. In this 
  1.1880 +case, the first and fourth separators should still be specified, but should 
  1.1881 +be represented by a null character.
  1.1882 +
  1.1883 +The date format follows the pattern:
  1.1884 +
  1.1885 +DateSeparator[0] DateComponent1 DateSeparator[1] DateComponent2 DateSeparator[2] 
  1.1886 +DateComponent3 DateSeparator[3]
  1.1887 +
  1.1888 +where the ordering of date components is determined by the locale's date format 
  1.1889 +setting.
  1.1890 +
  1.1891 +The time format follows the pattern:
  1.1892 +
  1.1893 +TimeSeparator[0] Hours TimeSeparator[1] Minutes TimeSeparator[2] Seconds TimeSeparator[3]
  1.1894 +
  1.1895 +If the time includes a microseconds component, the third separator should 
  1.1896 +occur after the microseconds, and the seconds and microseconds should be separated 
  1.1897 +by the decimal separator. When formatting a two component time, the following 
  1.1898 +rules apply:
  1.1899 +
  1.1900 +if the time consists of hours and minutes, the third time delimiter should 
  1.1901 +be omitted 
  1.1902 +
  1.1903 +if the time consists of minutes and seconds, the second time delimiter should 
  1.1904 +be omitted
  1.1905 +
  1.1906 +@param aDes    Descriptor, which,  on return contains the formatted date/time string.
  1.1907 +@param aFormat Format string which determines the format of the date and time.
  1.1908 +
  1.1909 +@leave KErrOverflow The date/time string is too long for the descriptor aDes.
  1.1910 +@leave KErrGeneral  A formatting error has occurred.
  1.1911 +*/
  1.1912 +	{
  1.1913 +	TLocale local;
  1.1914 +	FormatL(aDes,aFormat,local);
  1.1915 +	}
  1.1916 +
  1.1917 +EXPORT_C void TTime::FormatL(TDes &aDes,const TDesC &aFormat,const TLocale &aLocale) const
  1.1918 +//
  1.1919 +// Fill aString with current Date and Time according to given aFormat string
  1.1920 +//
  1.1921 +/**
  1.1922 +Puts this TTime into a descriptor and formats it according to the format string 
  1.1923 +specified in the second argument.
  1.1924 +
  1.1925 +Many of the formatting commands use the 
  1.1926 +system's locale settings for the date and time, for example the characters 
  1.1927 +used to separate components of the date and time and the ordering of day, 
  1.1928 +month and year. The list of formatting commands below is divided into two 
  1.1929 +sections, the first of which lists the commands which operate without reference 
  1.1930 +to the locale's date and time settings (see class TLocale) and the second 
  1.1931 +table lists the commands which do use these settings.
  1.1932 +
  1.1933 +The following formatting commands do not honour the locale-specific system 
  1.1934 +settings:
  1.1935 +
  1.1936 +\%\% : Include a single '%' character in the string
  1.1937 +
  1.1938 +\%* : Abbreviate following item (the following item should not be preceded 
  1.1939 +by a '%' character).
  1.1940 +
  1.1941 +\%C : Interpret the argument as the six digit microsecond component of the 
  1.1942 +time. In its abbreviated form, ('%*C') this should be followed by an integer 
  1.1943 +between zero and six, where the integer indicates the number of digits to display.
  1.1944 +
  1.1945 +\%D : Interpret the argument as the two digit day number in the month. Abbreviation 
  1.1946 +suppresses leading zero.
  1.1947 +
  1.1948 +\%E : Interpret the argument as the day name. Abbreviation is language-specific 
  1.1949 +(e.g. English uses the first three letters).
  1.1950 +
  1.1951 +\%F : Use this command for locale-independent ordering of date components. 
  1.1952 +This orders the following day/month/year component(s) (\%D, \%M, \%Y for example) 
  1.1953 +according to the order in which they are specified in the string. This removes 
  1.1954 +the need to use \%1 to \%5 (described below).
  1.1955 +
  1.1956 +\%H : Interpret the argument as the one or two digit hour component of the 
  1.1957 +time in 24 hour time format. Abbreviation suppresses leading zero. For locale-dependent 
  1.1958 +hour formatting, use \%J.
  1.1959 +
  1.1960 +\%I : Interpret the argument as the one or two digit hour component of the 
  1.1961 +time in 12 hour time format. The leading zero is automatically suppressed 
  1.1962 +so that abbreviation has no effect. For locale-dependent hour formatting, 
  1.1963 +use \%J.
  1.1964 +
  1.1965 +\%M : Interpret the argument as the one or two digit month number. Abbreviation 
  1.1966 +suppresses leading zero.
  1.1967 +
  1.1968 +\%N : Interpret the argument as the month name. Abbreviation is language specific, e.g. 
  1.1969 +English uses the first three letters only. When using locale-dependent formatting, 
  1.1970 +(that is, \%F has not previously been specified), specifying \%N causes any 
  1.1971 +subsequent occurrence of a month specifier in the string to insert the month 
  1.1972 +as text rather than in numeric form. When using locale-independent formatting, 
  1.1973 +specifying \%N causes the month to be inserted as text at that position, but 
  1.1974 +any subsequent occurrence of \%M will cause the month to be inserted in numeric 
  1.1975 +form.
  1.1976 +
  1.1977 +\%S : Interpret the argument as the one or two digit seconds component of the 
  1.1978 +time. Abbreviation suppresses leading zero.
  1.1979 +
  1.1980 +\%T : Interpret the argument as the one or two digit minutes component of the 
  1.1981 +time. Abbreviation suppresses leading zero.
  1.1982 +
  1.1983 +\%W : Interpret the argument as the one or two digit week number in year. Abbreviation 
  1.1984 +suppresses leading zero.
  1.1985 +
  1.1986 +\%X : Interpret the argument as the date suffix. Cannot be abbreviated. When 
  1.1987 +using locale-dependent formatting (that is, \%F has not previously been specified), 
  1.1988 +\%X causes all further occurrences of the day number to be displayed with the 
  1.1989 +date suffix. When using locale-independent formatting, a date suffix will 
  1.1990 +be inserted only after the occurrence of the day number which \%X follows in 
  1.1991 +the format string. Any further occurrence of \%D without a following \%X will 
  1.1992 +insert the day number without a suffix.
  1.1993 +
  1.1994 +\%Y : Interpret the argument as the four digit year number. Abbreviation suppresses 
  1.1995 +the first two digits.
  1.1996 +
  1.1997 +\%Z : Interpret the argument as the one, two or three digit day number in the 
  1.1998 +year. Abbreviation suppresses leading zeros.
  1.1999 +
  1.2000 +The following formatting commands do honour the locale-specific system settings:
  1.2001 +
  1.2002 +\%. : Interpret the argument as the decimal separator character (as set by 
  1.2003 +TLocale::SetDecimalSeparator()). The decimal separator is used to separate 
  1.2004 +seconds and microseconds, if present.
  1.2005 +
  1.2006 +\%: : Interpret the argument as one of the four time separator characters (as 
  1.2007 +set by TLocale::SetTimeSeparator()). Must be followed by an integer between 
  1.2008 +zero and three inclusive to indicate which time separator character is being 
  1.2009 +referred to.
  1.2010 +
  1.2011 +\%/ : Interpret the argument as one of the four date separator characters (as 
  1.2012 +set by TLocale::SetDateSeparator()). Must be followed by an integer between 
  1.2013 +zero and three inclusive to indicate which date separator character is being 
  1.2014 +referred to.
  1.2015 +
  1.2016 +\%1 : Interpret the argument as the first component of a three component date 
  1.2017 +(i.e. day, month or year) where the order has been set by TLocale::SetDateFormat(). 
  1.2018 +When the date format is EDateEuropean, this is the day, when EDateAmerican, 
  1.2019 +the month, and when EDateJapanese, the year. For more information on this 
  1.2020 +and the following four formatting commands, see the Notes section immediately 
  1.2021 +below.
  1.2022 +
  1.2023 +\%2 : Interpret the argument as the second component of a three component date 
  1.2024 +where the order has been set by TLocale::SetDateFormat(). When the date format 
  1.2025 +is EDateEuropean, this is the month, when EDateAmerican, the day and when 
  1.2026 +EDateJapanese, the month.
  1.2027 +
  1.2028 +\%3 : Interpret the argument as the third component of a three component date 
  1.2029 +where the order has been set by TLocale::SetDateFormat(). When the date format 
  1.2030 +is EDateEuropean, or EDateAmerican this is the year and when EDateJapanese, 
  1.2031 +the day.
  1.2032 +
  1.2033 +\%4 : Interpret the argument as the first component of a two component date 
  1.2034 +(day and month) where the order has been set by TLocale::SetDateFormat(). 
  1.2035 +When the date format is EDateEuropean this is the day, and when EDateAmerican 
  1.2036 +or EDateJapanese, the month.
  1.2037 +
  1.2038 +\%5 : Interpret the argument as the second component of a two component date 
  1.2039 +(day and month) where the order has been set by TLocale::SetDateFormat(). 
  1.2040 +When the date format is EDateEuropean this is the month, and when EDateAmerican 
  1.2041 +or EDateJapanese, the day.
  1.2042 +
  1.2043 +\%A : Interpret the argument as "am" or "pm" text according to the current 
  1.2044 +language and time of day. Unlike the \%B formatting command (described below), 
  1.2045 +\%A disregards the locale's 12 or 24 hour clock setting, so that when used 
  1.2046 +without an inserted + or - sign, am/pm text will always be displayed. Whether 
  1.2047 +a space is inserted between the am/pm text and the time depends on the locale-specific 
  1.2048 +settings. However, if abbreviated (\%*A), no space is inserted, regardless 
  1.2049 +of the locale's settings. The am/pm text appears before or after the time, 
  1.2050 +according to the position of the \%A, regardless of the locale-specific settings. 
  1.2051 +For example, the following ordering of formatting commands causes am/pm text 
  1.2052 +to be printed after the time: \%H \%T \%S \%A. Optionally, a minus or plus sign 
  1.2053 +may be inserted between the "%" and the "A". This operates as follows:
  1.2054 +
  1.2055 +\%-A causes am/pm text to be inserted into the descriptor only if the am/pm 
  1.2056 +symbol position has been set in the locale to ELocaleBefore. Cannot be abbreviated 
  1.2057 +using asterisk.
  1.2058 +
  1.2059 +\%+A causes am/pm text to be inserted into the descriptor only if the am/pm 
  1.2060 +symbol position has been set in the locale to ELocaleAfter. Cannot be abbreviated 
  1.2061 +using asterisk. For example, the following formatting commands will cause 
  1.2062 +am/pm text to be displayed after the time if the am/pm position has been set 
  1.2063 +in the locale to ELocaleAfter or before the time if ELocaleBefore: \%-A \%H 
  1.2064 +\%T \%S \%+A.
  1.2065 +
  1.2066 +\%B Interpret the argument as am or pm text according to the current language 
  1.2067 +and time of day. Unlike the \%A command, when using \%B, am/pm text is displayed 
  1.2068 +only if the clock setting in the locale is 12-hour. Whether a space is inserted 
  1.2069 +between the am/pm text and the time depends on the locale-specific settings. 
  1.2070 +However, if abbreviated (\%*B), no space is inserted, regardless of the locale's 
  1.2071 +settings. The am/pm text appears before or after the time, according to the 
  1.2072 +location of the "%B", regardless of the locale-specific settings. For example, 
  1.2073 +the following formatting commands cause am/pm text to be printed after the 
  1.2074 +time: \%H \%T \%S \%B. Optionally, a minus or plus sign may be inserted between 
  1.2075 +the "%" and the "B". This operates as follows:
  1.2076 +
  1.2077 +\%-B causes am/pm text to be inserted into the descriptor only if using a 12 
  1.2078 +hour clock and the am/pm symbol position has been set in the locale to ELocaleBefore. 
  1.2079 +Cannot be abbreviated using asterisk.
  1.2080 +
  1.2081 +\%+B causes am/pm text to be inserted into the descriptor only if using a 12 
  1.2082 +hour clock and the am/pm symbol position has been set in the locale to ELocaleAfter. 
  1.2083 +Cannot be abbreviated using asterisk. For example, the following formatting 
  1.2084 +commands cause am/pm text to be printed after the time if the am/pm position 
  1.2085 +has been set in the locale to ELocaleAfter or before the time if ELocaleBefore: 
  1.2086 +\%-B \%H \%T \%S \%+B.
  1.2087 +
  1.2088 +\%J Interpret the argument as the hour component of the time in either 12 or 
  1.2089 +24 hour clock format depending on the locale's clock format setting. When 
  1.2090 +the clock format has been set to 12 hour, leading zeros are automatically 
  1.2091 +suppressed so that abbreviation has no effect. Abbreviation suppresses leading 
  1.2092 +zero only when using a 24 hour clock.
  1.2093 +
  1.2094 +Notes:
  1.2095 +
  1.2096 +The \%1, \%2, \%3, \%4 and \%5 formatting commands are used in conjunction with 
  1.2097 +\%D, \%M and \%Y to format the date locale-dependently. When formatting the date 
  1.2098 +locale-dependently, the order of the day, month and year components within 
  1.2099 +the string is determined by the order of the \%1 to \%5 formatting commands, 
  1.2100 +not that of \%D, \%M, \%Y.
  1.2101 +
  1.2102 +When formatting the date locale-independently (that is, \%F has been specified 
  1.2103 +in the format string), the \%1 to \%5 formatting commands are not required, 
  1.2104 +and should be omitted. In this case, the order of the date components is determined 
  1.2105 +by the order of the \%D, \%M, \%Y format commands within aFormat.
  1.2106 +
  1.2107 +Up to four date separators and up to four time separators can be used to separate 
  1.2108 +the components of a date or time. When formatting a numerical date consisting 
  1.2109 +of the day, month and year or a time containing hours, minutes and seconds, 
  1.2110 +all four separators should always be specified in the format command string. 
  1.2111 +Usually, the leading and trailing separators should not be displayed. In this 
  1.2112 +case, the first and fourth separators should still be specified, but should 
  1.2113 +be represented by a null character.
  1.2114 +
  1.2115 +The date format follows the pattern:
  1.2116 +
  1.2117 +DateSeparator[0] DateComponent1 DateSeparator[1] DateComponent2 DateSeparator[2] 
  1.2118 +DateComponent3 DateSeparator[3]
  1.2119 +
  1.2120 +where the ordering of date components is determined by the locale's date format 
  1.2121 +setting.
  1.2122 +
  1.2123 +The time format follows the pattern:
  1.2124 +
  1.2125 +TimeSeparator[0] Hours TimeSeparator[1] Minutes TimeSeparator[2] Seconds TimeSeparator[3]
  1.2126 +
  1.2127 +If the time includes a microseconds component, the third separator should 
  1.2128 +occur after the microseconds, and the seconds and microseconds should be separated 
  1.2129 +by the decimal separator. When formatting a two component time, the following 
  1.2130 +rules apply:
  1.2131 +
  1.2132 +if the time consists of hours and minutes, the third time delimiter should 
  1.2133 +be omitted 
  1.2134 +
  1.2135 +if the time consists of minutes and seconds, the second time delimiter should 
  1.2136 +be omitted
  1.2137 +
  1.2138 +@param aDes    Descriptor, which,  on return contains the formatted date/time string.
  1.2139 +@param aFormat Format string which determines the format of the date and time.
  1.2140 +@param aLocale Specific locale which formatting will be based on.
  1.2141 +
  1.2142 +@leave KErrOverflow The date/time string is too long for the descriptor aDes.
  1.2143 +@leave KErrGeneral  A formatting error has occurred.
  1.2144 +*/
  1.2145 +	{
  1.2146 +
  1.2147 +	TDateTime dateTime=DateTime();
  1.2148 +	aDes.Zero(); // ensure string is empty at start
  1.2149 +
  1.2150 + 	TLex aFmt(aFormat);
  1.2151 +	TBool fix=EFalse; // fixed date format
  1.2152 +	TBool da=EFalse; // day unabreviated
  1.2153 +	TBool ma=EFalse; // month unabreviated
  1.2154 +	TBool ya=EFalse; // year unabreviated
  1.2155 +	TBool suff=EFalse; // default no suffix
  1.2156 +	TBool mnam=EFalse; // default month as a number
  1.2157 +	TTimeOverflowLeave overflowLeave;
  1.2158 +
  1.2159 +   	while (!aFmt.Eos())
  1.2160 +		{
  1.2161 +		TChar ch=aFmt.Get();
  1.2162 +		TBool abb=EFalse;
  1.2163 +		const TInt NoPosSpecified=-1;
  1.2164 +		TInt pos=NoPosSpecified;
  1.2165 +		if (ch=='%')
  1.2166 +			ch=aFmt.Get();
  1.2167 +		else // not formatting,just want to add some characters to string
  1.2168 +			goto doAppend; 
  1.2169 +		if (ch=='*') // => abbreviate next field
  1.2170 +			{
  1.2171 +			abb=ETrue;
  1.2172 +			ch=aFmt.Get();
  1.2173 +			}
  1.2174 +		else if (ch=='+' || ch=='-') // => leading or following Am/Pm
  1.2175 +			{
  1.2176 +			pos= ((ch=='+') ? ELocaleAfter : ELocaleBefore);
  1.2177 +			ch=aFmt.Get();
  1.2178 +			if (ch!='A' && ch!='B')
  1.2179 +				User::Leave(KErrGeneral);
  1.2180 +			}
  1.2181 +		switch (ch)
  1.2182 +			{
  1.2183 +		case ':': // local time separator
  1.2184 +				{
  1.2185 +				if (aDes.Length()==aDes.MaxLength())
  1.2186 +					User::Leave(KErrOverflow);
  1.2187 +				ch=aFmt.Get();//Which separator?
  1.2188 +				if (ch<'0' || ch>='0'+KMaxTimeSeparators)
  1.2189 +					User::Leave(KErrGeneral);
  1.2190 +				ch-='0';
  1.2191 +				TChar separator=aLocale.TimeSeparator(ch);
  1.2192 +				if (separator!=0)
  1.2193 +					aDes.Append(separator);
  1.2194 +				}
  1.2195 +			break;
  1.2196 +		case '/': // local date separator
  1.2197 +				{
  1.2198 +				if (aDes.Length()==aDes.MaxLength())
  1.2199 +					User::Leave(KErrOverflow);
  1.2200 +				ch=aFmt.Get();//Which separator?
  1.2201 +				if (ch<'0' || ch>='0'+KMaxDateSeparators)
  1.2202 +					User::Leave(KErrGeneral);
  1.2203 +				ch-='0';
  1.2204 +				TChar separator=aLocale.DateSeparator(ch);
  1.2205 +				if (separator!=0)
  1.2206 +					aDes.Append(separator);
  1.2207 +				}
  1.2208 +			break;
  1.2209 +		case '.': // local decimal separator
  1.2210 +				{
  1.2211 +				if (aDes.Length()==aDes.MaxLength())
  1.2212 +					User::Leave(KErrOverflow);
  1.2213 +				aDes.Append(aLocale.DecimalSeparator());
  1.2214 +				}
  1.2215 +			break;
  1.2216 +		case '1': // 1st element of date,local order
  1.2217 +			switch (aLocale.DateFormat())
  1.2218 +				{
  1.2219 +			case EDateAmerican:
  1.2220 +				goto doMonth;
  1.2221 +			case EDateJapanese:
  1.2222 +				goto doYear;
  1.2223 +			default: // European
  1.2224 +				goto doDay;
  1.2225 +				}
  1.2226 +		case '2': // 2nd element of date,local order
  1.2227 +			switch (aLocale.DateFormat())
  1.2228 +				{
  1.2229 +			case EDateAmerican:
  1.2230 +				goto doDay;
  1.2231 +			default: // European and Japanese have month second
  1.2232 +				goto doMonth;
  1.2233 +				}
  1.2234 +		case '3': // 3rd element of date,local order
  1.2235 +			switch (aLocale.DateFormat())
  1.2236 +				{
  1.2237 +			case EDateJapanese:
  1.2238 +				goto doDay;
  1.2239 +			default: // European and American have year last
  1.2240 +				goto doYear;
  1.2241 +				}
  1.2242 +		case '4': // 1st element of date (no year),local order
  1.2243 +			switch (aLocale.DateFormat())
  1.2244 +				{
  1.2245 +			case EDateEuropean:
  1.2246 +				goto doDay;
  1.2247 +			default:
  1.2248 +				goto doMonth;
  1.2249 +				}
  1.2250 +		case '5': // 2nd element of date (no year),local order
  1.2251 +			switch (aLocale.DateFormat())
  1.2252 +				{
  1.2253 +			case EDateEuropean:
  1.2254 +				goto doMonth;
  1.2255 +			default:
  1.2256 +				goto doDay;
  1.2257 +				}
  1.2258 +		case 'A': // am/pm text
  1.2259 +doAmPm:
  1.2260 +            {
  1.2261 +            if (pos==NoPosSpecified || pos==aLocale.AmPmSymbolPosition())
  1.2262 +				{
  1.2263 +				TBuf<KMaxAmPmName+1> format(_S("%S"));
  1.2264 +				if (!abb && aLocale.AmPmSpaceBetween())
  1.2265 +					{
  1.2266 +					if (aLocale.AmPmSymbolPosition()==ELocaleBefore)
  1.2267 +						format.Append(' ');
  1.2268 +					else
  1.2269 +						{
  1.2270 +						if (aDes.Length()==aDes.MaxLength())
  1.2271 +							User::Leave(KErrOverflow);
  1.2272 +						aDes.Append(' ');
  1.2273 +						}
  1.2274 +					}
  1.2275 +				TAmPmName amPm((dateTime.Hour()<12) ? EAm : EPm);
  1.2276 +				aDes.AppendFormat(format,&overflowLeave,&amPm);
  1.2277 +				}
  1.2278 +			break;
  1.2279 +            }
  1.2280 +		case 'B': // am/pm text if local time format is 12 hour clock
  1.2281 +			if (aLocale.TimeFormat()==ETime24)
  1.2282 +				break;
  1.2283 +			else
  1.2284 +				goto doAmPm;
  1.2285 +		case 'C':
  1.2286 +			{
  1.2287 +			TBuf<6> digits;
  1.2288 +			digits.AppendFormat(_L("%06d"),dateTime.MicroSecond());
  1.2289 +			TUint numChars=6;	// Default length
  1.2290 +			if (abb)
  1.2291 +				{
  1.2292 +				ch=aFmt.Get();
  1.2293 +				if (ch>='0' && ch<='6')
  1.2294 +					{
  1.2295 +					numChars=ch;
  1.2296 +					numChars-='0';
  1.2297 +					}
  1.2298 +				}
  1.2299 +			if (aDes.Length()>(TInt)(aDes.MaxLength()-numChars))
  1.2300 +			    User::Leave(KErrOverflow);
  1.2301 +			aDes.Append(digits.Left(numChars));
  1.2302 +			}	
  1.2303 +			break;
  1.2304 +		case 'D': // day in date
  1.2305 +			if (abb)
  1.2306 +				da=ETrue;
  1.2307 +			if (!fix)
  1.2308 +				break;
  1.2309 +			else
  1.2310 +				{
  1.2311 +doDay:
  1.2312 +				aDes.AppendFormat((da||abb) ? _L("%d"):_L("%02d"),&overflowLeave,dateTime.Day()+1);
  1.2313 +				if (suff)
  1.2314 +doSuffix:
  1.2315 +                    {
  1.2316 +                    TDateSuffix day(dateTime.Day());
  1.2317 +					aDes.AppendFormat(_L("%S"),&overflowLeave,&day);
  1.2318 +                    }
  1.2319 +				break;
  1.2320 +				}
  1.2321 +		case 'E': // Day name
  1.2322 +            {
  1.2323 +			TDay day=DayNoInWeek();
  1.2324 +			if (abb)
  1.2325 +				{
  1.2326 +	            TDayNameAbb nameAbb(day);
  1.2327 +				aDes.AppendFormat(_L("%S"),&overflowLeave,&nameAbb);
  1.2328 +				}
  1.2329 +			else
  1.2330 +				{
  1.2331 +	            TDayName name(day);
  1.2332 +				aDes.AppendFormat(_L("%S"),&overflowLeave,&name);
  1.2333 +				}
  1.2334 +			break;
  1.2335 +            }
  1.2336 +		case 'F': // => user wants day,month,year order fixed
  1.2337 +			fix=ETrue;
  1.2338 +			break;
  1.2339 +		case 'H': // hour in 24 hour time format
  1.2340 +do24:
  1.2341 +			aDes.AppendFormat((abb) ? _L("%d"):_L("%02d"),&overflowLeave,dateTime.Hour());
  1.2342 +			break;
  1.2343 +		case 'I': // hour in 12 hour time format
  1.2344 +do12:
  1.2345 +			{
  1.2346 +			TInt hour=dateTime.Hour();
  1.2347 +			if (hour==0)
  1.2348 +				hour=12;
  1.2349 +			else if (hour>12)
  1.2350 +				hour-=12;
  1.2351 +			aDes.AppendFormat(_L("%d"),&overflowLeave,hour);
  1.2352 +			break;
  1.2353 +			}
  1.2354 +		case 'J': //default time format for hour
  1.2355 +			if (aLocale.TimeFormat()==ETime12)
  1.2356 +				goto do12;
  1.2357 +			else
  1.2358 +				goto do24;
  1.2359 +		case 'M': // month as a number (default value)
  1.2360 +			if (abb)
  1.2361 +				ma=ETrue;
  1.2362 +			if (fix)
  1.2363 +				goto doMonth;
  1.2364 +			break;
  1.2365 +		case 'N': // month as a name
  1.2366 +			mnam=ETrue;
  1.2367 +			if (abb)
  1.2368 +				ma=ETrue;
  1.2369 +			if (!fix)
  1.2370 +				break;
  1.2371 +			else
  1.2372 +				{
  1.2373 +doMonth:
  1.2374 +				if (mnam)
  1.2375 +					{
  1.2376 +					TMonth month=dateTime.Month();
  1.2377 +					if (ma || abb)
  1.2378 +						{
  1.2379 +		                TMonthNameAbb nameAbb(month);
  1.2380 +						aDes.AppendFormat(_L("%S"),&overflowLeave,&nameAbb);
  1.2381 +						}
  1.2382 +					else
  1.2383 +						{
  1.2384 +	                    TMonthName name(month);
  1.2385 +						aDes.AppendFormat(_L("%S"),&overflowLeave,&name);
  1.2386 +						}
  1.2387 +					}
  1.2388 +				else
  1.2389 +					aDes.AppendFormat((ma||abb) ? _L("%d"):_L("%02d"),&overflowLeave,dateTime.Month()+1);
  1.2390 +				break;
  1.2391 +				}
  1.2392 +		case 'S': // seconds
  1.2393 +			aDes.AppendFormat((abb) ? _L("%d"):_L("%02d"),&overflowLeave,dateTime.Second());
  1.2394 +			break;	
  1.2395 +		case 'T': // minutes	
  1.2396 +			aDes.AppendFormat((abb) ? _L("%d"):_L("%02d"),&overflowLeave,dateTime.Minute());
  1.2397 +			break;
  1.2398 +		case 'W': // week no in year
  1.2399 +			aDes.AppendFormat((abb) ? _L("%d"):_L("%02d"),&overflowLeave,WeekNoInYear());
  1.2400 +			break;
  1.2401 +		case 'X': // => wants day suffix
  1.2402 +			if (fix)
  1.2403 +				goto doSuffix;
  1.2404 +			else
  1.2405 +				{
  1.2406 +				suff=ETrue;
  1.2407 +				break;
  1.2408 +				}
  1.2409 +		case 'Y': // year
  1.2410 +			if (abb)
  1.2411 +				ya=ETrue;
  1.2412 +			if (!fix)
  1.2413 +				break;
  1.2414 +			else
  1.2415 +				{
  1.2416 +doYear:
  1.2417 +				if (ya || abb)
  1.2418 +					aDes.AppendFormat(_L("%02d"),&overflowLeave,((dateTime.Year())%100));
  1.2419 +				else
  1.2420 +					aDes.AppendFormat(_L("%04d"),&overflowLeave,dateTime.Year());
  1.2421 +				break;
  1.2422 +				}
  1.2423 +		case 'Z': // day no in year
  1.2424 +			aDes.AppendFormat((abb) ? _L("%d"):_L("%03d"),&overflowLeave,DayNoInYear());
  1.2425 +			break;
  1.2426 +		default:
  1.2427 +doAppend:
  1.2428 +			if (aDes.Length()==aDes.MaxLength())
  1.2429 +				User::Leave(KErrOverflow);
  1.2430 +			aDes.Append(ch);
  1.2431 +			break;
  1.2432 +			}
  1.2433 +		}
  1.2434 +	}
  1.2435 +
  1.2436 +
  1.2437 +
  1.2438 +
  1.2439 +EXPORT_C TTime Time::NullTTime()
  1.2440 +/**
  1.2441 +Gets a TTime with a null value.
  1.2442 +
  1.2443 +@return TTime object with a null value.
  1.2444 +*/
  1.2445 +	{
  1.2446 +	return UI64LIT(0x8000000000000000);
  1.2447 +	}
  1.2448 +
  1.2449 +EXPORT_C TTime Time::MaxTTime()
  1.2450 +/**
  1.2451 +Gets the maximum time value which can be held in a TTime object.
  1.2452 +
  1.2453 +@return The maximum TTime value.
  1.2454 +*/
  1.2455 +	{
  1.2456 +	return I64LIT(0x7fffffffffffffff);
  1.2457 +	}
  1.2458 +
  1.2459 +EXPORT_C TTime Time::MinTTime()
  1.2460 +/**
  1.2461 +Gets the minimum time value which can be held in a TTime object.
  1.2462 +
  1.2463 +@return The minimum TTime value.
  1.2464 +*/
  1.2465 +	{
  1.2466 +	return UI64LIT(0x8000000000000001);
  1.2467 +	}
  1.2468 +
  1.2469 +EXPORT_C TInt Time::DaysInMonth(TInt aYear,TMonth aMonth)
  1.2470 +/**
  1.2471 +Gets the number of days in a month.
  1.2472 +
  1.2473 +@param aYear  The year. Must be specified because of leap years.
  1.2474 +@param aMonth Month, from EJanuary to EDecember.
  1.2475 +
  1.2476 +@return The number of days in the month.
  1.2477 +*/
  1.2478 +	{
  1.2479 +
  1.2480 +    __ASSERT_DEBUG(aMonth<=EDecember && aMonth>=EJanuary,::Panic(ETTimeValueOutOfRange));
  1.2481 +    return(mTab[IsLeapYear(aYear)][aMonth]);
  1.2482 +	}
  1.2483 +
  1.2484 +EXPORT_C TBool Time::IsLeapYear(TInt aYear)
  1.2485 +//
  1.2486 +// up to and including 1600 leap years were every 4 years,since then leap years are every 4 years unless
  1.2487 +// the year falls on a century which is not divisible by 4 (ie 1900 wasnt,2000 will be)
  1.2488 +// for simplicity define year 0 as a leap year
  1.2489 +//
  1.2490 +/**
  1.2491 +Tests whether a year is a leap year.
  1.2492 +
  1.2493 +@param aYear The year of interest.
  1.2494 +
  1.2495 +@return True if leap year, False if not.
  1.2496 +*/
  1.2497 +	{
  1.2498 +
  1.2499 +	if (aYear>1600)
  1.2500 +    	return(!(aYear%4) && (aYear%100 || !(aYear%400)));
  1.2501 +	return(!(aYear%4));
  1.2502 +	}
  1.2503 +
  1.2504 +EXPORT_C TInt Time::LeapYearsUpTo(TInt aYear)
  1.2505 +//
  1.2506 +// from 0AD to present year according to the rule above
  1.2507 +//
  1.2508 +/**
  1.2509 +Gets the number of leap years between 0 AD nominal Gregorian and the specified 
  1.2510 +year - inclusive.
  1.2511 +
  1.2512 +@param aYear The final year in the range to search. If negative, the function 
  1.2513 +             will return a negative number of leap years.
  1.2514 +
  1.2515 +@return The number of leap years between 0 AD nominal Gregorian and aYear.
  1.2516 +*/
  1.2517 +	{
  1.2518 +
  1.2519 +	if (aYear<=0)
  1.2520 +		return(aYear/4);
  1.2521 +	if (aYear<=1600)
  1.2522 +		return(1+((aYear-1)/4));
  1.2523 +	TInt num=401; // 1600/4+1
  1.2524 +	aYear-=1601;
  1.2525 +	TInt century=aYear/100;
  1.2526 +	num+=(aYear/4-century+century/4);
  1.2527 +	return(num);
  1.2528 +	}
  1.2529 +