You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by se...@apache.org on 2008/03/11 15:50:51 UTC

svn commit: r635956 - /webservices/axis2/trunk/c/util/src/date_time.c

Author: senaka
Date: Tue Mar 11 07:50:49 2008
New Revision: 635956

URL: http://svn.apache.org/viewvc?rev=635956&view=rev
Log:
Adding support for rounding fractional second part, and removing trailing '0's

Modified:
    webservices/axis2/trunk/c/util/src/date_time.c

Modified: webservices/axis2/trunk/c/util/src/date_time.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/date_time.c?rev=635956&r1=635955&r2=635956&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/date_time.c (original)
+++ webservices/axis2/trunk/c/util/src/date_time.c Tue Mar 11 07:50:49 2008
@@ -70,6 +70,11 @@
     date_time->min = utc_time->tm_min;
     date_time->sec = utc_time->tm_sec;
     date_time->msec = axutil_get_milliseconds(env);
+    /* Round off msec */
+    while (date_time->msec && !(date_time->msec % 10))
+    {
+        date_time->msec /= 10;
+    }
     date_time->tz_hour = 0;
     date_time->tz_min = 0;
     date_time->tz_pos = AXIS2_TRUE;
@@ -137,6 +142,11 @@
     {
         return AXIS2_FAILURE;
     }
+    /* Round off msec */
+    while (msec && !(msec % 10))
+    {
+        msec /= 10;
+    }
     date_time->hour = hour;
     date_time->min = min;
     date_time->sec = sec;
@@ -214,6 +224,11 @@
     {
         return AXIS2_FAILURE;
     }
+    /* Round off msec */
+    while (msec && !(msec % 10))
+    {
+        msec /= 10;
+    }
     if (tz_hour < 0 || tz_hour > 14)
     {
         return AXIS2_FAILURE;
@@ -373,6 +388,11 @@
     {
         return AXIS2_FAILURE;
     }
+    /* Round off msec */
+    while (msec && !(msec % 10))
+    {
+        msec /= 10;
+    }
     date_time->year = year - 1900;
     date_time->mon = mon - 1;
     date_time->day = day;
@@ -500,6 +520,11 @@
     {
         return AXIS2_FAILURE;
     }
+    /* Round off msec */
+    while (msec && !(msec % 10))
+    {
+        msec /= 10;
+    }
     if (tz_hour < 0 || tz_hour > 14)
     {
         return AXIS2_FAILURE;
@@ -705,6 +730,11 @@
     {
         return AXIS2_FAILURE;
     }
+    /* Round off msec */
+    while (msec && !(msec % 10))
+    {
+        msec /= 10;
+    }
 
     date_time->year = year - 1900;
     date_time->mon = mon - 1;
@@ -729,9 +759,16 @@
     time_str =
         (axis2_char_t *) AXIS2_MALLOC(env->allocator,
                                       sizeof(axis2_char_t) * 32);
-
-    sprintf(time_str, "%02d:%02d:%02d.%03dZ", date_time->hour, date_time->min,
-            date_time->sec, date_time->msec);
+    if (date_time->msec)
+    {
+        sprintf(time_str, "%02d:%02d:%02d.%03dZ", date_time->hour, date_time->min,
+                date_time->sec, date_time->msec);
+    }
+    else
+    {
+        sprintf(time_str, "%02d:%02d:%02dZ", date_time->hour, date_time->min,
+                date_time->sec);
+    }
     return time_str;
 }
 
@@ -747,10 +784,18 @@
     time_str =
         (axis2_char_t *) AXIS2_MALLOC(env->allocator,
                                       sizeof(axis2_char_t) * 37);
-
-    sprintf(time_str, "%02d:%02d:%02d.%03d%c%02d:%02d", date_time->hour, date_time->min,
-            date_time->sec, date_time->msec, date_time->tz_pos ? '+': '-',
-            date_time->tz_hour, date_time->tz_min);
+    if (date_time->msec)
+    {
+        sprintf(time_str, "%02d:%02d:%02d.%03d%c%02d:%02d", date_time->hour, date_time->min,
+                date_time->sec, date_time->msec, date_time->tz_pos ? '+': '-',
+                date_time->tz_hour, date_time->tz_min);
+    }
+    else
+    {
+        sprintf(time_str, "%02d:%02d:%02d%c%02d:%02d", date_time->hour, date_time->min,
+                date_time->sec, date_time->tz_pos ? '+': '-',
+                date_time->tz_hour, date_time->tz_min);
+    }
     return time_str;
 }
 
@@ -782,9 +827,18 @@
     AXIS2_ENV_CHECK(env, NULL);
 
     date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 32);
-    sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02d.%03dZ",
-            date_time->year + 1900, date_time->mon + 1, date_time->day,
-            date_time->hour, date_time->min, date_time->sec, date_time->msec);
+    if (date_time->msec)
+    {
+        sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02d.%03dZ",
+                date_time->year + 1900, date_time->mon + 1, date_time->day,
+                date_time->hour, date_time->min, date_time->sec, date_time->msec);
+    }
+    else
+    {
+        sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02dZ",
+                date_time->year + 1900, date_time->mon + 1, date_time->day,
+                date_time->hour, date_time->min, date_time->sec);
+    }
     return date_time_str;
 }
 
@@ -798,10 +852,20 @@
     AXIS2_ENV_CHECK(env, NULL);
 
     date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 37);
-    sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d",
-            date_time->year + 1900, date_time->mon + 1, date_time->day,
-            date_time->hour, date_time->min, date_time->sec, date_time->msec, 
-            date_time->tz_pos ? '+': '-', date_time->tz_hour, date_time->tz_min);
+    if (date_time->msec)
+    {
+        sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d",
+                date_time->year + 1900, date_time->mon + 1, date_time->day,
+                date_time->hour, date_time->min, date_time->sec, date_time->msec, 
+                date_time->tz_pos ? '+': '-', date_time->tz_hour, date_time->tz_min);
+    }
+    else
+    {
+        sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+                date_time->year + 1900, date_time->mon + 1, date_time->day,
+                date_time->hour, date_time->min, date_time->sec,
+                date_time->tz_pos ? '+': '-', date_time->tz_hour, date_time->tz_min);
+    }
     return date_time_str;
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org