os/ossrv/genericopenlibs/cstdlib/LTIME/STRFTIME.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * NAME:
    16 * strftime - convert date and time to a string 
    17 * SYNOPSIS:
    18 * size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
    19 * Formats  Time into string for  the given tags[options] with a  limit of  Limitsize bytes.
    20 * Options:
    21 * %a - Abbreviated weekday name (eg:Mon)
    22 * %A - Full weekday name (eg:Monday)
    23 * %b - Abbreviated month name (eg:Jan)
    24 * %B - full month name (eg:January)
    25 * %c - preferred date and time representation (eg:Tue 06 12:34:45 2009)
    26 * %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
    27 * %d - Day of the month as a decimal number (range 01 to 31)
    28 * %D - Same as %m/%d/%y
    29 * %e - Day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
    30 * %F- Equivalent to %Y-%m-%d 
    31 * %g - Same As %G, but without the century.
    32 * %G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
    33 * %h - Same as %b
    34 * %H - Hour as a decimal number using a 24-hour clock (range 00 to 23)
    35 * %I - Hour as a decimal number using a 12-hour clock (range 01 to 12)
    36 * %j - Day of the year as a decimal number (range 001 to 366)
    37 * %m - Month as a decimal number (range 01 to 12)
    38 * %M - Minute as a decimal number
    39 * %n - Newline character
    40 * %p - UPPER-CASE `AM' or `PM' according to the given time value
    41 * %P - Lower-case `am' or `pm' according to the given time value
    42 * %r - Time in a.m. and p.m. notation
    43 * %R - Time in 24 hour notation
    44 * %S - Second as a decimal number
    45 * %t - Tab character
    46 * %T - Current time, Equal to %H:%M:%S
    47 * %u - Weekday as a decimal number [1,7], with 1 representing Monday
    48 * %U - Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
    49 * %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)
    50 * %W - Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
    51 * %w - Day of the week as a decimal, Sunday being 0
    52 * %x - Preferred date representation for the current locale without the time
    53 * %X - Preferred time representation for the current locale without the date
    54 * %y - Year as a decimal number without a century (range 00 to 99)
    55 * %Y - Year as a decimal number including the century
    56 * %Z or %z - Time zone offset or name or abbreviation (Operating System dependent)
    57 * %% - percent sign
    58 * Maximum length of this parameter is 1023 characters. 
    59 * 
    60 *
    61 */
    62 
    63 
    64 
    65 #include <time.h>
    66 #include <stdio.h>
    67 #include <stddef.h>
    68 #include <stdlib.h>  
    69 #include <string.h>
    70 
    71 static const int dayname_length[7] ={6, 6, 7, 9, 8, 6, 8};
    72 static const char*const  adayname[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    73 
    74 static const char *const dayname[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    75 
    76 static const int monthname_length[12] ={7, 8, 5, 5, 3, 4, 4, 6, 9, 7, 8, 8};
    77 
    78 static const char *const amonthname[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    79 
    80 static const char *const monthname[12] ={"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November","December"};
    81 
    82 
    83 //  The Function Stores all characters  in Char * array,until it finds %.
    84 int splitter(char *array,size_t limitsize,const char** format,size_t* counter)
    85 {
    86 	while(**format!='%' && **format)
    87 	   {
    88 		 if(*counter<limitsize-1 )
    89 			{
    90 				array[*counter]=**format;
    91 				 (*counter)++;
    92 				(*format)++;
    93 			}
    94      
    95 		 else
    96 			{
    97 				return  1;
    98 			}		
    99 	  }
   100 	 array[*counter]='\0';
   101 	 return 0;
   102 }
   103 // The Funtion is Used for Storing Abbreviated WeekDay Nname in Place of %a. (eg:Mon)
   104 int funa(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   105 {
   106 	 if(*counter<limitsize-1)
   107 		{   
   108 			strcat(array,adayname[tme->tm_wday]);
   109 			*counter+=3;
   110 		}
   111 	else
   112 		{
   113 			return 1;
   114 		}	
   115 	return 0;
   116 }
   117 //The Function is Used for Stroring WeekDay Name in Place of %A. (eg:Monday)
   118 int funA(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   119 {
   120 	 if(*counter<limitsize-1)
   121 		{
   122 			strcat(array,dayname[tme->tm_wday]);
   123 			*counter+=dayname_length[tme->tm_wday];                         
   124 		}
   125 	else
   126 		{
   127 			return 1;
   128 		}
   129 	return 0;
   130 }  
   131 // The  Function  is Used for Storing Abbreviated Month Name in Place of %b.(eg:Jan)
   132 int funb(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   133 {
   134 	if(*counter<limitsize-1)
   135 		{
   136 			strcat(array,amonthname[tme->tm_mon]);
   137 			*counter+=3;                        
   138 		}
   139 	else
   140 		{
   141 			return  1;
   142 		}	
   143 	return 0;
   144 }
   145 // The  Function  is Used for Storing Month Name in Place of %B .(eg:January) 
   146 int funB(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   147 {
   148 	if(*counter<limitsize-1)
   149 		{
   150 			strcat(array,monthname[tme->tm_mon]);
   151 			*counter+=monthname_length[tme->tm_mon];                         
   152 		}
   153 	else
   154 		{
   155 			return 1;
   156 		}
   157 	return 0;
   158 }
   159 // The Function is Used for Storing preferred date and time representation  in Place of %c.(eg:Tue 06 12:34:45 2009)
   160 int func(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   161 {
   162 	if(*counter<limitsize-24)
   163 		{
   164 			strcat(array,adayname[tme->tm_wday]);
   165 			strcat(array," ");
   166 			strcat(array,amonthname[tme->tm_mon]);
   167 			*counter+=7;
   168 			sprintf(&array[*counter]," %.2d %.2d %.2d %.2d %.4d",tme->tm_mday,tme->tm_hour,tme->tm_min,tme->tm_sec,1900+tme->tm_year);
   169 			*counter+=17;
   170 			array[*counter]='\0';
   171 		}  	
   172 	else
   173 		{	
   174 			return  1;
   175 		}
   176 	return 0; 
   177 }
   178 // The Function is Used for Storing  Century number in place of %C .(eg:he year divided by 100 and truncated to an integer, range 00 to 99)
   179 int funC(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   180 {
   181 	if(*counter<limitsize-1)
   182 		{
   183 			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)/100);
   184 			*counter+=2;
   185 			array[*counter]='\0';
   186 		}
   187 	else
   188 		{
   189 		return  1;
   190 		}
   191 	return 0;
   192 }
   193 // The Function is Used for Storing Day of the month as a decimal number in Place of %d.(eg:range 01 to 31)	
   194 int fund(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   195 {
   196 	if (*counter < limitsize - 2)
   197 		{
   198 		sprintf (&array[*counter], "%.2d", tme->tm_mday);
   199 		*counter += 2;
   200 		array[*counter]='\0';
   201 		}
   202 	else
   203 		{
   204 		return  1;
   205 		}
   206 	return 0;    	
   207 }
   208 // The Function is Used for Storing  Date in form of %m/%d/%y in Place of %D.
   209 int funD(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   210 {
   211 	if(*counter<limitsize-8)
   212 		{
   213 			sprintf(&array[*counter],"%.2d/%.2d/%.2d",tme->tm_mon,tme->tm_mday,(1900+tme->tm_year)%100);  
   214 			*counter+=8;
   215 			array[*counter]='\0';        
   216 		}
   217 	else
   218 		{
   219 			return  1;
   220 		}	
   221 	return 0;
   222 }
   223 // The Function is Used for Storing Day of the month as a Decimal number, a single digit is preceded by a space in Place of %e. (eg:range ' 1' to '31')
   224 int fune(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   225 {
   226 	if(*counter<limitsize-2)
   227 		{
   228 			if(tme->tm_mday<10)
   229 				sprintf(&array[*counter]," %d",tme->tm_mday);
   230 			else
   231 				sprintf(&array[*counter],"%2d",tme->tm_mday);  
   232 			*counter+=2; 
   233 			array[*counter]='\0';                      
   234 		}
   235 	else
   236 		{
   237 			return  1;
   238 		}
   239 	return 0; 
   240                             
   241 }
   242 // The Function is Used for Storing date in form of  %Y-%m-%d 
   243 int funF(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   244 {
   245 	if(*counter<limitsize-10)
   246 		{
   247 			sprintf(&array[*counter],"%4d/%.2d/%.2d",1900+tme->tm_year,tme->tm_mon,tme->tm_mday);
   248 			*counter+=10;
   249 			array[*counter]='\0';
   250 		}   
   251 	else
   252 		{
   253 		return  1;
   254 		}
   255 	return 0;
   256 }
   257 // The Function is  same as that of funG but without Century
   258 int fung(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   259 {
   260 	if(*counter<limitsize-2)
   261 		{
   262 			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)%100);
   263 			*counter+=2;
   264 			array[*counter]='\0';
   265 		}
   266 	else
   267 		{
   268 			return  1;
   269 		}	
   270 	return 0;
   271 }
   272 // The Function is Used For Storing  4-digit year corresponding to the ISO week number  in place of %G
   273 int funG(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   274 {
   275 	if(*counter<limitsize-4)
   276 		{
   277 			sprintf(&array[*counter],"%4d",1900+tme->tm_year);
   278 			*counter+=4;
   279 			array[*counter]='\0';
   280 		}
   281 	else
   282 		{	
   283 			return  1;
   284 		}	
   285 	return 0;
   286 }
   287 // The Function is same as funb
   288 int funh(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   289 {
   290 	if(*counter<limitsize-1)
   291 		{
   292 		strcat(array,amonthname[tme->tm_mon]);
   293 		*counter+=3;
   294 		array[*counter]='\0';
   295 		}
   296 	else
   297 		{
   298 			return  1;
   299 		}	
   300 	return 0;   
   301 }
   302 // The Function is Used for Storing Hour as a decimal number using a 24-hour clock in Place of %H (eg:range 00 to 23)	
   303 int funH(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   304 {	
   305 	if (*counter < limitsize - 2)
   306 		{
   307 			sprintf (&array[*counter], "%.2d",
   308 			tme->tm_hour);
   309 			*counter += 2;
   310 			array[*counter]='\0';
   311 		}
   312 	else
   313 		{
   314 			return  1;
   315 		}
   316 	return 0;  	
   317 }
   318 // The Function is Used for Storing Hour as a decimal number using a 12-hour clock in Place of %I(eg:range 01 to 12)
   319 int funI(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   320 {
   321 	if (*counter < limitsize - 2)
   322 		{
   323 			if(tme->tm_hour%12)
   324 				sprintf(&array[*counter],"%.2d",tme->tm_hour%12);
   325 			else
   326 				strcat(array,"12");
   327 			*counter+=2;
   328 			array[*counter]='\0';
   329 		}
   330 	else
   331 		{
   332 			return  1;
   333 		}
   334 	return 0;   
   335 }
   336 // The Function is Used for Storing Day of the year as a decimal number in Place of %j (eg:range 001 to 366)
   337 int funj(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   338 {
   339 	if (*counter < limitsize - 3)
   340 		{
   341 			sprintf (&array[*counter], "%.3d", tme->tm_yday + 1);
   342 			*counter += 3;
   343 			array[*counter]='\0';
   344 		}
   345 	else
   346 		{
   347 			return  1;
   348 		}
   349 	return 0;  	
   350 }
   351 // The Function is Used for StoringThe hour (24-hour clock) as a decimal number (range  0  to  23);single digits are preceded by a blankin Place of %k
   352 int funk(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   353 {
   354 	if(*counter<limitsize-2)
   355 		{
   356 			if(tme->tm_hour<10)
   357 				sprintf(&array[*counter]," %d",tme->tm_hour);
   358 			else
   359 				sprintf(&array[*counter],"%2d",tme->tm_hour);
   360 			*counter+=2; 
   361 			array[*counter]='\0';
   362 		}
   363 	else
   364 		{
   365 			return  1;
   366 		}	
   367 	return 0;    
   368 }
   369 // The Function is Used for Storing The  hour  (12-hour  clock) as a decimal number (range 1 to 12);single digits are preceded by a blank in Place of %l
   370 int funl(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   371 {
   372 	if (*counter < limitsize - 2)
   373 		{
   374 			if(tme->tm_hour%12)
   375 				{
   376 					if(tme->tm_hour%12<10)
   377 						sprintf(&array[*counter],"% d",tme->tm_hour%12);
   378 					else
   379 						sprintf(&array[*counter],"%d",tme->tm_hour%12);
   380 				}
   381 			else
   382 				strcat(array,"12");
   383 			*counter+=2;
   384 			array[*counter]='\0';
   385 		}
   386 	else
   387 		{
   388 			return  1;
   389 		}
   390 	return 0;       
   391 }
   392 // The Function is Used for Storing Month as a decimal number in Place of %m (eg:range 01 to 12)
   393 int funm(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   394 {
   395 	if (*counter < limitsize - 2)
   396 		{
   397 			sprintf (&array[*counter], "%.2d", tme->tm_mon + 1);
   398 			*counter += 2;
   399 			array[*counter]='\0';
   400 		}
   401 	else
   402 		{
   403 		return  1;
   404 		}
   405 	return 0;   	
   406 }
   407 // The Function is Used for Storing Minute as a decimal number in Place of %M
   408 int funM(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   409 {
   410 	if (*counter < limitsize - 2)
   411 		{
   412 			sprintf (&array[*counter], "%.2d", tme->tm_min);
   413 			*counter += 2;
   414 			array[*counter]='\0';
   415 		}
   416 	else
   417 		{
   418 			return  1;
   419 		}
   420 	return 0;  	
   421 }
   422 // The Function is Used for Storing `AM' or `PM' according to the given time  value,  or  the corresponding  strings  for the current locale.  Noon is treated as `pm' and midnight as `am'.
   423 int funp(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   424 {
   425 	if (*counter< limitsize - 2)
   426 		{
   427 			if (tme->tm_hour < 12)
   428 				strcat(array,"A");
   429 			else
   430 				strcat(array,"P");
   431 			strcat(array,"M");
   432 			*counter+=2;
   433 		}
   434 	else
   435 		{
   436 			return  1;
   437 		}
   438 	return 0;   	
   439 }
   440 // The Function is Used for Storing `am' or `pm' according to the given time  value,  or  the corresponding  strings  for the current locale.  Noon is treated as `pm' and midnight as `am'.
   441 int funP(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   442 {	
   443 	if (*counter< limitsize - 2)
   444 		{
   445 			if (tme->tm_hour < 12)
   446 				strcat(array,"a");
   447 			else
   448 				strcat(array,"p");
   449 			strcat(array,"m");
   450 			*counter+=2;
   451 		}
   452 	else
   453 		{
   454 			return  1;
   455 		}
   456 	return 0;
   457 }
   458 //The Function is Used for Storing  Hour,minute,second,time value in place of %r,same as %I:%M:%S %p'
   459 int funr(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   460 {
   461 	if (*counter< limitsize - 11)
   462 		{
   463 			if(tme->tm_hour%12)
   464 				{
   465 					if(tme->tm_hour%12<10)
   466 						sprintf(&array[*counter],"% d",tme->tm_hour);
   467 					else
   468 						sprintf(&array[*counter],"%d",tme->tm_hour);
   469 				}
   470 			else
   471 				strcat(array,"12");  
   472 			*counter+=2;
   473 			array[*counter]='\0';
   474 			strcat(array,":");
   475 			*counter+=1;
   476 			sprintf (&array[*counter], "%.2d", tme->tm_min);
   477 			*counter += 2;
   478 			array[*counter]='\0';
   479 			strcat(array,":");
   480 			*counter+=1;
   481 			sprintf (&array[*counter], "%2.2d",tme->tm_sec);
   482 			*counter += 2;
   483 			array[*counter]='\0';
   484 			strcat(array," ");
   485 			*counter+=1;
   486 			if (tme->tm_hour < 12)
   487 				strcat(array,"A");
   488 			else
   489 				strcat(array,"P");
   490 			strcat(array,"M");
   491 			*counter+=2;
   492 		}
   493 	else
   494 		{
   495 			return  1;
   496 		}
   497 	return 0; 
   498      
   499 }
   500 //   The Function is Used for Storing  The time in 24-hour notation in Place of %R .Same as (%H:%M)..
   501 int funR(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   502 {
   503     if (*counter< limitsize - 5)
   504     {
   505      sprintf (&array[*counter], "%.2d",
   506 		       tme->tm_hour);
   507      strcat(array,":");
   508      *counter+=3;
   509       sprintf (&array[*counter], "%.2d", tme->tm_min);
   510 	      *counter += 2;
   511 	      array[*counter]='\0';
   512        }
   513        else
   514 	       {
   515 		   return  1;
   516 		}	   
   517     return 0;
   518     
   519 }
   520 //   The Function is Used for Storing The  number  of  seconds since the Epoch, i.e., since 1970-01-0  0:00:00 UTC.in place of %s
   521 int funs(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
   522 {
   523 	size_t count=0;
   524 	size_t temptime;
   525 	time_t timeinseconds;
   526 	timeinseconds = time (NULL);
   527 	temptime=timeinseconds;
   528 	while(temptime>0)
   529 		{
   530 			count++;
   531 			temptime/=10;
   532 		}
   533 	if(*counter<limitsize-count)
   534 		{
   535 			sprintf(&array[*counter],"%ld",timeinseconds);
   536 			*counter+=count;
   537 			array[*counter]='\0';
   538 		}
   539 	else
   540 		{
   541 		return  1;
   542 		}
   543 	return 0;
   544     
   545 }
   546 //   The Function is Used for Storing   The second as a decimal number (eg:range 00 to 60)
   547 int funS(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   548 {
   549 	if (*counter < limitsize - 2)
   550 		{
   551 			sprintf (&array[*counter], "%.2d", tme->tm_sec);
   552 			*counter += 2;
   553 			array[*counter]='\0';
   554 		}
   555 	else
   556 		{
   557 			return  1;
   558 		}
   559 	return 0;     	
   560 }
   561 //   The Function is Used for Storing  The time in 24-hour notation (%H:%M:%S) in place of %T
   562 int funT(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   563 {
   564 	 if (*counter < limitsize - 2)
   565 		 {
   566 			 sprintf (&array[*counter], "%.2d",tme->tm_hour);
   567 			 *counter+=2;
   568 			 array[*counter]='\0';
   569 			 strcat(array,":");
   570 			 *counter += 1; 
   571 			 sprintf (&array[*counter], "%.2d", tme->tm_min);
   572 			 *counter+=2;
   573 			 array[*counter]='\0';
   574 			 strcat(array,":");
   575 			 *counter += 1;
   576 			 sprintf (&array[*counter], "%.2d", tme->tm_sec);
   577 			 *counter += 2;
   578 			 array[*counter]='\0';
   579 		} 
   580 	else
   581 		{
   582 			return  1;
   583 		}
   584 	return 0;
   585 }
   586 //   The Function is Used for Storing The  day of the week as a decimal, range 1 to 7, Monday being 1 in Place of %U.
   587 	
   588 int funu(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   589 {
   590 	if (*counter < limitsize - 1)
   591 		{
   592 			sprintf (&array[*counter], "%.1d",tme->tm_wday);
   593 			*counter+=1;
   594 			array[*counter]='\0';
   595 		}
   596 	else
   597 		{
   598 			return  1;
   599 		}
   600 	return 0;    
   601 }
   602 //   The Function is Used for Storing The week number of the current year as a decimal  number,  range  00  to  53,  starting  with the first Sunday as the first day of week 01 in Place of %U
   603 int funU(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   604 {
   605 	if (*counter < limitsize - 2) 
   606 		{
   607 			int  temp= tme->tm_yday/7;
   608 			if (tme->tm_yday%7 >tme->tm_wday)
   609 				temp++;
   610 			sprintf(&array[*counter],"%.2d",temp);
   611 			*counter+=2;
   612 			array[*counter]='\0';
   613 		}
   614 	else
   615 		{
   616 			return   1;
   617 		}
   618 	return 0;      	
   619 }
   620 //   The Function is Used for Storing The  day of the week as a decimal, range 0 to 6, Sunday being 0 in Place of %w
   621 int funw(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   622 {
   623 	if (*counter < limitsize - 1)
   624 		{
   625 			sprintf (&array[*counter], "%.1d",tme->tm_wday);
   626 			*counter+=1;
   627 			array[*counter]='\0';
   628 		}
   629 	else
   630 		{
   631 			return  1;
   632 		}
   633 	return 0;    	
   634 }
   635 //   The Function is Used for Storing The week number of the current year as a decimal  number,  range 00  to  53,  starting  with the first Monday as the first day of week 01 in Place of %W
   636 
   637 int funW(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   638 {
   639 	if (*counter < limitsize - 2) 
   640 		{
   641 			int temp= tme->tm_yday/7;
   642 			if (tme->tm_yday%7 > (tme->tm_wday+6)%7)
   643 				temp++;
   644 			sprintf(&array[*counter],"%.2d",temp);
   645 			*counter+=2;
   646 			array[*counter]='\0';
   647 		}
   648 	else
   649 		{
   650 			return  1;
   651 		}
   652 	return 0;
   653 }
   654 // The Function is Used for Storing preferred date representation for the current locale without   the time in Place of %x
   655 int funx(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   656 {
   657 	if (*counter < limitsize - 15)
   658 		{
   659 			strcat(array,adayname[tme->tm_wday]);
   660 			*counter+=3;
   661 			array[*counter]='\0';
   662 			strcat(array," ");
   663 			*counter+=1;
   664 			strcat(array,amonthname[tme->tm_mon]);
   665 			strcat(array," ");
   666 			*counter+=4;
   667 			sprintf (&array[*counter]," %.2d %.4d", tme->tm_mday,1900 + tme->tm_year);
   668 			*counter += 8;
   669 			array[*counter]='\0';
   670 		}
   671 	else
   672 		{	
   673 			return  1;
   674 		}
   675 	return 0;    	
   676 }
   677 // The Function is Used for Storing  preferred time representation for the current locale without the date in Place of %X
   678 int funX(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   679 {
   680 	if (*counter < limitsize - 8)
   681 		{
   682 			sprintf (&array[*counter],"%2.2d:%2.2d:%2.2d",tme->tm_hour, tme->tm_min,tme->tm_sec);
   683 			*counter += 8;
   684 			array[*counter]='\0';
   685 		}
   686 	else
   687 		{
   688 			return  1;
   689 		}
   690 	return 0;     	
   691 }
   692 // The Function is Used for Storing  year as a decimal number without a century (range 00 to 99). in Place of %y
   693 int funy(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   694 {
   695 	if (*counter < limitsize - 2)
   696 		{
   697 			sprintf (&array[*counter], "%.2d",tme->tm_year);
   698 			*counter += 2;
   699 			array[*counter]='\0';
   700 		}
   701 	else
   702 		{
   703 			return  1;
   704 		}
   705 	return 0;   	
   706 }
   707 // The Function is Used for Storing  The year as a decimal number including the century in Place of %Y
   708 int funY(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
   709 {
   710 	if (*counter < limitsize - 4)
   711 		{
   712 			sprintf (&array[*counter], "%.4d",1900 + tme->tm_year);
   713 			*counter += 4;
   714 			array[*counter]='\0';
   715 		}
   716 	else
   717 		{
   718 			return  1;
   719 		}
   720 	return 0;   	
   721 }
   722 
   723 //- convert/Formats date and time to a string for  the given tags[options] with a  limit of  Limitsize bytes
   724 // It formats the broken-down time  according to the format specification format and places the result in the  character  array of  Limitsize .The Function returns the number of characters written in the array,
   725 // if successful and 0 if  the size exceeeds the limit .
   726 
   727 EXPORT_C size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
   728 {          
   729 	size_t* counter=(size_t* )malloc(sizeof(size_t));
   730 	size_t error=0,funerror=0;
   731 	*counter=0;
   732 	array[*counter]='\0';
   733 	while(1)
   734 		{
   735 			error=splitter(array,limitsize,&pattern,counter);
   736 			if(!error)
   737 				{
   738 					if(*pattern=='\0')
   739 						break;
   740 					else
   741 						{
   742 							pattern++;
   743 							switch(*pattern)
   744 								{
   745 									case '%':
   746 										if(*counter<limitsize-1)
   747 											array[(*counter)++]='%';
   748 										else
   749 											return  0;
   750 										break;
   751 									case 'a':
   752 										funerror= funa(array,limitsize,counter,tme);
   753 										if(funerror)
   754 											return  0;
   755 										break;
   756 									case 'A':
   757 										funerror=funA(array,limitsize,counter,tme);
   758 										if(funerror)
   759 											return 0;
   760 										break;
   761 									case 'b':
   762 										funerror=funb(array,limitsize,counter,tme);
   763 										if(funerror)
   764 											return  0;
   765 										break;
   766 									case 'B':
   767 										funerror=funB(array,limitsize,counter,tme);
   768 										if(funerror)
   769 											return  0;
   770 										break;
   771 									case 'c':
   772 										funerror=func(array,limitsize,counter,tme);
   773 										if(funerror)
   774 											return  0;
   775 										break;
   776 									case 'C':
   777 										funerror=funC(array,limitsize,counter,tme);
   778 										if(funerror)
   779 											return  0;
   780 										break;
   781 									case 'd':
   782 										funerror=fund(array,limitsize,counter,tme);
   783 										if(funerror)
   784 											return  0;
   785 										break;
   786 									case 'D':
   787 										funerror=funD(array,limitsize,counter,tme);
   788 										if(funerror)
   789 											return  0;
   790 										break; 
   791 									case 'e':
   792 										funerror=fune(array,limitsize,counter,tme);
   793 										if(funerror)
   794 											return  0;
   795 										break;
   796 									case 'F':
   797 										funerror=funF(array,limitsize,counter,tme);
   798 										if(funerror)
   799 											return  0;
   800 										break;         
   801 									case 'g':
   802 										funerror=fung(array,limitsize,counter,tme);
   803 										if(funerror)
   804 											return  0;
   805 										break;  
   806 									case 'G':
   807 										funerror=funG(array,limitsize,counter,tme);
   808 										if(funerror)
   809 											return  0;
   810 										break;
   811 									case 'H':
   812 										funerror=funH(array,limitsize,counter,tme);
   813 										if(funerror)
   814 											return  0;
   815 										break;
   816 									case 'I':
   817 										funerror=funI(array,limitsize,counter,tme);
   818 										if(funerror)
   819 											return  0;
   820 										break;
   821 									case 'j':
   822 										funerror=funj(array,limitsize,counter,tme);
   823 										if(funerror)
   824 											return  0;
   825 										break;
   826 									case 'k':
   827 										funerror=funk(array,limitsize,counter,tme);
   828 										if(funerror)
   829 											return  0;
   830 										break;
   831 									case 'l':
   832 										funerror=funl(array,limitsize,counter,tme);
   833 										if(funerror)
   834 											return  0;
   835 										break;
   836 									case 'm':
   837 										funerror=funm(array,limitsize,counter,tme);
   838 										if(funerror)
   839 											return  0;
   840 										break;
   841 									case 'M':
   842 										funerror=funM(array,limitsize,counter,tme);
   843 										if(funerror)
   844 											return  0;
   845 										break;
   846 									case 'p':
   847 										funerror=funp(array,limitsize,counter,tme);
   848 										if(funerror)
   849 											return  0;
   850 										break;
   851 									case 'P':
   852 										funerror=funP(array,limitsize,counter,tme);
   853 										if(funerror)
   854 											return  0;
   855 										break;
   856 									case 'r':
   857 										funerror=funr(array,limitsize,counter,tme);
   858 										if(funerror)
   859 											return  0;
   860 										break;
   861 									case 'R':
   862 										funerror=funR(array,limitsize,counter,tme);
   863 										if(funerror)
   864 											return  0;
   865 										break; 
   866 									case 's':
   867 										funerror=funs(array,limitsize,counter,tme);
   868 										if(funerror)
   869 											return  0;
   870 										break;
   871 									case 'S':
   872 										funerror=funS(array,limitsize,counter,tme);
   873 										if(funerror)
   874 											return  0;
   875 										break;
   876 									case 'T':
   877 										funerror=funT(array,limitsize,counter,tme);
   878 										if(funerror)
   879 											return  0;
   880 										break;
   881 									case 'u':
   882 										funerror=funu(array,limitsize,counter,tme);
   883 										if(funerror)
   884 											return  0;
   885 										break;
   886 									case 'U':
   887 										funerror=funU(array,limitsize,counter,tme);
   888 										if(funerror)
   889 											return  0;
   890 										break;
   891 									case 'w':
   892 										funerror=funw(array,limitsize,counter,tme);
   893 										if(funerror)
   894 											return  0;
   895 										break;
   896 									case 'W':
   897 										funerror=funW(array,limitsize,counter,tme);
   898 										if(funerror)
   899 											return  0;
   900 										break;
   901 									case 'x':
   902 										funerror=funx(array,limitsize,counter,tme);
   903 										if(funerror)
   904 											return  0;
   905 										break;
   906 									case 'X':
   907 										funerror=funX(array,limitsize,counter,tme);
   908 										if(funerror)
   909 											return  0;
   910 										break;
   911 									case'y':
   912 										funerror=funy(array,limitsize,counter,tme);
   913 										if(funerror)
   914 											return  0;
   915 										break;
   916 									case 'Y':
   917 										funerror=funY(array,limitsize,counter,tme);
   918 										if(funerror)
   919 											return  0;
   920 										break;
   921 									case 'Z':
   922 										break;
   923 								}		
   924 						}
   925 				}		
   926 			else
   927 				{
   928 					return  0;
   929 				}
   930 			if (*pattern)
   931 				pattern++;
   932 			else
   933 				break;
   934 		}
   935 	array[*counter]='\0';
   936 	error=*counter;
   937 	free (counter);
   938 	counter=NULL;
   939 	return error;
   940 }