sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:
sl@0: * NAME:
sl@0: * strftime - convert date and time to a string 
sl@0: * SYNOPSIS:
sl@0: * size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
sl@0: * Formats  Time into string for  the given tags[options] with a  limit of  Limitsize bytes.
sl@0: * Options:
sl@0: * %a - Abbreviated weekday name (eg:Mon)
sl@0: * %A - Full weekday name (eg:Monday)
sl@0: * %b - Abbreviated month name (eg:Jan)
sl@0: * %B - full month name (eg:January)
sl@0: * %c - preferred date and time representation (eg:Tue 06 12:34:45 2009)
sl@0: * %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
sl@0: * %d - Day of the month as a decimal number (range 01 to 31)
sl@0: * %D - Same as %m/%d/%y
sl@0: * %e - Day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
sl@0: * %F- Equivalent to %Y-%m-%d 
sl@0: * %g - Same As %G, but without the century.
sl@0: * %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.
sl@0: * %h - Same as %b
sl@0: * %H - Hour as a decimal number using a 24-hour clock (range 00 to 23)
sl@0: * %I - Hour as a decimal number using a 12-hour clock (range 01 to 12)
sl@0: * %j - Day of the year as a decimal number (range 001 to 366)
sl@0: * %m - Month as a decimal number (range 01 to 12)
sl@0: * %M - Minute as a decimal number
sl@0: * %n - Newline character
sl@0: * %p - UPPER-CASE `AM' or `PM' according to the given time value
sl@0: * %P - Lower-case `am' or `pm' according to the given time value
sl@0: * %r - Time in a.m. and p.m. notation
sl@0: * %R - Time in 24 hour notation
sl@0: * %S - Second as a decimal number
sl@0: * %t - Tab character
sl@0: * %T - Current time, Equal to %H:%M:%S
sl@0: * %u - Weekday as a decimal number [1,7], with 1 representing Monday
sl@0: * %U - Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
sl@0: * %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.)
sl@0: * %W - Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
sl@0: * %w - Day of the week as a decimal, Sunday being 0
sl@0: * %x - Preferred date representation for the current locale without the time
sl@0: * %X - Preferred time representation for the current locale without the date
sl@0: * %y - Year as a decimal number without a century (range 00 to 99)
sl@0: * %Y - Year as a decimal number including the century
sl@0: * %Z or %z - Time zone offset or name or abbreviation (Operating System dependent)
sl@0: * %% - percent sign
sl@0: * Maximum length of this parameter is 1023 characters. 
sl@0: * 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #include <time.h>
sl@0: #include <stdio.h>
sl@0: #include <stddef.h>
sl@0: #include <stdlib.h>  
sl@0: #include <string.h>
sl@0: 
sl@0: static const int dayname_length[7] ={6, 6, 7, 9, 8, 6, 8};
sl@0: static const char*const  adayname[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
sl@0: 
sl@0: static const char *const dayname[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
sl@0: 
sl@0: static const int monthname_length[12] ={7, 8, 5, 5, 3, 4, 4, 6, 9, 7, 8, 8};
sl@0: 
sl@0: static const char *const amonthname[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
sl@0: 
sl@0: static const char *const monthname[12] ={"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November","December"};
sl@0: 
sl@0: 
sl@0: //  The Function Stores all characters  in Char * array,until it finds %.
sl@0: int splitter(char *array,size_t limitsize,const char** format,size_t* counter)
sl@0: {
sl@0: 	while(**format!='%' && **format)
sl@0: 	   {
sl@0: 		 if(*counter<limitsize-1 )
sl@0: 			{
sl@0: 				array[*counter]=**format;
sl@0: 				 (*counter)++;
sl@0: 				(*format)++;
sl@0: 			}
sl@0:      
sl@0: 		 else
sl@0: 			{
sl@0: 				return  1;
sl@0: 			}		
sl@0: 	  }
sl@0: 	 array[*counter]='\0';
sl@0: 	 return 0;
sl@0: }
sl@0: // The Funtion is Used for Storing Abbreviated WeekDay Nname in Place of %a. (eg:Mon)
sl@0: int funa(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	 if(*counter<limitsize-1)
sl@0: 		{   
sl@0: 			strcat(array,adayname[tme->tm_wday]);
sl@0: 			*counter+=3;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return 1;
sl@0: 		}	
sl@0: 	return 0;
sl@0: }
sl@0: //The Function is Used for Stroring WeekDay Name in Place of %A. (eg:Monday)
sl@0: int funA(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	 if(*counter<limitsize-1)
sl@0: 		{
sl@0: 			strcat(array,dayname[tme->tm_wday]);
sl@0: 			*counter+=dayname_length[tme->tm_wday];                         
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return 1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }  
sl@0: // The  Function  is Used for Storing Abbreviated Month Name in Place of %b.(eg:Jan)
sl@0: int funb(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-1)
sl@0: 		{
sl@0: 			strcat(array,amonthname[tme->tm_mon]);
sl@0: 			*counter+=3;                        
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;
sl@0: }
sl@0: // The  Function  is Used for Storing Month Name in Place of %B .(eg:January) 
sl@0: int funB(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-1)
sl@0: 		{
sl@0: 			strcat(array,monthname[tme->tm_mon]);
sl@0: 			*counter+=monthname_length[tme->tm_mon];                         
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return 1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is Used for Storing preferred date and time representation  in Place of %c.(eg:Tue 06 12:34:45 2009)
sl@0: int func(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-24)
sl@0: 		{
sl@0: 			strcat(array,adayname[tme->tm_wday]);
sl@0: 			strcat(array," ");
sl@0: 			strcat(array,amonthname[tme->tm_mon]);
sl@0: 			*counter+=7;
sl@0: 			sprintf(&array[*counter]," %.2d %.2d %.2d %.2d %.4d",tme->tm_mday,tme->tm_hour,tme->tm_min,tme->tm_sec,1900+tme->tm_year);
sl@0: 			*counter+=17;
sl@0: 			array[*counter]='\0';
sl@0: 		}  	
sl@0: 	else
sl@0: 		{	
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0; 
sl@0: }
sl@0: // 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)
sl@0: int funC(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-1)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)/100);
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is Used for Storing Day of the month as a decimal number in Place of %d.(eg:range 01 to 31)	
sl@0: int fund(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 		sprintf (&array[*counter], "%.2d", tme->tm_mday);
sl@0: 		*counter += 2;
sl@0: 		array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		return  1;
sl@0: 		}
sl@0: 	return 0;    	
sl@0: }
sl@0: // The Function is Used for Storing  Date in form of %m/%d/%y in Place of %D.
sl@0: int funD(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-8)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%.2d/%.2d/%.2d",tme->tm_mon,tme->tm_mday,(1900+tme->tm_year)%100);  
sl@0: 			*counter+=8;
sl@0: 			array[*counter]='\0';        
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;
sl@0: }
sl@0: // 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')
sl@0: int fune(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-2)
sl@0: 		{
sl@0: 			if(tme->tm_mday<10)
sl@0: 				sprintf(&array[*counter]," %d",tme->tm_mday);
sl@0: 			else
sl@0: 				sprintf(&array[*counter],"%2d",tme->tm_mday);  
sl@0: 			*counter+=2; 
sl@0: 			array[*counter]='\0';                      
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0; 
sl@0:                             
sl@0: }
sl@0: // The Function is Used for Storing date in form of  %Y-%m-%d 
sl@0: int funF(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-10)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%4d/%.2d/%.2d",1900+tme->tm_year,tme->tm_mon,tme->tm_mday);
sl@0: 			*counter+=10;
sl@0: 			array[*counter]='\0';
sl@0: 		}   
sl@0: 	else
sl@0: 		{
sl@0: 		return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is  same as that of funG but without Century
sl@0: int fung(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-2)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)%100);
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is Used For Storing  4-digit year corresponding to the ISO week number  in place of %G
sl@0: int funG(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-4)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%4d",1900+tme->tm_year);
sl@0: 			*counter+=4;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{	
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is same as funb
sl@0: int funh(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-1)
sl@0: 		{
sl@0: 		strcat(array,amonthname[tme->tm_mon]);
sl@0: 		*counter+=3;
sl@0: 		array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;   
sl@0: }
sl@0: // 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)	
sl@0: int funH(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {	
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.2d",
sl@0: 			tme->tm_hour);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;  	
sl@0: }
sl@0: // 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)
sl@0: int funI(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			if(tme->tm_hour%12)
sl@0: 				sprintf(&array[*counter],"%.2d",tme->tm_hour%12);
sl@0: 			else
sl@0: 				strcat(array,"12");
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;   
sl@0: }
sl@0: // The Function is Used for Storing Day of the year as a decimal number in Place of %j (eg:range 001 to 366)
sl@0: int funj(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 3)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.3d", tme->tm_yday + 1);
sl@0: 			*counter += 3;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;  	
sl@0: }
sl@0: // 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
sl@0: int funk(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if(*counter<limitsize-2)
sl@0: 		{
sl@0: 			if(tme->tm_hour<10)
sl@0: 				sprintf(&array[*counter]," %d",tme->tm_hour);
sl@0: 			else
sl@0: 				sprintf(&array[*counter],"%2d",tme->tm_hour);
sl@0: 			*counter+=2; 
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}	
sl@0: 	return 0;    
sl@0: }
sl@0: // 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
sl@0: int funl(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			if(tme->tm_hour%12)
sl@0: 				{
sl@0: 					if(tme->tm_hour%12<10)
sl@0: 						sprintf(&array[*counter],"% d",tme->tm_hour%12);
sl@0: 					else
sl@0: 						sprintf(&array[*counter],"%d",tme->tm_hour%12);
sl@0: 				}
sl@0: 			else
sl@0: 				strcat(array,"12");
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;       
sl@0: }
sl@0: // The Function is Used for Storing Month as a decimal number in Place of %m (eg:range 01 to 12)
sl@0: int funm(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.2d", tme->tm_mon + 1);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		return  1;
sl@0: 		}
sl@0: 	return 0;   	
sl@0: }
sl@0: // The Function is Used for Storing Minute as a decimal number in Place of %M
sl@0: int funM(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;  	
sl@0: }
sl@0: // 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'.
sl@0: int funp(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter< limitsize - 2)
sl@0: 		{
sl@0: 			if (tme->tm_hour < 12)
sl@0: 				strcat(array,"A");
sl@0: 			else
sl@0: 				strcat(array,"P");
sl@0: 			strcat(array,"M");
sl@0: 			*counter+=2;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;   	
sl@0: }
sl@0: // 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'.
sl@0: int funP(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {	
sl@0: 	if (*counter< limitsize - 2)
sl@0: 		{
sl@0: 			if (tme->tm_hour < 12)
sl@0: 				strcat(array,"a");
sl@0: 			else
sl@0: 				strcat(array,"p");
sl@0: 			strcat(array,"m");
sl@0: 			*counter+=2;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: //The Function is Used for Storing  Hour,minute,second,time value in place of %r,same as %I:%M:%S %p'
sl@0: int funr(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter< limitsize - 11)
sl@0: 		{
sl@0: 			if(tme->tm_hour%12)
sl@0: 				{
sl@0: 					if(tme->tm_hour%12<10)
sl@0: 						sprintf(&array[*counter],"% d",tme->tm_hour);
sl@0: 					else
sl@0: 						sprintf(&array[*counter],"%d",tme->tm_hour);
sl@0: 				}
sl@0: 			else
sl@0: 				strcat(array,"12");  
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 			strcat(array,":");
sl@0: 			*counter+=1;
sl@0: 			sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 			strcat(array,":");
sl@0: 			*counter+=1;
sl@0: 			sprintf (&array[*counter], "%2.2d",tme->tm_sec);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 			strcat(array," ");
sl@0: 			*counter+=1;
sl@0: 			if (tme->tm_hour < 12)
sl@0: 				strcat(array,"A");
sl@0: 			else
sl@0: 				strcat(array,"P");
sl@0: 			strcat(array,"M");
sl@0: 			*counter+=2;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0; 
sl@0:      
sl@0: }
sl@0: //   The Function is Used for Storing  The time in 24-hour notation in Place of %R .Same as (%H:%M)..
sl@0: int funR(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0:     if (*counter< limitsize - 5)
sl@0:     {
sl@0:      sprintf (&array[*counter], "%.2d",
sl@0: 		       tme->tm_hour);
sl@0:      strcat(array,":");
sl@0:      *counter+=3;
sl@0:       sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0: 	      *counter += 2;
sl@0: 	      array[*counter]='\0';
sl@0:        }
sl@0:        else
sl@0: 	       {
sl@0: 		   return  1;
sl@0: 		}	   
sl@0:     return 0;
sl@0:     
sl@0: }
sl@0: //   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
sl@0: int funs(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	size_t count=0;
sl@0: 	size_t temptime;
sl@0: 	time_t timeinseconds;
sl@0: 	timeinseconds = time (NULL);
sl@0: 	temptime=timeinseconds;
sl@0: 	while(temptime>0)
sl@0: 		{
sl@0: 			count++;
sl@0: 			temptime/=10;
sl@0: 		}
sl@0: 	if(*counter<limitsize-count)
sl@0: 		{
sl@0: 			sprintf(&array[*counter],"%ld",timeinseconds);
sl@0: 			*counter+=count;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0:     
sl@0: }
sl@0: //   The Function is Used for Storing   The second as a decimal number (eg:range 00 to 60)
sl@0: int funS(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.2d", tme->tm_sec);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;     	
sl@0: }
sl@0: //   The Function is Used for Storing  The time in 24-hour notation (%H:%M:%S) in place of %T
sl@0: int funT(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	 if (*counter < limitsize - 2)
sl@0: 		 {
sl@0: 			 sprintf (&array[*counter], "%.2d",tme->tm_hour);
sl@0: 			 *counter+=2;
sl@0: 			 array[*counter]='\0';
sl@0: 			 strcat(array,":");
sl@0: 			 *counter += 1; 
sl@0: 			 sprintf (&array[*counter], "%.2d", tme->tm_min);
sl@0: 			 *counter+=2;
sl@0: 			 array[*counter]='\0';
sl@0: 			 strcat(array,":");
sl@0: 			 *counter += 1;
sl@0: 			 sprintf (&array[*counter], "%.2d", tme->tm_sec);
sl@0: 			 *counter += 2;
sl@0: 			 array[*counter]='\0';
sl@0: 		} 
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: //   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.
sl@0: 	
sl@0: int funu(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 1)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.1d",tme->tm_wday);
sl@0: 			*counter+=1;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;    
sl@0: }
sl@0: //   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
sl@0: int funU(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2) 
sl@0: 		{
sl@0: 			int  temp= tme->tm_yday/7;
sl@0: 			if (tme->tm_yday%7 >tme->tm_wday)
sl@0: 				temp++;
sl@0: 			sprintf(&array[*counter],"%.2d",temp);
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return   1;
sl@0: 		}
sl@0: 	return 0;      	
sl@0: }
sl@0: //   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
sl@0: int funw(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 1)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.1d",tme->tm_wday);
sl@0: 			*counter+=1;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;    	
sl@0: }
sl@0: //   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
sl@0: 
sl@0: int funW(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2) 
sl@0: 		{
sl@0: 			int temp= tme->tm_yday/7;
sl@0: 			if (tme->tm_yday%7 > (tme->tm_wday+6)%7)
sl@0: 				temp++;
sl@0: 			sprintf(&array[*counter],"%.2d",temp);
sl@0: 			*counter+=2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;
sl@0: }
sl@0: // The Function is Used for Storing preferred date representation for the current locale without   the time in Place of %x
sl@0: int funx(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 15)
sl@0: 		{
sl@0: 			strcat(array,adayname[tme->tm_wday]);
sl@0: 			*counter+=3;
sl@0: 			array[*counter]='\0';
sl@0: 			strcat(array," ");
sl@0: 			*counter+=1;
sl@0: 			strcat(array,amonthname[tme->tm_mon]);
sl@0: 			strcat(array," ");
sl@0: 			*counter+=4;
sl@0: 			sprintf (&array[*counter]," %.2d %.4d", tme->tm_mday,1900 + tme->tm_year);
sl@0: 			*counter += 8;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{	
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;    	
sl@0: }
sl@0: // The Function is Used for Storing  preferred time representation for the current locale without the date in Place of %X
sl@0: int funX(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 8)
sl@0: 		{
sl@0: 			sprintf (&array[*counter],"%2.2d:%2.2d:%2.2d",tme->tm_hour, tme->tm_min,tme->tm_sec);
sl@0: 			*counter += 8;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;     	
sl@0: }
sl@0: // The Function is Used for Storing  year as a decimal number without a century (range 00 to 99). in Place of %y
sl@0: int funy(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 2)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.2d",tme->tm_year);
sl@0: 			*counter += 2;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;   	
sl@0: }
sl@0: // The Function is Used for Storing  The year as a decimal number including the century in Place of %Y
sl@0: int funY(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
sl@0: {
sl@0: 	if (*counter < limitsize - 4)
sl@0: 		{
sl@0: 			sprintf (&array[*counter], "%.4d",1900 + tme->tm_year);
sl@0: 			*counter += 4;
sl@0: 			array[*counter]='\0';
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 			return  1;
sl@0: 		}
sl@0: 	return 0;   	
sl@0: }
sl@0: 
sl@0: //- convert/Formats date and time to a string for  the given tags[options] with a  limit of  Limitsize bytes
sl@0: // 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,
sl@0: // if successful and 0 if  the size exceeeds the limit .
sl@0: 
sl@0: EXPORT_C size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
sl@0: {          
sl@0: 	size_t* counter=(size_t* )malloc(sizeof(size_t));
sl@0: 	size_t error=0,funerror=0;
sl@0: 	*counter=0;
sl@0: 	array[*counter]='\0';
sl@0: 	while(1)
sl@0: 		{
sl@0: 			error=splitter(array,limitsize,&pattern,counter);
sl@0: 			if(!error)
sl@0: 				{
sl@0: 					if(*pattern=='\0')
sl@0: 						break;
sl@0: 					else
sl@0: 						{
sl@0: 							pattern++;
sl@0: 							switch(*pattern)
sl@0: 								{
sl@0: 									case '%':
sl@0: 										if(*counter<limitsize-1)
sl@0: 											array[(*counter)++]='%';
sl@0: 										else
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'a':
sl@0: 										funerror= funa(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'A':
sl@0: 										funerror=funA(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return 0;
sl@0: 										break;
sl@0: 									case 'b':
sl@0: 										funerror=funb(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'B':
sl@0: 										funerror=funB(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'c':
sl@0: 										funerror=func(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'C':
sl@0: 										funerror=funC(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'd':
sl@0: 										funerror=fund(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'D':
sl@0: 										funerror=funD(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break; 
sl@0: 									case 'e':
sl@0: 										funerror=fune(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'F':
sl@0: 										funerror=funF(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;         
sl@0: 									case 'g':
sl@0: 										funerror=fung(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;  
sl@0: 									case 'G':
sl@0: 										funerror=funG(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'H':
sl@0: 										funerror=funH(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'I':
sl@0: 										funerror=funI(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'j':
sl@0: 										funerror=funj(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'k':
sl@0: 										funerror=funk(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'l':
sl@0: 										funerror=funl(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'm':
sl@0: 										funerror=funm(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'M':
sl@0: 										funerror=funM(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'p':
sl@0: 										funerror=funp(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'P':
sl@0: 										funerror=funP(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'r':
sl@0: 										funerror=funr(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'R':
sl@0: 										funerror=funR(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break; 
sl@0: 									case 's':
sl@0: 										funerror=funs(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'S':
sl@0: 										funerror=funS(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'T':
sl@0: 										funerror=funT(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'u':
sl@0: 										funerror=funu(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'U':
sl@0: 										funerror=funU(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'w':
sl@0: 										funerror=funw(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'W':
sl@0: 										funerror=funW(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'x':
sl@0: 										funerror=funx(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'X':
sl@0: 										funerror=funX(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case'y':
sl@0: 										funerror=funy(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'Y':
sl@0: 										funerror=funY(array,limitsize,counter,tme);
sl@0: 										if(funerror)
sl@0: 											return  0;
sl@0: 										break;
sl@0: 									case 'Z':
sl@0: 										break;
sl@0: 								}		
sl@0: 						}
sl@0: 				}		
sl@0: 			else
sl@0: 				{
sl@0: 					return  0;
sl@0: 				}
sl@0: 			if (*pattern)
sl@0: 				pattern++;
sl@0: 			else
sl@0: 				break;
sl@0: 		}
sl@0: 	array[*counter]='\0';
sl@0: 	error=*counter;
sl@0: 	free (counter);
sl@0: 	counter=NULL;
sl@0: 	return error;
sl@0: }