os/kernelhwsrv/kerneltest/e32test/datetime/t_tparse.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\datetime\t_tparse.cpp
sl@0
    15
// Overview:
sl@0
    16
// Date & time tests
sl@0
    17
// API Information:
sl@0
    18
// TTime, TDateTime
sl@0
    19
// Details:
sl@0
    20
// - Set various locale settings to known values.
sl@0
    21
// - Test parsing a variety of simple time formats. Verify results are as expected.
sl@0
    22
// - Test parsing a variety of simple date formats. Verify results are as expected.
sl@0
    23
// - Test parsing a variety of date and time formats. Verify results are as expected.
sl@0
    24
// - Attempt to parse a variety of bad date and time descriptors. Verify the error 
sl@0
    25
// results are as expected.
sl@0
    26
// - Test a variety of date and time locale changes. Verify results are as expected.
sl@0
    27
// Platforms/Drives/Compatibility:
sl@0
    28
// All.
sl@0
    29
// Assumptions/Requirement/Pre-requisites:
sl@0
    30
// Failures and causes:
sl@0
    31
// Base Port information:
sl@0
    32
// 
sl@0
    33
//
sl@0
    34
sl@0
    35
#include <e32test.h>
sl@0
    36
sl@0
    37
RTest test(_L("T_TPARSE"));
sl@0
    38
sl@0
    39
LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=0)
sl@0
    40
	{
sl@0
    41
sl@0
    42
	TTime time;
sl@0
    43
	TInt r=time.Parse(aDes,aCenturyOffset);
sl@0
    44
	if (r>=0)
sl@0
    45
		aDateTime=time.DateTime();
sl@0
    46
	return r;
sl@0
    47
	}
sl@0
    48
sl@0
    49
LOCAL_D void SimpleTimeFormats()
sl@0
    50
	{
sl@0
    51
sl@0
    52
	TInt error;
sl@0
    53
	TDateTime dateTime;
sl@0
    54
	error=DateTimeParse(dateTime,_L("23:34:45:56"));
sl@0
    55
	test(error==EParseTimePresent);
sl@0
    56
	test(dateTime.Hour()==23);
sl@0
    57
	test(dateTime.Minute()==34);
sl@0
    58
	test(dateTime.Second()==45);
sl@0
    59
	test(dateTime.MicroSecond()==56);
sl@0
    60
sl@0
    61
	error=DateTimeParse(dateTime,_L("23:34:45.56"));
sl@0
    62
	test(error==EParseTimePresent);
sl@0
    63
	test(dateTime.Hour()==23);
sl@0
    64
	test(dateTime.Minute()==34);
sl@0
    65
	test(dateTime.Second()==45);
sl@0
    66
	test(dateTime.MicroSecond()==56);
sl@0
    67
sl@0
    68
	error=DateTimeParse(dateTime,_L("23:34:45.1234567"));
sl@0
    69
	test(error==KErrGeneral);
sl@0
    70
sl@0
    71
	error=DateTimeParse(dateTime,_L("23:34:45"));
sl@0
    72
	test(error==EParseTimePresent);
sl@0
    73
	test(dateTime.Hour()==23);
sl@0
    74
	test(dateTime.Minute()==34);
sl@0
    75
	test(dateTime.Second()==45);
sl@0
    76
	test(dateTime.MicroSecond()==0);
sl@0
    77
sl@0
    78
	error=DateTimeParse(dateTime,_L("00023:00034"));
sl@0
    79
	test(error==EParseTimePresent);
sl@0
    80
	test(dateTime.Hour()==23);
sl@0
    81
	test(dateTime.Minute()==34);
sl@0
    82
	test(dateTime.Second()==00);
sl@0
    83
	test(dateTime.MicroSecond()==0);
sl@0
    84
sl@0
    85
	error=DateTimeParse(dateTime,_L("23: 34"));
sl@0
    86
	test(error==EParseTimePresent);
sl@0
    87
	test(dateTime.Hour()==23);
sl@0
    88
	test(dateTime.Minute()==34);
sl@0
    89
	test(dateTime.Second()==0);
sl@0
    90
	test(dateTime.MicroSecond()==0);
sl@0
    91
sl@0
    92
	error=DateTimeParse(dateTime,_L("23: 34am"));
sl@0
    93
	test(error==EParseTimePresent);
sl@0
    94
	test(dateTime.Hour()==23);
sl@0
    95
	test(dateTime.Minute()==34);
sl@0
    96
	test(dateTime.Second()==0);
sl@0
    97
	test(dateTime.MicroSecond()==0);
sl@0
    98
sl@0
    99
	error=DateTimeParse(dateTime,_L("23: 34AM"));
sl@0
   100
	test(error==EParseTimePresent);
sl@0
   101
	test(dateTime.Hour()==23);
sl@0
   102
	test(dateTime.Minute()==34);
sl@0
   103
	test(dateTime.Second()==0);
sl@0
   104
	test(dateTime.MicroSecond()==0);
sl@0
   105
sl@0
   106
	error=DateTimeParse(dateTime,_L("     23  : 34   "));
sl@0
   107
	test(error==EParseTimePresent);
sl@0
   108
	test(dateTime.Hour()==23);
sl@0
   109
	test(dateTime.Minute()==34);
sl@0
   110
	test(dateTime.Second()==0);
sl@0
   111
	test(dateTime.MicroSecond()==0);
sl@0
   112
sl@0
   113
	DateTimeParse(dateTime,_L("12    .    34"));
sl@0
   114
	test(dateTime.Hour()==12);
sl@0
   115
	test(dateTime.Minute()==34);
sl@0
   116
sl@0
   117
	error=DateTimeParse(dateTime,_L("23:34:"));
sl@0
   118
	test(error==KErrArgument);
sl@0
   119
sl@0
   120
	error=DateTimeParse(dateTime,_L("   0012    : 00034  .    056"));
sl@0
   121
	test(error==EParseTimePresent);
sl@0
   122
	test(dateTime.Hour()==12);
sl@0
   123
	test(dateTime.Minute()==34);
sl@0
   124
	test(dateTime.Second()==56);
sl@0
   125
	test(dateTime.MicroSecond()==0);
sl@0
   126
sl@0
   127
	error=DateTimeParse(dateTime,_L("24    :    56"));
sl@0
   128
	test(error==KErrGeneral);// TDateTime class does not allow 24:56
sl@0
   129
sl@0
   130
	error=DateTimeParse(dateTime,_L("10"));
sl@0
   131
	test(error==KErrArgument);
sl@0
   132
sl@0
   133
	error=DateTimeParse(dateTime,_L("10a"));
sl@0
   134
	test(error==EParseTimePresent);
sl@0
   135
	test(dateTime.Hour()==10);
sl@0
   136
sl@0
   137
	error=DateTimeParse(dateTime,_L("10p"));
sl@0
   138
	test(error==EParseTimePresent);
sl@0
   139
	test(dateTime.Hour()==22);
sl@0
   140
sl@0
   141
	error=DateTimeParse(dateTime,_L("10 p"));
sl@0
   142
	test(error==EParseTimePresent);
sl@0
   143
	test(dateTime.Hour()==22);
sl@0
   144
sl@0
   145
	error=DateTimeParse(dateTime,_L("10pm "));
sl@0
   146
	test(error==EParseTimePresent);
sl@0
   147
	test(dateTime.Hour()==22);
sl@0
   148
sl@0
   149
	error=DateTimeParse(dateTime,_L("10 pm"));
sl@0
   150
	test(error==EParseTimePresent);
sl@0
   151
	test(dateTime.Hour()==22);
sl@0
   152
sl@0
   153
	error=DateTimeParse(dateTime,_L("10 AM"));
sl@0
   154
	test(error==EParseTimePresent);
sl@0
   155
	test(dateTime.Hour()==10);
sl@0
   156
sl@0
   157
	error=DateTimeParse(dateTime,_L("10 PM"));
sl@0
   158
	test(error==EParseTimePresent);
sl@0
   159
	test(dateTime.Hour()==22);
sl@0
   160
sl@0
   161
	error=DateTimeParse(dateTime,_L("10pmERROR"));
sl@0
   162
	test(error==KErrArgument);
sl@0
   163
sl@0
   164
	DateTimeParse(dateTime,_L("12 : 56 pm"));
sl@0
   165
	test(dateTime.Hour()==12);
sl@0
   166
	test(dateTime.Minute()==56);
sl@0
   167
sl@0
   168
	DateTimeParse(dateTime,_L("12 : 56 am "));
sl@0
   169
	test(dateTime.Hour()==0);
sl@0
   170
	test(dateTime.Minute()==56);
sl@0
   171
sl@0
   172
	DateTimeParse(dateTime,_L("12.34.56am"));
sl@0
   173
	test(dateTime.Hour()==0);
sl@0
   174
	test(dateTime.Minute()==34);
sl@0
   175
	test(dateTime.Second()==56);
sl@0
   176
sl@0
   177
	DateTimeParse(dateTime,_L("12.34.56pm "));
sl@0
   178
	test(dateTime.Hour()==12);
sl@0
   179
	test(dateTime.Minute()==34);
sl@0
   180
	test(dateTime.Second()==56);
sl@0
   181
	test(dateTime.MicroSecond()==0);
sl@0
   182
sl@0
   183
	error=DateTimeParse(dateTime,_L("12:34:56am  ERROR"));
sl@0
   184
	test(error==KErrArgument);
sl@0
   185
sl@0
   186
	error=DateTimeParse(dateTime,_L("12 : 56 am 05/jan/1996 "));
sl@0
   187
	test(error==(EParseTimePresent|EParseDatePresent));
sl@0
   188
	test(dateTime.Hour()==0);
sl@0
   189
	test(dateTime.Minute()==56);
sl@0
   190
	}
