1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LTIME/STRFTIME.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,940 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* NAME:
1.19 +* strftime - convert date and time to a string
1.20 +* SYNOPSIS:
1.21 +* size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
1.22 +* Formats Time into string for the given tags[options] with a limit of Limitsize bytes.
1.23 +* Options:
1.24 +* %a - Abbreviated weekday name (eg:Mon)
1.25 +* %A - Full weekday name (eg:Monday)
1.26 +* %b - Abbreviated month name (eg:Jan)
1.27 +* %B - full month name (eg:January)
1.28 +* %c - preferred date and time representation (eg:Tue 06 12:34:45 2009)
1.29 +* %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
1.30 +* %d - Day of the month as a decimal number (range 01 to 31)
1.31 +* %D - Same as %m/%d/%y
1.32 +* %e - Day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
1.33 +* %F- Equivalent to %Y-%m-%d
1.34 +* %g - Same As %G, but without the century.
1.35 +* %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.
1.36 +* %h - Same as %b
1.37 +* %H - Hour as a decimal number using a 24-hour clock (range 00 to 23)
1.38 +* %I - Hour as a decimal number using a 12-hour clock (range 01 to 12)
1.39 +* %j - Day of the year as a decimal number (range 001 to 366)
1.40 +* %m - Month as a decimal number (range 01 to 12)
1.41 +* %M - Minute as a decimal number
1.42 +* %n - Newline character
1.43 +* %p - UPPER-CASE `AM' or `PM' according to the given time value
1.44 +* %P - Lower-case `am' or `pm' according to the given time value
1.45 +* %r - Time in a.m. and p.m. notation
1.46 +* %R - Time in 24 hour notation
1.47 +* %S - Second as a decimal number
1.48 +* %t - Tab character
1.49 +* %T - Current time, Equal to %H:%M:%S
1.50 +* %u - Weekday as a decimal number [1,7], with 1 representing Monday
1.51 +* %U - Week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
1.52 +* %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.)
1.53 +* %W - Week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
1.54 +* %w - Day of the week as a decimal, Sunday being 0
1.55 +* %x - Preferred date representation for the current locale without the time
1.56 +* %X - Preferred time representation for the current locale without the date
1.57 +* %y - Year as a decimal number without a century (range 00 to 99)
1.58 +* %Y - Year as a decimal number including the century
1.59 +* %Z or %z - Time zone offset or name or abbreviation (Operating System dependent)
1.60 +* %% - percent sign
1.61 +* Maximum length of this parameter is 1023 characters.
1.62 +*
1.63 +*
1.64 +*/
1.65 +
1.66 +
1.67 +
1.68 +#include <time.h>
1.69 +#include <stdio.h>
1.70 +#include <stddef.h>
1.71 +#include <stdlib.h>
1.72 +#include <string.h>
1.73 +
1.74 +static const int dayname_length[7] ={6, 6, 7, 9, 8, 6, 8};
1.75 +static const char*const adayname[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
1.76 +
1.77 +static const char *const dayname[7] ={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
1.78 +
1.79 +static const int monthname_length[12] ={7, 8, 5, 5, 3, 4, 4, 6, 9, 7, 8, 8};
1.80 +
1.81 +static const char *const amonthname[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
1.82 +
1.83 +static const char *const monthname[12] ={"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November","December"};
1.84 +
1.85 +
1.86 +// The Function Stores all characters in Char * array,until it finds %.
1.87 +int splitter(char *array,size_t limitsize,const char** format,size_t* counter)
1.88 +{
1.89 + while(**format!='%' && **format)
1.90 + {
1.91 + if(*counter<limitsize-1 )
1.92 + {
1.93 + array[*counter]=**format;
1.94 + (*counter)++;
1.95 + (*format)++;
1.96 + }
1.97 +
1.98 + else
1.99 + {
1.100 + return 1;
1.101 + }
1.102 + }
1.103 + array[*counter]='\0';
1.104 + return 0;
1.105 +}
1.106 +// The Funtion is Used for Storing Abbreviated WeekDay Nname in Place of %a. (eg:Mon)
1.107 +int funa(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.108 +{
1.109 + if(*counter<limitsize-1)
1.110 + {
1.111 + strcat(array,adayname[tme->tm_wday]);
1.112 + *counter+=3;
1.113 + }
1.114 + else
1.115 + {
1.116 + return 1;
1.117 + }
1.118 + return 0;
1.119 +}
1.120 +//The Function is Used for Stroring WeekDay Name in Place of %A. (eg:Monday)
1.121 +int funA(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.122 +{
1.123 + if(*counter<limitsize-1)
1.124 + {
1.125 + strcat(array,dayname[tme->tm_wday]);
1.126 + *counter+=dayname_length[tme->tm_wday];
1.127 + }
1.128 + else
1.129 + {
1.130 + return 1;
1.131 + }
1.132 + return 0;
1.133 +}
1.134 +// The Function is Used for Storing Abbreviated Month Name in Place of %b.(eg:Jan)
1.135 +int funb(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.136 +{
1.137 + if(*counter<limitsize-1)
1.138 + {
1.139 + strcat(array,amonthname[tme->tm_mon]);
1.140 + *counter+=3;
1.141 + }
1.142 + else
1.143 + {
1.144 + return 1;
1.145 + }
1.146 + return 0;
1.147 +}
1.148 +// The Function is Used for Storing Month Name in Place of %B .(eg:January)
1.149 +int funB(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.150 +{
1.151 + if(*counter<limitsize-1)
1.152 + {
1.153 + strcat(array,monthname[tme->tm_mon]);
1.154 + *counter+=monthname_length[tme->tm_mon];
1.155 + }
1.156 + else
1.157 + {
1.158 + return 1;
1.159 + }
1.160 + return 0;
1.161 +}
1.162 +// The Function is Used for Storing preferred date and time representation in Place of %c.(eg:Tue 06 12:34:45 2009)
1.163 +int func(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.164 +{
1.165 + if(*counter<limitsize-24)
1.166 + {
1.167 + strcat(array,adayname[tme->tm_wday]);
1.168 + strcat(array," ");
1.169 + strcat(array,amonthname[tme->tm_mon]);
1.170 + *counter+=7;
1.171 + sprintf(&array[*counter]," %.2d %.2d %.2d %.2d %.4d",tme->tm_mday,tme->tm_hour,tme->tm_min,tme->tm_sec,1900+tme->tm_year);
1.172 + *counter+=17;
1.173 + array[*counter]='\0';
1.174 + }
1.175 + else
1.176 + {
1.177 + return 1;
1.178 + }
1.179 + return 0;
1.180 +}
1.181 +// 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)
1.182 +int funC(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.183 +{
1.184 + if(*counter<limitsize-1)
1.185 + {
1.186 + sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)/100);
1.187 + *counter+=2;
1.188 + array[*counter]='\0';
1.189 + }
1.190 + else
1.191 + {
1.192 + return 1;
1.193 + }
1.194 + return 0;
1.195 +}
1.196 +// The Function is Used for Storing Day of the month as a decimal number in Place of %d.(eg:range 01 to 31)
1.197 +int fund(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.198 +{
1.199 + if (*counter < limitsize - 2)
1.200 + {
1.201 + sprintf (&array[*counter], "%.2d", tme->tm_mday);
1.202 + *counter += 2;
1.203 + array[*counter]='\0';
1.204 + }
1.205 + else
1.206 + {
1.207 + return 1;
1.208 + }
1.209 + return 0;
1.210 +}
1.211 +// The Function is Used for Storing Date in form of %m/%d/%y in Place of %D.
1.212 +int funD(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.213 +{
1.214 + if(*counter<limitsize-8)
1.215 + {
1.216 + sprintf(&array[*counter],"%.2d/%.2d/%.2d",tme->tm_mon,tme->tm_mday,(1900+tme->tm_year)%100);
1.217 + *counter+=8;
1.218 + array[*counter]='\0';
1.219 + }
1.220 + else
1.221 + {
1.222 + return 1;
1.223 + }
1.224 + return 0;
1.225 +}
1.226 +// 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')
1.227 +int fune(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.228 +{
1.229 + if(*counter<limitsize-2)
1.230 + {
1.231 + if(tme->tm_mday<10)
1.232 + sprintf(&array[*counter]," %d",tme->tm_mday);
1.233 + else
1.234 + sprintf(&array[*counter],"%2d",tme->tm_mday);
1.235 + *counter+=2;
1.236 + array[*counter]='\0';
1.237 + }
1.238 + else
1.239 + {
1.240 + return 1;
1.241 + }
1.242 + return 0;
1.243 +
1.244 +}
1.245 +// The Function is Used for Storing date in form of %Y-%m-%d
1.246 +int funF(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.247 +{
1.248 + if(*counter<limitsize-10)
1.249 + {
1.250 + sprintf(&array[*counter],"%4d/%.2d/%.2d",1900+tme->tm_year,tme->tm_mon,tme->tm_mday);
1.251 + *counter+=10;
1.252 + array[*counter]='\0';
1.253 + }
1.254 + else
1.255 + {
1.256 + return 1;
1.257 + }
1.258 + return 0;
1.259 +}
1.260 +// The Function is same as that of funG but without Century
1.261 +int fung(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.262 +{
1.263 + if(*counter<limitsize-2)
1.264 + {
1.265 + sprintf(&array[*counter],"%.2d",(1900+tme->tm_year)%100);
1.266 + *counter+=2;
1.267 + array[*counter]='\0';
1.268 + }
1.269 + else
1.270 + {
1.271 + return 1;
1.272 + }
1.273 + return 0;
1.274 +}
1.275 +// The Function is Used For Storing 4-digit year corresponding to the ISO week number in place of %G
1.276 +int funG(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.277 +{
1.278 + if(*counter<limitsize-4)
1.279 + {
1.280 + sprintf(&array[*counter],"%4d",1900+tme->tm_year);
1.281 + *counter+=4;
1.282 + array[*counter]='\0';
1.283 + }
1.284 + else
1.285 + {
1.286 + return 1;
1.287 + }
1.288 + return 0;
1.289 +}
1.290 +// The Function is same as funb
1.291 +int funh(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.292 +{
1.293 + if(*counter<limitsize-1)
1.294 + {
1.295 + strcat(array,amonthname[tme->tm_mon]);
1.296 + *counter+=3;
1.297 + array[*counter]='\0';
1.298 + }
1.299 + else
1.300 + {
1.301 + return 1;
1.302 + }
1.303 + return 0;
1.304 +}
1.305 +// 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)
1.306 +int funH(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.307 +{
1.308 + if (*counter < limitsize - 2)
1.309 + {
1.310 + sprintf (&array[*counter], "%.2d",
1.311 + tme->tm_hour);
1.312 + *counter += 2;
1.313 + array[*counter]='\0';
1.314 + }
1.315 + else
1.316 + {
1.317 + return 1;
1.318 + }
1.319 + return 0;
1.320 +}
1.321 +// 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)
1.322 +int funI(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.323 +{
1.324 + if (*counter < limitsize - 2)
1.325 + {
1.326 + if(tme->tm_hour%12)
1.327 + sprintf(&array[*counter],"%.2d",tme->tm_hour%12);
1.328 + else
1.329 + strcat(array,"12");
1.330 + *counter+=2;
1.331 + array[*counter]='\0';
1.332 + }
1.333 + else
1.334 + {
1.335 + return 1;
1.336 + }
1.337 + return 0;
1.338 +}
1.339 +// The Function is Used for Storing Day of the year as a decimal number in Place of %j (eg:range 001 to 366)
1.340 +int funj(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.341 +{
1.342 + if (*counter < limitsize - 3)
1.343 + {
1.344 + sprintf (&array[*counter], "%.3d", tme->tm_yday + 1);
1.345 + *counter += 3;
1.346 + array[*counter]='\0';
1.347 + }
1.348 + else
1.349 + {
1.350 + return 1;
1.351 + }
1.352 + return 0;
1.353 +}
1.354 +// 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
1.355 +int funk(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.356 +{
1.357 + if(*counter<limitsize-2)
1.358 + {
1.359 + if(tme->tm_hour<10)
1.360 + sprintf(&array[*counter]," %d",tme->tm_hour);
1.361 + else
1.362 + sprintf(&array[*counter],"%2d",tme->tm_hour);
1.363 + *counter+=2;
1.364 + array[*counter]='\0';
1.365 + }
1.366 + else
1.367 + {
1.368 + return 1;
1.369 + }
1.370 + return 0;
1.371 +}
1.372 +// 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
1.373 +int funl(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.374 +{
1.375 + if (*counter < limitsize - 2)
1.376 + {
1.377 + if(tme->tm_hour%12)
1.378 + {
1.379 + if(tme->tm_hour%12<10)
1.380 + sprintf(&array[*counter],"% d",tme->tm_hour%12);
1.381 + else
1.382 + sprintf(&array[*counter],"%d",tme->tm_hour%12);
1.383 + }
1.384 + else
1.385 + strcat(array,"12");
1.386 + *counter+=2;
1.387 + array[*counter]='\0';
1.388 + }
1.389 + else
1.390 + {
1.391 + return 1;
1.392 + }
1.393 + return 0;
1.394 +}
1.395 +// The Function is Used for Storing Month as a decimal number in Place of %m (eg:range 01 to 12)
1.396 +int funm(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.397 +{
1.398 + if (*counter < limitsize - 2)
1.399 + {
1.400 + sprintf (&array[*counter], "%.2d", tme->tm_mon + 1);
1.401 + *counter += 2;
1.402 + array[*counter]='\0';
1.403 + }
1.404 + else
1.405 + {
1.406 + return 1;
1.407 + }
1.408 + return 0;
1.409 +}
1.410 +// The Function is Used for Storing Minute as a decimal number in Place of %M
1.411 +int funM(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.412 +{
1.413 + if (*counter < limitsize - 2)
1.414 + {
1.415 + sprintf (&array[*counter], "%.2d", tme->tm_min);
1.416 + *counter += 2;
1.417 + array[*counter]='\0';
1.418 + }
1.419 + else
1.420 + {
1.421 + return 1;
1.422 + }
1.423 + return 0;
1.424 +}
1.425 +// 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'.
1.426 +int funp(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.427 +{
1.428 + if (*counter< limitsize - 2)
1.429 + {
1.430 + if (tme->tm_hour < 12)
1.431 + strcat(array,"A");
1.432 + else
1.433 + strcat(array,"P");
1.434 + strcat(array,"M");
1.435 + *counter+=2;
1.436 + }
1.437 + else
1.438 + {
1.439 + return 1;
1.440 + }
1.441 + return 0;
1.442 +}
1.443 +// 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'.
1.444 +int funP(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.445 +{
1.446 + if (*counter< limitsize - 2)
1.447 + {
1.448 + if (tme->tm_hour < 12)
1.449 + strcat(array,"a");
1.450 + else
1.451 + strcat(array,"p");
1.452 + strcat(array,"m");
1.453 + *counter+=2;
1.454 + }
1.455 + else
1.456 + {
1.457 + return 1;
1.458 + }
1.459 + return 0;
1.460 +}
1.461 +//The Function is Used for Storing Hour,minute,second,time value in place of %r,same as %I:%M:%S %p'
1.462 +int funr(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.463 +{
1.464 + if (*counter< limitsize - 11)
1.465 + {
1.466 + if(tme->tm_hour%12)
1.467 + {
1.468 + if(tme->tm_hour%12<10)
1.469 + sprintf(&array[*counter],"% d",tme->tm_hour);
1.470 + else
1.471 + sprintf(&array[*counter],"%d",tme->tm_hour);
1.472 + }
1.473 + else
1.474 + strcat(array,"12");
1.475 + *counter+=2;
1.476 + array[*counter]='\0';
1.477 + strcat(array,":");
1.478 + *counter+=1;
1.479 + sprintf (&array[*counter], "%.2d", tme->tm_min);
1.480 + *counter += 2;
1.481 + array[*counter]='\0';
1.482 + strcat(array,":");
1.483 + *counter+=1;
1.484 + sprintf (&array[*counter], "%2.2d",tme->tm_sec);
1.485 + *counter += 2;
1.486 + array[*counter]='\0';
1.487 + strcat(array," ");
1.488 + *counter+=1;
1.489 + if (tme->tm_hour < 12)
1.490 + strcat(array,"A");
1.491 + else
1.492 + strcat(array,"P");
1.493 + strcat(array,"M");
1.494 + *counter+=2;
1.495 + }
1.496 + else
1.497 + {
1.498 + return 1;
1.499 + }
1.500 + return 0;
1.501 +
1.502 +}
1.503 +// The Function is Used for Storing The time in 24-hour notation in Place of %R .Same as (%H:%M)..
1.504 +int funR(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.505 +{
1.506 + if (*counter< limitsize - 5)
1.507 + {
1.508 + sprintf (&array[*counter], "%.2d",
1.509 + tme->tm_hour);
1.510 + strcat(array,":");
1.511 + *counter+=3;
1.512 + sprintf (&array[*counter], "%.2d", tme->tm_min);
1.513 + *counter += 2;
1.514 + array[*counter]='\0';
1.515 + }
1.516 + else
1.517 + {
1.518 + return 1;
1.519 + }
1.520 + return 0;
1.521 +
1.522 +}
1.523 +// 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
1.524 +int funs(char*array,size_t limitsize,size_t *counter,const struct tm*tme)
1.525 +{
1.526 + size_t count=0;
1.527 + size_t temptime;
1.528 + time_t timeinseconds;
1.529 + timeinseconds = time (NULL);
1.530 + temptime=timeinseconds;
1.531 + while(temptime>0)
1.532 + {
1.533 + count++;
1.534 + temptime/=10;
1.535 + }
1.536 + if(*counter<limitsize-count)
1.537 + {
1.538 + sprintf(&array[*counter],"%ld",timeinseconds);
1.539 + *counter+=count;
1.540 + array[*counter]='\0';
1.541 + }
1.542 + else
1.543 + {
1.544 + return 1;
1.545 + }
1.546 + return 0;
1.547 +
1.548 +}
1.549 +// The Function is Used for Storing The second as a decimal number (eg:range 00 to 60)
1.550 +int funS(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.551 +{
1.552 + if (*counter < limitsize - 2)
1.553 + {
1.554 + sprintf (&array[*counter], "%.2d", tme->tm_sec);
1.555 + *counter += 2;
1.556 + array[*counter]='\0';
1.557 + }
1.558 + else
1.559 + {
1.560 + return 1;
1.561 + }
1.562 + return 0;
1.563 +}
1.564 +// The Function is Used for Storing The time in 24-hour notation (%H:%M:%S) in place of %T
1.565 +int funT(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.566 +{
1.567 + if (*counter < limitsize - 2)
1.568 + {
1.569 + sprintf (&array[*counter], "%.2d",tme->tm_hour);
1.570 + *counter+=2;
1.571 + array[*counter]='\0';
1.572 + strcat(array,":");
1.573 + *counter += 1;
1.574 + sprintf (&array[*counter], "%.2d", tme->tm_min);
1.575 + *counter+=2;
1.576 + array[*counter]='\0';
1.577 + strcat(array,":");
1.578 + *counter += 1;
1.579 + sprintf (&array[*counter], "%.2d", tme->tm_sec);
1.580 + *counter += 2;
1.581 + array[*counter]='\0';
1.582 + }
1.583 + else
1.584 + {
1.585 + return 1;
1.586 + }
1.587 + return 0;
1.588 +}
1.589 +// 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.
1.590 +
1.591 +int funu(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.592 +{
1.593 + if (*counter < limitsize - 1)
1.594 + {
1.595 + sprintf (&array[*counter], "%.1d",tme->tm_wday);
1.596 + *counter+=1;
1.597 + array[*counter]='\0';
1.598 + }
1.599 + else
1.600 + {
1.601 + return 1;
1.602 + }
1.603 + return 0;
1.604 +}
1.605 +// 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
1.606 +int funU(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.607 +{
1.608 + if (*counter < limitsize - 2)
1.609 + {
1.610 + int temp= tme->tm_yday/7;
1.611 + if (tme->tm_yday%7 >tme->tm_wday)
1.612 + temp++;
1.613 + sprintf(&array[*counter],"%.2d",temp);
1.614 + *counter+=2;
1.615 + array[*counter]='\0';
1.616 + }
1.617 + else
1.618 + {
1.619 + return 1;
1.620 + }
1.621 + return 0;
1.622 +}
1.623 +// 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
1.624 +int funw(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.625 +{
1.626 + if (*counter < limitsize - 1)
1.627 + {
1.628 + sprintf (&array[*counter], "%.1d",tme->tm_wday);
1.629 + *counter+=1;
1.630 + array[*counter]='\0';
1.631 + }
1.632 + else
1.633 + {
1.634 + return 1;
1.635 + }
1.636 + return 0;
1.637 +}
1.638 +// 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
1.639 +
1.640 +int funW(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.641 +{
1.642 + if (*counter < limitsize - 2)
1.643 + {
1.644 + int temp= tme->tm_yday/7;
1.645 + if (tme->tm_yday%7 > (tme->tm_wday+6)%7)
1.646 + temp++;
1.647 + sprintf(&array[*counter],"%.2d",temp);
1.648 + *counter+=2;
1.649 + array[*counter]='\0';
1.650 + }
1.651 + else
1.652 + {
1.653 + return 1;
1.654 + }
1.655 + return 0;
1.656 +}
1.657 +// The Function is Used for Storing preferred date representation for the current locale without the time in Place of %x
1.658 +int funx(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.659 +{
1.660 + if (*counter < limitsize - 15)
1.661 + {
1.662 + strcat(array,adayname[tme->tm_wday]);
1.663 + *counter+=3;
1.664 + array[*counter]='\0';
1.665 + strcat(array," ");
1.666 + *counter+=1;
1.667 + strcat(array,amonthname[tme->tm_mon]);
1.668 + strcat(array," ");
1.669 + *counter+=4;
1.670 + sprintf (&array[*counter]," %.2d %.4d", tme->tm_mday,1900 + tme->tm_year);
1.671 + *counter += 8;
1.672 + array[*counter]='\0';
1.673 + }
1.674 + else
1.675 + {
1.676 + return 1;
1.677 + }
1.678 + return 0;
1.679 +}
1.680 +// The Function is Used for Storing preferred time representation for the current locale without the date in Place of %X
1.681 +int funX(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.682 +{
1.683 + if (*counter < limitsize - 8)
1.684 + {
1.685 + sprintf (&array[*counter],"%2.2d:%2.2d:%2.2d",tme->tm_hour, tme->tm_min,tme->tm_sec);
1.686 + *counter += 8;
1.687 + array[*counter]='\0';
1.688 + }
1.689 + else
1.690 + {
1.691 + return 1;
1.692 + }
1.693 + return 0;
1.694 +}
1.695 +// The Function is Used for Storing year as a decimal number without a century (range 00 to 99). in Place of %y
1.696 +int funy(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.697 +{
1.698 + if (*counter < limitsize - 2)
1.699 + {
1.700 + sprintf (&array[*counter], "%.2d",tme->tm_year);
1.701 + *counter += 2;
1.702 + array[*counter]='\0';
1.703 + }
1.704 + else
1.705 + {
1.706 + return 1;
1.707 + }
1.708 + return 0;
1.709 +}
1.710 +// The Function is Used for Storing The year as a decimal number including the century in Place of %Y
1.711 +int funY(char *array,size_t limitsize,size_t *counter,const struct tm*tme)
1.712 +{
1.713 + if (*counter < limitsize - 4)
1.714 + {
1.715 + sprintf (&array[*counter], "%.4d",1900 + tme->tm_year);
1.716 + *counter += 4;
1.717 + array[*counter]='\0';
1.718 + }
1.719 + else
1.720 + {
1.721 + return 1;
1.722 + }
1.723 + return 0;
1.724 +}
1.725 +
1.726 +//- convert/Formats date and time to a string for the given tags[options] with a limit of Limitsize bytes
1.727 +// 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,
1.728 +// if successful and 0 if the size exceeeds the limit .
1.729 +
1.730 +EXPORT_C size_t strftime (char *array, size_t limitsize,const char*pattern,const struct tm *tme)
1.731 +{
1.732 + size_t* counter=(size_t* )malloc(sizeof(size_t));
1.733 + size_t error=0,funerror=0;
1.734 + *counter=0;
1.735 + array[*counter]='\0';
1.736 + while(1)
1.737 + {
1.738 + error=splitter(array,limitsize,&pattern,counter);
1.739 + if(!error)
1.740 + {
1.741 + if(*pattern=='\0')
1.742 + break;
1.743 + else
1.744 + {
1.745 + pattern++;
1.746 + switch(*pattern)
1.747 + {
1.748 + case '%':
1.749 + if(*counter<limitsize-1)
1.750 + array[(*counter)++]='%';
1.751 + else
1.752 + return 0;
1.753 + break;
1.754 + case 'a':
1.755 + funerror= funa(array,limitsize,counter,tme);
1.756 + if(funerror)
1.757 + return 0;
1.758 + break;
1.759 + case 'A':
1.760 + funerror=funA(array,limitsize,counter,tme);
1.761 + if(funerror)
1.762 + return 0;
1.763 + break;
1.764 + case 'b':
1.765 + funerror=funb(array,limitsize,counter,tme);
1.766 + if(funerror)
1.767 + return 0;
1.768 + break;
1.769 + case 'B':
1.770 + funerror=funB(array,limitsize,counter,tme);
1.771 + if(funerror)
1.772 + return 0;
1.773 + break;
1.774 + case 'c':
1.775 + funerror=func(array,limitsize,counter,tme);
1.776 + if(funerror)
1.777 + return 0;
1.778 + break;
1.779 + case 'C':
1.780 + funerror=funC(array,limitsize,counter,tme);
1.781 + if(funerror)
1.782 + return 0;
1.783 + break;
1.784 + case 'd':
1.785 + funerror=fund(array,limitsize,counter,tme);
1.786 + if(funerror)
1.787 + return 0;
1.788 + break;
1.789 + case 'D':
1.790 + funerror=funD(array,limitsize,counter,tme);
1.791 + if(funerror)
1.792 + return 0;
1.793 + break;
1.794 + case 'e':
1.795 + funerror=fune(array,limitsize,counter,tme);
1.796 + if(funerror)
1.797 + return 0;
1.798 + break;
1.799 + case 'F':
1.800 + funerror=funF(array,limitsize,counter,tme);
1.801 + if(funerror)
1.802 + return 0;
1.803 + break;
1.804 + case 'g':
1.805 + funerror=fung(array,limitsize,counter,tme);
1.806 + if(funerror)
1.807 + return 0;
1.808 + break;
1.809 + case 'G':
1.810 + funerror=funG(array,limitsize,counter,tme);
1.811 + if(funerror)
1.812 + return 0;
1.813 + break;
1.814 + case 'H':
1.815 + funerror=funH(array,limitsize,counter,tme);
1.816 + if(funerror)
1.817 + return 0;
1.818 + break;
1.819 + case 'I':
1.820 + funerror=funI(array,limitsize,counter,tme);
1.821 + if(funerror)
1.822 + return 0;
1.823 + break;
1.824 + case 'j':
1.825 + funerror=funj(array,limitsize,counter,tme);
1.826 + if(funerror)
1.827 + return 0;
1.828 + break;
1.829 + case 'k':
1.830 + funerror=funk(array,limitsize,counter,tme);
1.831 + if(funerror)
1.832 + return 0;
1.833 + break;
1.834 + case 'l':
1.835 + funerror=funl(array,limitsize,counter,tme);
1.836 + if(funerror)
1.837 + return 0;
1.838 + break;
1.839 + case 'm':
1.840 + funerror=funm(array,limitsize,counter,tme);
1.841 + if(funerror)
1.842 + return 0;
1.843 + break;
1.844 + case 'M':
1.845 + funerror=funM(array,limitsize,counter,tme);
1.846 + if(funerror)
1.847 + return 0;
1.848 + break;
1.849 + case 'p':
1.850 + funerror=funp(array,limitsize,counter,tme);
1.851 + if(funerror)
1.852 + return 0;
1.853 + break;
1.854 + case 'P':
1.855 + funerror=funP(array,limitsize,counter,tme);
1.856 + if(funerror)
1.857 + return 0;
1.858 + break;
1.859 + case 'r':
1.860 + funerror=funr(array,limitsize,counter,tme);
1.861 + if(funerror)
1.862 + return 0;
1.863 + break;
1.864 + case 'R':
1.865 + funerror=funR(array,limitsize,counter,tme);
1.866 + if(funerror)
1.867 + return 0;
1.868 + break;
1.869 + case 's':
1.870 + funerror=funs(array,limitsize,counter,tme);
1.871 + if(funerror)
1.872 + return 0;
1.873 + break;
1.874 + case 'S':
1.875 + funerror=funS(array,limitsize,counter,tme);
1.876 + if(funerror)
1.877 + return 0;
1.878 + break;
1.879 + case 'T':
1.880 + funerror=funT(array,limitsize,counter,tme);
1.881 + if(funerror)
1.882 + return 0;
1.883 + break;
1.884 + case 'u':
1.885 + funerror=funu(array,limitsize,counter,tme);
1.886 + if(funerror)
1.887 + return 0;
1.888 + break;
1.889 + case 'U':
1.890 + funerror=funU(array,limitsize,counter,tme);
1.891 + if(funerror)
1.892 + return 0;
1.893 + break;
1.894 + case 'w':
1.895 + funerror=funw(array,limitsize,counter,tme);
1.896 + if(funerror)
1.897 + return 0;
1.898 + break;
1.899 + case 'W':
1.900 + funerror=funW(array,limitsize,counter,tme);
1.901 + if(funerror)
1.902 + return 0;
1.903 + break;
1.904 + case 'x':
1.905 + funerror=funx(array,limitsize,counter,tme);
1.906 + if(funerror)
1.907 + return 0;
1.908 + break;
1.909 + case 'X':
1.910 + funerror=funX(array,limitsize,counter,tme);
1.911 + if(funerror)
1.912 + return 0;
1.913 + break;
1.914 + case'y':
1.915 + funerror=funy(array,limitsize,counter,tme);
1.916 + if(funerror)
1.917 + return 0;
1.918 + break;
1.919 + case 'Y':
1.920 + funerror=funY(array,limitsize,counter,tme);
1.921 + if(funerror)
1.922 + return 0;
1.923 + break;
1.924 + case 'Z':
1.925 + break;
1.926 + }
1.927 + }
1.928 + }
1.929 + else
1.930 + {
1.931 + return 0;
1.932 + }
1.933 + if (*pattern)
1.934 + pattern++;
1.935 + else
1.936 + break;
1.937 + }
1.938 + array[*counter]='\0';
1.939 + error=*counter;
1.940 + free (counter);
1.941 + counter=NULL;
1.942 + return error;
1.943 +}