sl@0
   191
sl@0
   192
LOCAL_D void SimpleDateFormats()
sl@0
   193
	{
sl@0
   194
	TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0);
sl@0
   195
	TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0);
sl@0
   196
	TTime before2000(before2000DateTime);
sl@0
   197
	TTime after2000(after2000DateTime);
sl@0
   198
	
sl@0
   199
	for (TInt ii=0;ii<=1;ii++)
sl@0
   200
		{
sl@0
   201
		TBool currentTimeIsBeforeYear2000=ETrue;
sl@0
   202
		if (ii==0)
sl@0
   203
			{
sl@0
   204
			User::SetUTCTime(before2000);
sl@0
   205
			currentTimeIsBeforeYear2000=ETrue;
sl@0
   206
			}
sl@0
   207
		else if (ii==1)
sl@0
   208
			{
sl@0
   209
			User::SetUTCTime(after2000);
sl@0
   210
			currentTimeIsBeforeYear2000=EFalse;
sl@0
   211
			}
sl@0
   212
		TInt error;
sl@0
   213
		TDateTime dateTime;
sl@0
   214
		DateTimeParse(dateTime,_L("5/6/1996"));
sl@0
   215
		test(dateTime.Day()==4);
sl@0
   216
		test(dateTime.Month()==EJune);
sl@0
   217
		test(dateTime.Year()==1996);
sl@0
   218
sl@0
   219
		DateTimeParse(dateTime,_L("5-6,1996"));
sl@0
   220
		test(dateTime.Day()==4);
sl@0
   221
		test(dateTime.Month()==EJune);
sl@0
   222
		test(dateTime.Year()==1996);
sl@0
   223
sl@0
   224
		DateTimeParse(dateTime,_L("5 6 1996"));
sl@0
   225
		test(dateTime.Day()==4);
sl@0
   226
		test(dateTime.Month()==EJune);
sl@0
   227
		test(dateTime.Year()==1996);
sl@0
   228
sl@0
   229
		DateTimeParse(dateTime,_L("5  ;  6     1996"));
sl@0
   230
		test(dateTime.Day()==4);
sl@0
   231
		test(dateTime.Month()==EJune);
sl@0
   232
		test(dateTime.Year()==1996);
sl@0
   233
sl@0
   234
		
sl@0
   235
		DateTimeParse(dateTime,_L("5 / 6, 96 "));
sl@0
   236
		test(dateTime.Day()==4);
sl@0
   237
		test(dateTime.Month()==EJune);
sl@0
   238
		if (currentTimeIsBeforeYear2000) 
sl@0
   239
			test(dateTime.Year()==1996);
sl@0
   240
		else
sl@0
   241
			test(dateTime.Year()==2096);
sl@0
   242
sl@0
   243
		DateTimeParse(dateTime,_L("5/6/19 "),20);
sl@0
   244
		test(dateTime.Day()==4);
sl@0
   245
		test(dateTime.Month()==EJune);
sl@0
   246
		test(dateTime.Year()==2019);
sl@0
   247
sl@0
   248
		DateTimeParse(dateTime,_L("5/6/20 "),20);
sl@0
   249
		test(dateTime.Day()==4);
sl@0
   250
		test(dateTime.Month()==EJune);
sl@0
   251
		test(dateTime.Year()==1920);
sl@0
   252
sl@0
   253
		DateTimeParse(dateTime,_L("5/6/00"),20);
sl@0
   254
		test(dateTime.Day()==4);
sl@0
   255
		test(dateTime.Month()==EJune);
sl@0
   256
		test(dateTime.Year()==2000);
sl@0
   257
sl@0
   258
		error=DateTimeParse(dateTime,_L("5/6/00  "),00);
sl@0
   259
		test(error==EParseDatePresent);
sl@0
   260
		test(dateTime.Day()==4);
sl@0
   261
		test(dateTime.Month()==EJune);
sl@0
   262
		if (currentTimeIsBeforeYear2000) 
sl@0
   263
			test(dateTime.Year()==1900);
sl@0
   264
		else
sl@0
   265
			test(dateTime.Year()==2000);
sl@0
   266
sl@0
   267
		error=DateTimeParse(dateTime,_L("june 5 /00  "),00);
sl@0
   268
		test(error==EParseDatePresent);
sl@0
   269
		test(dateTime.Day()==4);
sl@0
   270
		test(dateTime.Month()==EJune);
sl@0
   271
		if (currentTimeIsBeforeYear2000) 
sl@0
   272
			test(dateTime.Year()==1900);
sl@0
   273
		else
sl@0
   274
			test(dateTime.Year()==2000);
sl@0
   275
sl@0
   276
		error=DateTimeParse(dateTime,_L("5 june/00  "),00);
sl@0
   277
		test(error==EParseDatePresent);
sl@0
   278
		test(dateTime.Day()==4);
sl@0
   279
		test(dateTime.Month()==EJune);
sl@0
   280
		if (currentTimeIsBeforeYear2000) 
sl@0
   281
			test(dateTime.Year()==1900);
sl@0
   282
		else
sl@0
   283
			test(dateTime.Year()==2000);
sl@0
   284
sl@0
   285
		error=DateTimeParse(dateTime,_L("5june 96  "),00);
sl@0
   286
		test(error==KErrArgument);
sl@0
   287
sl@0
   288
		// two field dates
sl@0
   289
sl@0
   290
		error=DateTimeParse(dateTime,_L("5/6"));
sl@0
   291
		test(error==EParseDatePresent);
sl@0
   292
		test(dateTime.Day()==4);
sl@0
   293
		test(dateTime.Month()==EJune);
sl@0
   294
		test(dateTime.Year()==0);
sl@0
   295
sl@0
   296
		error=DateTimeParse(dateTime,_L("5-6,"));
sl@0
   297
		test(error==KErrArgument);
sl@0
   298
sl@0
   299
		error=DateTimeParse(dateTime,_L("5/6/ "),20);
sl@0
   300
		test(error==KErrArgument);
sl@0
   301
sl@0
   302
		error=DateTimeParse(dateTime,_L("july 11"),20);
sl@0
   303
		test(error==EParseDatePresent);
sl@0
   304
		test(dateTime.Day()==10);
sl@0
   305
		test(dateTime.Month()==EJuly);
sl@0
   306
		test(dateTime.Year()==0);
sl@0
   307
sl@0
   308
		error=DateTimeParse(dateTime,_L("11 july"),20);
sl@0
   309
		test(error==EParseDatePresent);
sl@0
   310
		test(dateTime.Day()==10);
sl@0
   311
		test(dateTime.Month()==EJuly);
sl@0
   312
		test(dateTime.Year()==0);
sl@0
   313
sl@0
   314
		error=DateTimeParse(dateTime,_L("june 5  "),00);
sl@0
   315
		test(error==EParseDatePresent);
sl@0
   316
		test(dateTime.Day()==4);
sl@0
   317
		test(dateTime.Month()==EJune);
sl@0
   318
		test(dateTime.Year()==0);
sl@0
   319
sl@0
   320
		error=DateTimeParse(dateTime,_L("5 june/  "),00);
sl@0
   321
		test(error==KErrArgument);
sl@0
   322
sl@0
   323
		error=DateTimeParse(dateTime,_L("5june  "),00);
sl@0
   324
		test(error==KErrArgument);
sl@0
   325
sl@0
   326
		DateTimeParse(dateTime,_L("5/6/1"));
sl@0
   327
		if (currentTimeIsBeforeYear2000) 
sl@0
   328
			test(dateTime.Year()==1901);
sl@0
   329
		else
sl@0
   330
			test(dateTime.Year()==2001);
sl@0
   331
		DateTimeParse(dateTime,_L("5/6/01"));
sl@0
   332
		if (currentTimeIsBeforeYear2000) 
sl@0
   333
			test(dateTime.Year()==1901);
sl@0
   334
		else
sl@0
   335
			test(dateTime.Year()==2001);
sl@0
   336
		DateTimeParse(dateTime,_L("5/6/001"));
sl@0
   337
		test(dateTime.Year()==0001);		
sl@0
   338
		DateTimeParse(dateTime,_L("5/6/0001"));
sl@0
   339
		test(dateTime.Year()==0001);		
sl@0
   340
		}
sl@0
   341
	}
sl@0
   342
sl@0
   343
LOCAL_D void DateTimeFormats()
sl@0
   344
	{
sl@0
   345
	TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0);
sl@0
   346
	TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0);
sl@0
   347
	TTime before2000(before2000DateTime);
sl@0
   348
	TTime after2000(after2000DateTime);
sl@0
   349
	
sl@0
   350
	for (TInt ii=0;ii<=1;ii++)
sl@0
   351
		{
sl@0
   352
		TBool currentTimeIsBeforeYear2000=ETrue;
sl@0
   353
		if (ii==0)
sl@0
   354
			{
sl@0
   355
			User::SetUTCTime(before2000);
sl@0
   356
			currentTimeIsBeforeYear2000=ETrue;
sl@0
   357
			}
sl@0
   358
		else if (ii==1)
sl@0
   359
			{
sl@0
   360
			User::SetUTCTime(after2000);
sl@0
   361
			currentTimeIsBeforeYear2000=EFalse;
sl@0
   362
			}
sl@0
   363
		TInt error;
sl@0
   364
		TDateTime dateTime;
sl@0
   365
		error=DateTimeParse(dateTime,_L("5/6/1996 10am"));
sl@0
   366
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   367
		test(dateTime.Day()==4);
sl@0
   368
		test(dateTime.Month()==EJune);
sl@0
   369
		test(dateTime.Year()==1996);
sl@0
   370
		test(dateTime.Hour()==10);
sl@0
   371
sl@0
   372
		error=DateTimeParse(dateTime,_L("5/6/1996 10 pm "));
sl@0
   373
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   374
		test(dateTime.Day()==4);
sl@0
   375
		test(dateTime.Month()==EJune);
sl@0
   376
		test(dateTime.Year()==1996);
sl@0
   377
		test(dateTime.Hour()==22);
sl@0
   378
sl@0
   379
		error=DateTimeParse(dateTime,_L("5/6/1996 10 : 30  "));
sl@0
   380
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   381
		test(dateTime.Day()==4);
sl@0
   382
		test(dateTime.Month()==EJune);
sl@0
   383
		test(dateTime.Year()==1996);
sl@0
   384
		test(dateTime.Hour()==10);
sl@0
   385
		test(dateTime.Minute()==30);
sl@0
   386
sl@0
   387
		error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 pm  "));
sl@0
   388
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   389
		test(dateTime.Day()==4);
sl@0
   390
		test(dateTime.Month()==EJune);
sl@0
   391
		test(dateTime.Year()==1996);
sl@0
   392
		test(dateTime.Hour()==22);
sl@0
   393
		test(dateTime.Minute()==40);
sl@0
   394
sl@0
   395
		error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 "));
sl@0
   396
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   397
		test(dateTime.Day()==4);
sl@0
   398
		test(dateTime.Month()==EJune);
sl@0
   399
		test(dateTime.Year()==1996);
sl@0
   400
		test(dateTime.Hour()==10);
sl@0
   401
		test(dateTime.Minute()==40);
sl@0
   402
		test(dateTime.Second()==01);
sl@0
   403
		test(dateTime.MicroSecond()==0);
sl@0
   404
sl@0
   405
		error=DateTimeParse(dateTime,_L("5-6 ,1996    10 : 40 . 01 pm "));
sl@0
   406
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   407
		test(dateTime.Day()==4);
sl@0
   408
		test(dateTime.Month()==EJune);
sl@0
   409
		test(dateTime.Year()==1996);
sl@0
   410
		test(dateTime.Hour()==22);
sl@0
   411
		test(dateTime.Minute()==40);
sl@0
   412
		test(dateTime.Second()==01);
sl@0
   413
		test(dateTime.MicroSecond()==0);
sl@0
   414
sl@0
   415
		error=DateTimeParse(dateTime,_L("20- feb /96    12 : 40 . 01 am"));
sl@0
   416
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   417
		test(dateTime.Day()==19);
sl@0
   418
		test(dateTime.Month()==EFebruary);
sl@0
   419
		test(dateTime.Hour()==0);
sl@0
   420
		test(dateTime.Minute()==40);
sl@0
   421
		test(dateTime.Second()==01);
sl@0
   422
		test(dateTime.MicroSecond()==0);
sl@0
   423
		if (currentTimeIsBeforeYear2000) 
sl@0
   424
			test(dateTime.Year()==1996);
sl@0
   425
		else
sl@0
   426
			test(dateTime.Year()==2096);
sl@0
   427
sl@0
   428
		error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 . 02 "));
sl@0
   429
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   430
		test(dateTime.Day()==4);
sl@0
   431
		test(dateTime.Month()==EJune);
sl@0
   432
		test(dateTime.Year()==1996);
sl@0
   433
		test(dateTime.Hour()==10);
sl@0
   434
		test(dateTime.Minute()==40);
sl@0
   435
		test(dateTime.Second()==01);
sl@0
   436
		test(dateTime.MicroSecond()==2);
sl@0
   437
sl@0
   438
		error=DateTimeParse(dateTime,_L("5-6 ,1996    10 : 40 . 01 . 03 pm "));
sl@0
   439
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   440
		test(dateTime.Day()==4);
sl@0
   441
		test(dateTime.Month()==EJune);
sl@0
   442
		test(dateTime.Year()==1996);
sl@0
   443
		test(dateTime.Hour()==22);
sl@0
   444
		test(dateTime.Minute()==40);
sl@0
   445
		test(dateTime.Second()==01);
sl@0
   446
		test(dateTime.MicroSecond()==3);
sl@0
   447
sl@0
   448
		error=DateTimeParse(dateTime,_L("20- feb /96    12 : 40 . 01 . 04 am"));
sl@0
   449
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   450
		test(dateTime.Day()==19);
sl@0
   451
		test(dateTime.Month()==EFebruary);
sl@0
   452
		test(dateTime.Hour()==0);
sl@0
   453
		test(dateTime.Minute()==40);
sl@0
   454
		test(dateTime.Second()==01);
sl@0
   455
		test(dateTime.MicroSecond()==4);
sl@0
   456
		if (currentTimeIsBeforeYear2000) 
sl@0
   457
			test(dateTime.Year()==1996);
sl@0
   458
		else
sl@0
   459
			test(dateTime.Year()==2096);
sl@0
   460
sl@0
   461
		error=DateTimeParse(dateTime,_L("20- feb /9612 : 40.01am"));
sl@0
   462
		test(error==KErrGeneral);
sl@0
   463
sl@0
   464
		// two field dates
sl@0
   465
sl@0
   466
		error=DateTimeParse(dateTime,_L("5/6 10am"));
sl@0
   467
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   468
		test(dateTime.Day()==4);
sl@0
   469
		test(dateTime.Month()==EJune);
sl@0
   470
		test(dateTime.Year()==0);
sl@0
   471
		test(dateTime.Hour()==10);
sl@0
   472
sl@0
   473
		error=DateTimeParse(dateTime,_L("5/6/ 10 pm "));
sl@0
   474
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   475
		test(dateTime.Day()==4);
sl@0
   476
		test(dateTime.Month()==EJune);
sl@0
   477
		test(dateTime.Year()==0);
sl@0
   478
		test(dateTime.Hour()==22);
sl@0
   479
sl@0
   480
		error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 "));
sl@0
   481
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   482
		test(dateTime.Day()==4);
sl@0
   483
		test(dateTime.Month()==EJune);
sl@0
   484
		test(dateTime.Year()==0);
sl@0
   485
		test(dateTime.Hour()==10);
sl@0
   486
		test(dateTime.Minute()==40);
sl@0
   487
		test(dateTime.Second()==01);
sl@0
   488
		test(dateTime.MicroSecond()==0);
sl@0
   489
sl@0
   490
		error=DateTimeParse(dateTime,_L("5-6 ,    10 : 40 . 01 pm "));
sl@0
   491
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   492
		test(dateTime.Day()==4);
sl@0
   493
		test(dateTime.Month()==EJune);
sl@0
   494
		test(dateTime.Year()==0);
sl@0
   495
		test(dateTime.Hour()==22);
sl@0
   496
		test(dateTime.Minute()==40);
sl@0
   497
		test(dateTime.Second()==01);
sl@0
   498
		test(dateTime.MicroSecond()==0);
sl@0
   499
sl@0
   500
		error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 . 02"));
sl@0
   501
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   502
		test(dateTime.Day()==4);
sl@0
   503
		test(dateTime.Month()==EJune);
sl@0
   504
		test(dateTime.Year()==0);
sl@0
   505
		test(dateTime.Hour()==10);
sl@0
   506
		test(dateTime.Minute()==40);
sl@0
   507
		test(dateTime.Second()==01);
sl@0
   508
		test(dateTime.MicroSecond()==2);
sl@0
   509
sl@0
   510
		error=DateTimeParse(dateTime,_L("5-6 ,    10 : 40 . 01 . 05pm "));
sl@0
   511
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   512
		test(dateTime.Day()==4);
sl@0
   513
		test(dateTime.Month()==EJune);
sl@0
   514
		test(dateTime.Year()==0);
sl@0
   515
		test(dateTime.Hour()==22);
sl@0
   516
		test(dateTime.Minute()==40);
sl@0
   517
		test(dateTime.Second()==01);
sl@0
   518
		test(dateTime.MicroSecond()==5);
sl@0
   519
sl@0
   520
		}
sl@0
   521
	}
sl@0
   522
sl@0
   523
LOCAL_D void TimeDateFormats()
sl@0
   524
	{
sl@0
   525
	TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0);
sl@0
   526
	TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0);
sl@0
   527
	TTime before2000(before2000DateTime);
sl@0
   528
	TTime after2000(after2000DateTime);
sl@0
   529
	
sl@0
   530
	for (TInt ii=0;ii<=1;ii++)
sl@0
   531
		{
sl@0
   532
		TBool currentTimeIsBeforeYear2000=ETrue;
sl@0
   533
		if (ii==0)
sl@0
   534
			{
sl@0
   535
			User::SetUTCTime(before2000);
sl@0
   536
			currentTimeIsBeforeYear2000=ETrue;
sl@0
   537
			}
sl@0
   538
		else if (ii==1)
sl@0
   539
			{
sl@0
   540
			User::SetUTCTime(after2000);
sl@0
   541
			currentTimeIsBeforeYear2000=EFalse;
sl@0
   542
			}
sl@0
   543
		TInt error;
sl@0
   544
		TDateTime dateTime;
sl@0
   545
		error=DateTimeParse(dateTime,_L("10pm 5/6/96"));
sl@0
   546
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   547
		test(dateTime.Hour()==22);
sl@0
   548
		test(dateTime.Day()==4);
sl@0
   549
		test(dateTime.Month()==EJune);
sl@0
   550
		if (currentTimeIsBeforeYear2000) 
sl@0
   551
			test(dateTime.Year()==1996);
sl@0
   552
		else
sl@0
   553
			test(dateTime.Year()==2096);
sl@0
   554
sl@0
   555
sl@0
   556
		error=DateTimeParse(dateTime,_L("12 am  5 -feb,03 "));
sl@0
   557
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   558
		test(dateTime.Hour()==00);
sl@0
   559
		test(dateTime.Day()==4);
sl@0
   560
		test(dateTime.Month()==EFebruary);
sl@0
   561
		if (currentTimeIsBeforeYear2000) 
sl@0
   562
			test(dateTime.Year()==1903);
sl@0
   563
		else
sl@0
   564
			test(dateTime.Year()==2003);
sl@0
   565
sl@0
   566
		error=DateTimeParse(dateTime,_L("12 .56am  5 -feb,03 "));
sl@0
   567
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   568
		test(dateTime.Hour()==00);
sl@0
   569
		test(dateTime.Minute()==56);
sl@0
   570
		test(dateTime.Day()==4);
sl@0
   571
		test(dateTime.Month()==EFebruary);
sl@0
   572
		if (currentTimeIsBeforeYear2000) 
sl@0
   573
			test(dateTime.Year()==1903);
sl@0
   574
		else
sl@0
   575
			test(dateTime.Year()==2003);
sl@0
   576
sl@0
   577
		error=DateTimeParse(dateTime,_L("12 .56:01.03pm  5 -SEPTEMBER,03 "));
sl@0
   578
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   579
		test(dateTime.Hour()==12);
sl@0
   580
		test(dateTime.Minute()==56);
sl@0
   581
		test(dateTime.Second()==01);
sl@0
   582
		test(dateTime.MicroSecond()==03);
sl@0
   583
		test(dateTime.Day()==4);
sl@0
   584
		test(dateTime.Month()==ESeptember);
sl@0
   585
		if (currentTimeIsBeforeYear2000) 
sl@0
   586
			test(dateTime.Year()==1903);
sl@0
   587
		else
sl@0
   588
			test(dateTime.Year()==2003);
sl@0
   589
sl@0
   590
sl@0
   591
		error=DateTimeParse(dateTime,_L("12 .56:01pm  SEPTEMBER 5,03 "));
sl@0
   592
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   593
		test(dateTime.Hour()==12);
sl@0
   594
		test(dateTime.Minute()==56);
sl@0
   595
		test(dateTime.Second()==01);
sl@0
   596
		test(dateTime.Day()==4);
sl@0
   597
		test(dateTime.Month()==ESeptember);
sl@0
   598
		if (currentTimeIsBeforeYear2000) 
sl@0
   599
			test(dateTime.Year()==1903);
sl@0
   600
		else
sl@0
   601
			test(dateTime.Year()==2003);
sl@0
   602
sl@0
   603
sl@0
   604
		error=DateTimeParse(dateTime,_L("12 .0056:01pm  5 -SEPTEMBERX,03 "));
sl@0
   605
		test(error==KErrArgument);
sl@0
   606
sl@0
   607
		error=DateTimeParse(dateTime,_L("12 .56:015 -SEPTEMBER,03 "));
sl@0
   608
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   609
		test(dateTime.Hour()==12);
sl@0
   610
		test(dateTime.Minute()==56);
sl@0
   611
		test(dateTime.Second()==15);
sl@0
   612
		test(dateTime.Day()==2);
sl@0
   613
		test(dateTime.Month()==ESeptember);
sl@0
   614
		test(dateTime.Year()==0);
sl@0
   615
		
sl@0
   616
		// max descriptor length 27 tokens// 13 tokens after spaces are striped
sl@0
   617
		error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 . 123456 pm 5 / 6 / 96 "));
sl@0
   618
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   619
		test(dateTime.MicroSecond()==123456);
sl@0
   620
		test(dateTime.Second()==0);
sl@0
   621
		test(dateTime.Minute()==0);
sl@0
   622
		test(dateTime.Hour()==22);
sl@0
   623
		test(dateTime.Day()==4);
sl@0
   624
		test(dateTime.Month()==EJune);
sl@0
   625
		if (currentTimeIsBeforeYear2000) 
sl@0
   626
			test(dateTime.Year()==1996);
sl@0
   627
		else
sl@0
   628
			test(dateTime.Year()==2096);
sl@0
   629
sl@0
   630
		
sl@0
   631
		// the formaula array will overflow with too many tokens
sl@0
   632
		error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 pm 5 / 6 / 96 / / / / / / / / / / / / / / / "));
sl@0
   633
		test(error==KErrArgument);
sl@0
   634
		}
sl@0
   635
	}
sl@0
   636
sl@0
   637
LOCAL_D void BadDescriptors()
sl@0
   638
	{
sl@0
   639
sl@0
   640
	TInt error;
sl@0
   641
	TDateTime dateTime;
sl@0
   642
	error=DateTimeParse(dateTime,_L("10pmpm"));
sl@0
   643
	test(error==KErrArgument);
sl@0
   644
sl@0
   645
	error=DateTimeParse(dateTime,_L("10pmX"));
sl@0
   646
	test(error==KErrArgument);
sl@0
   647
sl@0
   648
	error=DateTimeParse(dateTime,_L("1111"));
sl@0
   649
	test(error==KErrArgument);
sl@0
   650
sl@0
   651
	error=DateTimeParse(dateTime,_L("10::10"));
sl@0
   652
	test(error==KErrGeneral);
sl@0
   653
sl@0
   654
	error=DateTimeParse(dateTime,_L("10-,10"));
sl@0
   655
	test(error==KErrArgument);
sl@0
   656
sl@0
   657
	error=DateTimeParse(dateTime,_L("   -  10:10"));
sl@0
   658
	test(error==KErrArgument);
sl@0
   659
sl@0
   660
	error=DateTimeParse(dateTime,_L(" 10  10:10"));
sl@0
   661
	test(error==KErrArgument);
sl@0
   662
sl@0
   663
	error=DateTimeParse(dateTime,_L(" 5 june 10000"));
sl@0
   664
	test(error==KErrArgument);
sl@0
   665
sl@0
   666
	error=DateTimeParse(dateTime,_L("24:01"));
sl@0
   667
	test(error==KErrGeneral);
sl@0
   668
sl@0
   669
	error=DateTimeParse(dateTime,_L("may 2, 9623:34:45"));
sl@0
   670
	test(error==KErrGeneral);
sl@0
   671
sl@0
   672
	error=DateTimeParse(dateTime,_L(" 9/10/- "));
sl@0
   673
	test(error==KErrArgument);
sl@0
   674
	}
sl@0
   675
sl@0
   676
LOCAL_D void TestLocaleChanges()
sl@0
   677
	{
sl@0
   678
	TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0);
sl@0
   679
	TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0);
sl@0
   680
	TTime before2000(before2000DateTime);
sl@0
   681
	TTime after2000(after2000DateTime);
sl@0
   682
	
sl@0
   683
	for (TInt ii=0;ii<=1;ii++)
sl@0
   684
		{
sl@0
   685
		TBool currentTimeIsBeforeYear2000=ETrue;
sl@0
   686
		if (ii==0)
sl@0
   687
			{
sl@0
   688
			User::SetUTCTime(before2000);
sl@0
   689
			currentTimeIsBeforeYear2000=ETrue;
sl@0
   690
			}
sl@0
   691
		else if (ii==1)
sl@0
   692
			{
sl@0
   693
			User::SetUTCTime(after2000);
sl@0
   694
			currentTimeIsBeforeYear2000=EFalse;
sl@0
   695
			}
sl@0
   696
		TLocale locale;
sl@0
   697
		locale.Refresh();
sl@0
   698
		TLocale savedLocale;
sl@0
   699
		TInt error;
sl@0
   700
		TDateTime dateTime;
sl@0
   701
sl@0
   702
		//Set decimal separator in locale to another value:
sl@0
   703
		locale.SetDecimalSeparator('!');
sl@0
   704
		locale.Set();
sl@0
   705
		error=DateTimeParse(dateTime,_L("3/6 10:10:10!111111"));
sl@0
   706
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   707
		test(dateTime.MicroSecond()==111111);
sl@0
   708
		test(dateTime.Second()==10);
sl@0
   709
		test(dateTime.Minute()==10);
sl@0
   710
		test(dateTime.Hour()==10);
sl@0
   711
		test(dateTime.Day()==2);
sl@0
   712
		test(dateTime.Month()==EJune);
sl@0
   713
				
sl@0
   714
		error=DateTimeParse(dateTime,_L("1/6/12"));
sl@0
   715
		test(error==EParseDatePresent);
sl@0
   716
		test(dateTime.Second()==0);
sl@0
   717
		test(dateTime.Minute()==0);
sl@0
   718
		test(dateTime.Hour()==0);
sl@0
   719
		test(dateTime.Day()==0);
sl@0
   720
		test(dateTime.Month()==EJune);
sl@0
   721
		if (currentTimeIsBeforeYear2000) 
sl@0
   722
			test(dateTime.Year()==1912);
sl@0
   723
		else
sl@0
   724
			test(dateTime.Year()==2012);
sl@0
   725
sl@0
   726
		error=DateTimeParse(dateTime,_L(" dec  3 12"),10);
sl@0
   727
		test(error==EParseDatePresent);
sl@0
   728
		test(dateTime.Second()==0);
sl@0
   729
		test(dateTime.Minute()==0);
sl@0
   730
		test(dateTime.Hour()==0);
sl@0
   731
		test(dateTime.Day()==2);
sl@0
   732
		test(dateTime.Month()==EDecember);
sl@0
   733
		if (currentTimeIsBeforeYear2000) 
sl@0
   734
			test(dateTime.Year()==1912);
sl@0
   735
		else
sl@0
   736
			test(dateTime.Year()==1912);
sl@0
   737
sl@0
   738
		error=DateTimeParse(dateTime,_L(" 3 dec 12 "),12);
sl@0
   739
		test(error==EParseDatePresent);
sl@0
   740
		test(dateTime.Second()==0);
sl@0
   741
		test(dateTime.Minute()==0);
sl@0
   742
		test(dateTime.Hour()==0);
sl@0
   743
		test(dateTime.Day()==2);
sl@0
   744
		test(dateTime.Month()==EDecember);
sl@0
   745
		if (currentTimeIsBeforeYear2000) 
sl@0
   746
			test(dateTime.Year()==1912);
sl@0
   747
		else
sl@0
   748
			test(dateTime.Year()==1912);
sl@0
   749
sl@0
   750
		TDateFormat dateFormat=EDateAmerican;
sl@0
   751
		locale.SetDateFormat(dateFormat);
sl@0
   752
		locale.Set();
sl@0
   753
sl@0
   754
		error=DateTimeParse(dateTime,_L("1/6/12"));
sl@0
   755
		test(error==EParseDatePresent);
sl@0
   756
		test(dateTime.Second()==0);
sl@0
   757
		test(dateTime.Minute()==0);
sl@0
   758
		test(dateTime.Hour()==0);
sl@0
   759
		test(dateTime.Day()==5);
sl@0
   760
		test(dateTime.Month()==EJanuary);
sl@0
   761
		if (currentTimeIsBeforeYear2000) 
sl@0
   762
			test(dateTime.Year()==1912);
sl@0
   763
		else
sl@0
   764
			test(dateTime.Year()==2012);
sl@0
   765
sl@0
   766
		error=DateTimeParse(dateTime,_L(" dec  3 12"),13);
sl@0
   767
		test(error==EParseDatePresent);
sl@0
   768
		test(dateTime.Second()==0);
sl@0
   769
		test(dateTime.Minute()==0);
sl@0
   770
		test(dateTime.Hour()==0);
sl@0
   771
		test(dateTime.Day()==2);
sl@0
   772
		test(dateTime.Month()==EDecember);
sl@0
   773
		if (currentTimeIsBeforeYear2000) 
sl@0
   774
			test(dateTime.Year()==2012);
sl@0
   775
		else
sl@0
   776
			test(dateTime.Year()==2012);
sl@0
   777
sl@0
   778
		error=DateTimeParse(dateTime,_L(" 3 dec 12 "));
sl@0
   779
		test(error==EParseDatePresent);
sl@0
   780
		test(dateTime.Second()==0);
sl@0
   781
		test(dateTime.Minute()==0);
sl@0
   782
		test(dateTime.Hour()==0);
sl@0
   783
		test(dateTime.Day()==2);
sl@0
   784
		test(dateTime.Month()==EDecember);
sl@0
   785
		if (currentTimeIsBeforeYear2000) 
sl@0
   786
			test(dateTime.Year()==1912);
sl@0
   787
		else
sl@0
   788
			test(dateTime.Year()==2012);
sl@0
   789
sl@0
   790
		dateFormat=EDateJapanese;
sl@0
   791
		locale.SetDateFormat(dateFormat);
sl@0
   792
		locale.Set();
sl@0
   793
sl@0
   794
		error=DateTimeParse(dateTime,_L("3/17"));
sl@0
   795
		test(error==EParseDatePresent);
sl@0
   796
		test(dateTime.Second()==0);
sl@0
   797
		test(dateTime.Minute()==0);
sl@0
   798
		test(dateTime.Hour()==0);
sl@0
   799
		test(dateTime.Day()==16);
sl@0
   800
		test(dateTime.Month()==EMarch);
sl@0
   801
		test(dateTime.Year()==0);
sl@0
   802
sl@0
   803
		error=DateTimeParse(dateTime,_L("1/6/12"));
sl@0
   804
		test(error==EParseDatePresent);
sl@0
   805
		test(dateTime.Second()==0);
sl@0
   806
		test(dateTime.Minute()==0);
sl@0
   807
		test(dateTime.Hour()==0);
sl@0
   808
		test(dateTime.Day()==11);
sl@0
   809
		test(dateTime.Month()==EJune);
sl@0
   810
		if (currentTimeIsBeforeYear2000) 
sl@0
   811
			test(dateTime.Year()==1901);
sl@0
   812
		else
sl@0
   813
			test(dateTime.Year()==2001);
sl@0
   814
sl@0
   815
		error=DateTimeParse(dateTime,_L("1*6*12"));
sl@0
   816
		test(error==KErrArgument);
sl@0
   817
sl@0
   818
		error=DateTimeParse(dateTime,_L("1+6+12"));
sl@0
   819
		test(error==KErrArgument);
sl@0
   820
sl@0
   821
		locale.SetDateSeparator('*',1);
sl@0
   822
		locale.SetDateSeparator('+',2);
sl@0
   823
		locale.Set();
sl@0
   824
sl@0
   825
		error=DateTimeParse(dateTime,_L("1*6*12"));
sl@0
   826
		test(error==EParseDatePresent);
sl@0
   827
		test(dateTime.Second()==0);
sl@0
   828
		test(dateTime.Minute()==0);
sl@0
   829
		test(dateTime.Hour()==0);
sl@0
   830
		test(dateTime.Day()==11);
sl@0
   831
		test(dateTime.Month()==EJune);
sl@0
   832
		if (currentTimeIsBeforeYear2000) 
sl@0
   833
			test(dateTime.Year()==1901);
sl@0
   834
		else
sl@0
   835
			test(dateTime.Year()==2001);
sl@0
   836
sl@0
   837
		error=DateTimeParse(dateTime,_L("1+6+12"));
sl@0
   838
		test(error==EParseDatePresent);
sl@0
   839
		test(dateTime.Second()==0);
sl@0
   840
		test(dateTime.Minute()==0);
sl@0
   841
		test(dateTime.Hour()==0);
sl@0
   842
		test(dateTime.Day()==11);
sl@0
   843
		test(dateTime.Month()==EJune);
sl@0
   844
		if (currentTimeIsBeforeYear2000) 
sl@0
   845
			test(dateTime.Year()==1901);
sl@0
   846
		else
sl@0
   847
			test(dateTime.Year()==2001);
sl@0
   848
sl@0
   849
		error=DateTimeParse(dateTime,_L("1+6+12 14:32.54am"));
sl@0
   850
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   851
		test(dateTime.Second()==54);
sl@0
   852
		test(dateTime.Minute()==32);
sl@0
   853
		test(dateTime.Hour()==14);
sl@0
   854
		test(dateTime.Day()==11);
sl@0
   855
		test(dateTime.Month()==EJune);
sl@0
   856
		if (currentTimeIsBeforeYear2000) 
sl@0
   857
			test(dateTime.Year()==1901);
sl@0
   858
		else
sl@0
   859
			test(dateTime.Year()==2001);
sl@0
   860
sl@0
   861
		error=DateTimeParse(dateTime,_L("10p 1+6+12"));
sl@0
   862
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   863
		test(dateTime.Second()==0);
sl@0
   864
		test(dateTime.Minute()==0);
sl@0
   865
		test(dateTime.Hour()==22);
sl@0
   866
		test(dateTime.Day()==11);
sl@0
   867
		test(dateTime.Month()==EJune);
sl@0
   868
		if (currentTimeIsBeforeYear2000) 
sl@0
   869
			test(dateTime.Year()==1901);
sl@0
   870
		else
sl@0
   871
			test(dateTime.Year()==2001);
sl@0
   872
sl@0
   873
		// European
sl@0
   874
		locale.SetDateFormat(EDateEuropean);
sl@0
   875
		locale.SetDateSeparator('.',2);
sl@0
   876
		locale.Set();
sl@0
   877
sl@0
   878
		error=DateTimeParse(dateTime,_L("1+6+12"));
sl@0
   879
		test(error==KErrArgument);
sl@0
   880
sl@0
   881
		error=DateTimeParse(dateTime,_L("3.6.86"));
sl@0
   882
		test(error==EParseDatePresent);
sl@0
   883
		test(dateTime.Second()==0);
sl@0
   884
		test(dateTime.Minute()==0);
sl@0
   885
		test(dateTime.Hour()==0);
sl@0
   886
		test(dateTime.Day()==2);
sl@0
   887
		test(dateTime.Month()==EJune);
sl@0
   888
		if (currentTimeIsBeforeYear2000) 
sl@0
   889
			test(dateTime.Year()==1986);
sl@0
   890
		else
sl@0
   891
			test(dateTime.Year()==2086);
sl@0
   892
sl@0
   893
		error=DateTimeParse(dateTime,_L("3.6.86 10:10:10"));
sl@0
   894
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   895
		test(dateTime.Second()==10);
sl@0
   896
		test(dateTime.Minute()==10);
sl@0
   897
		test(dateTime.Hour()==10);
sl@0
   898
		test(dateTime.Day()==2);
sl@0
   899
		test(dateTime.Month()==EJune);
sl@0
   900
		if (currentTimeIsBeforeYear2000) 
sl@0
   901
			test(dateTime.Year()==1986);
sl@0
   902
		else
sl@0
   903
			test(dateTime.Year()==2086);
sl@0
   904
sl@0
   905
		locale.SetDateSeparator(':',1);
sl@0
   906
		locale.Set();
sl@0
   907
sl@0
   908
		error=DateTimeParse(dateTime,_L("3.6.86 10:10:10"));
sl@0
   909
		test(error==KErrArgument);
sl@0
   910
//		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   911
		test(dateTime.Second()==10);
sl@0
   912
		test(dateTime.Minute()==10);
sl@0
   913
		test(dateTime.Hour()==10);
sl@0
   914
		test(dateTime.Day()==2);
sl@0
   915
		test(dateTime.Month()==EJune);
sl@0
   916
		if (currentTimeIsBeforeYear2000) 
sl@0
   917
			test(dateTime.Year()==1986);
sl@0
   918
		else
sl@0
   919
			test(dateTime.Year()==2086);
sl@0
   920
sl@0
   921
		error=DateTimeParse(dateTime,_L("3:6:86 10.10.10"));
sl@0
   922
		test(error==KErrArgument);
sl@0
   923
		test(dateTime.Second()==10);
sl@0
   924
		test(dateTime.Minute()==10);
sl@0
   925
		test(dateTime.Hour()==10);
sl@0
   926
		test(dateTime.Day()==2);
sl@0
   927
		test(dateTime.Month()==EJune);
sl@0
   928
		if (currentTimeIsBeforeYear2000) 
sl@0
   929
			test(dateTime.Year()==1986);
sl@0
   930
		else
sl@0
   931
			test(dateTime.Year()==2086);
sl@0
   932
sl@0
   933
		error=DateTimeParse(dateTime,_L("10.10"));
sl@0
   934
		test(error==EParseDatePresent);
sl@0
   935
		test(dateTime.Second()==0);
sl@0
   936
		test(dateTime.Minute()==0);
sl@0
   937
		test(dateTime.Hour()==0);
sl@0
   938
		test(dateTime.Day()==9);
sl@0
   939
		test(dateTime.Month()==EOctober);
sl@0
   940
		test(dateTime.Year()==0);
sl@0
   941
sl@0
   942
		// If the date sep has been set to '.' then 10th October
sl@0
   943
		error=DateTimeParse(dateTime,_L("10.10pm"));
sl@0
   944
		test(error==KErrArgument);
sl@0
   945
		test(dateTime.Second()==0);
sl@0
   946
		test(dateTime.Minute()==0);
sl@0
   947
		test(dateTime.Hour()==0);
sl@0
   948
		test(dateTime.Day()==9);
sl@0
   949
		test(dateTime.Month()==EOctober);
sl@0
   950
		test(dateTime.Year()==0);
sl@0
   951
sl@0
   952
		error=DateTimeParse(dateTime,_L("10p 3:6:86"));
sl@0
   953
		test(error==(EParseDatePresent|EParseTimePresent));
sl@0
   954
		test(dateTime.Second()==0);
sl@0
   955
		test(dateTime.Minute()==0);
sl@0
   956
		test(dateTime.Hour()==22);
sl@0
   957
		test(dateTime.Day()==2);
sl@0
   958
		test(dateTime.Month()==EJune);
sl@0
   959
		if (currentTimeIsBeforeYear2000) 
sl@0
   960
			test(dateTime.Year()==1986);
sl@0
   961
		else
sl@0
   962
			test(dateTime.Year()==2086);
sl@0
   963
sl@0
   964
		error=DateTimeParse(dateTime,_L("1:6:12 3.05.06"));
sl@0
   965
		test(error==KErrArgument);
sl@0
   966
sl@0
   967
		error=DateTimeParse(dateTime,_L(" 3.05.06  1:6:12"));
sl@0
   968
		test(error==KErrArgument);
sl@0
   969
sl@0
   970
		locale.Refresh();
sl@0
   971
		savedLocale.Set();
sl@0
   972
		}
sl@0
   973
	}
sl@0
   974
sl@0
   975
TInt E32Main()
sl@0
   976
	{
sl@0
   977
	
sl@0
   978
	test.Title();
sl@0
   979
	test.Start(_L("Begin tests"));
sl@0
   980
	TLocale currentLocale;
sl@0
   981
sl@0
   982
	TLocale b;
sl@0
   983
	b.SetDateSeparator('\0',0);
sl@0
   984
	b.SetDateSeparator('/',1);
sl@0
   985
	b.SetDateSeparator('/',2);
sl@0
   986
	b.SetDateSeparator('\0',3);
sl@0
   987
	b.SetDateFormat(EDateEuropean);
sl@0
   988
	b.SetTimeFormat(ETime12);
sl@0
   989
	b.SetTimeSeparator('\0',0);
sl@0
   990
	b.SetTimeSeparator(':',1);
sl@0
   991
	b.SetTimeSeparator(':',2);
sl@0
   992
	b.SetTimeSeparator('\0',3);
sl@0
   993
	b.SetAmPmSpaceBetween(ETrue);
sl@0
   994
	b.SetAmPmSymbolPosition(ELocaleAfter);
sl@0
   995
	b.SetWorkDays(0x1F);
sl@0
   996
	b.SetStartOfWeek(EMonday);
sl@0
   997
	b.Set();
sl@0
   998
sl@0
   999
	TTimeIntervalSeconds oldOffset = User::UTCOffset();
sl@0
  1000
	User::SetUTCOffset(0);
sl@0
  1001
sl@0
  1002
	test.Console()->Printf(_L("SimpleTimeFormats\n"));
sl@0
  1003
	SimpleTimeFormats();
sl@0
  1004
	test.Console()->Printf(_L("SimpleDateFormats\n"));
sl@0
  1005
	SimpleDateFormats();
sl@0
  1006
	test.Console()->Printf(_L("DateTimeFormats\n"));
sl@0
  1007
	DateTimeFormats();
sl@0
  1008
	test.Console()->Printf(_L("TimeDateFormats\n"));
sl@0
  1009
	TimeDateFormats();
sl@0
  1010
	test.Console()->Printf(_L("BadDescriptors\n"));
sl@0
  1011
	BadDescriptors();
sl@0
  1012
	test.Console()->Printf(_L("TestLocaleChanges\n"));
sl@0
  1013
	TestLocaleChanges();
sl@0
  1014
	test.Console()->Printf(_L("End of tests\n"));
sl@0
  1015
	currentLocale.Set();
sl@0
  1016
	User::SetUTCOffset(oldOffset);
sl@0
  1017
	test.End();
sl@0
  1018
	return(KErrNone);
sl@0
  1019
	}
sl@0
  1020
sl@0
  1021