← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba

 

Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Code clean-up.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/150490

Code clean-up.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/150490
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp'
--- src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp	2013-01-16 15:16:33 +0000
+++ src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp	2013-02-26 05:27:25 +0000
@@ -15,6 +15,8 @@
  */
 #include "stdafx.h"
 
+#include <cstdlib>
+
 #include "zorbatypes/datetime.h"
 #include "zorbatypes/duration.h"
 #include "zorbatypes/numconversions.h"
@@ -501,7 +503,7 @@
   }
   else
   {
-    if (parse_long(str.c_str(), str.size(), position, min_width, -1, -1, 1))
+    if (parse_long(str.data(), str.size(), position, min_width, -1, -1, 1))
       min_width = -3;
   }
 
@@ -520,7 +522,7 @@
   }
   else
   {
-    if (parse_long(str.c_str(), str.size(), position, max_width, -1, -1, 1))
+    if (parse_long(str.data(), str.size(), position, max_width, -1, -1, 1))
       min_width = -3;
   }
 }
@@ -669,7 +671,7 @@
         switch (component)
         {
         case 'Y':
-          output_year(resultString, abs<int>(dateTimeItem->getDateTimeValue().getYear()), modifier);
+          output_year(resultString, std::abs(dateTimeItem->getDateTimeValue().getYear()), modifier);
           break;
         case 'M':
           output_month(resultString, dateTimeItem->getDateTimeValue().getMonth(), modifier);

=== modified file 'src/zorbatypes/datetime.h'
--- src/zorbatypes/datetime.h	2012-11-17 01:08:54 +0000
+++ src/zorbatypes/datetime.h	2013-02-26 05:27:25 +0000
@@ -59,7 +59,7 @@
 public:
       
   /** Available facets for the DateTime class */
-  typedef enum 
+  enum FACET_TYPE
   {
     DATETIME_FACET = 0,
     DATE_FACET = 1,
@@ -69,12 +69,12 @@
     GMONTH_FACET = 5,
     GMONTHDAY_FACET = 6,
     GDAY_FACET = 7
-  } FACET_TYPE;
+  };
 
   // Only year may be negative, all other must be positive
   // The year gives the sign of DateTime, Date, etc
       
-  typedef enum
+  enum DATA_TYPE
   {
     YEAR_DATA = 0,
     MONTH_DATA = 1,
@@ -83,7 +83,7 @@
     MINUTE_DATA = 4,
     SECONDS_DATA = 5,
     FRACSECONDS_DATA = 6
-  } DATA_TYPE;
+  };
 
 
   static const int FACET_MEMBERS[8][8];

=== modified file 'src/zorbatypes/datetime/datetimetype.cpp'
--- src/zorbatypes/datetime/datetimetype.cpp	2012-11-17 01:08:54 +0000
+++ src/zorbatypes/datetime/datetimetype.cpp	2013-02-26 05:27:25 +0000
@@ -15,6 +15,8 @@
  */
 #include "stdafx.h"
 
+#include <cstdlib>
+#include <cmath>
 #include <string>
 #include <exception>
 #include <cassert>
@@ -128,12 +130,12 @@
 {
   dt.facet = DATETIME_FACET;
   dt.data[YEAR_DATA] = years;
-  dt.data[MONTH_DATA] = abs<int>(months);
-  dt.data[DAY_DATA] = abs<int>(days);
-  dt.data[HOUR_DATA] = abs<int>(hours);
-  dt.data[MINUTE_DATA] = abs<int>(minutes);
-  dt.data[SECONDS_DATA] = abs<int>(seconds);
-  dt.data[FRACSECONDS_DATA] = abs<int>(fractional_seconds);
+  dt.data[MONTH_DATA] = std::abs(months);
+  dt.data[DAY_DATA] = std::abs(days);
+  dt.data[HOUR_DATA] = std::abs(hours);
+  dt.data[MINUTE_DATA] = std::abs(minutes);
+  dt.data[SECONDS_DATA] = std::abs(seconds);
+  dt.data[FRACSECONDS_DATA] = std::abs(fractional_seconds);
   return 0;
 }
 
@@ -150,12 +152,12 @@
 {
   dt.facet = DATETIME_FACET;
   dt.data[YEAR_DATA] = years;
-  dt.data[MONTH_DATA] = abs<int>(months);
-  dt.data[DAY_DATA] = abs<int>(days);
-  dt.data[HOUR_DATA] = abs<int>(hours);
-  dt.data[MINUTE_DATA] = abs<int>(minutes);
-  dt.data[SECONDS_DATA] = floor<double>(abs<double>(seconds));
-  dt.data[FRACSECONDS_DATA] = round(frac(abs<double>(seconds)) * FRAC_SECONDS_UPPER_LIMIT);
+  dt.data[MONTH_DATA] = std::abs(months);
+  dt.data[DAY_DATA] = std::abs(days);
+  dt.data[HOUR_DATA] = std::abs(hours);
+  dt.data[MINUTE_DATA] = std::abs(minutes);
+  dt.data[SECONDS_DATA] = std::floor(std::fabs(seconds));
+  dt.data[FRACSECONDS_DATA] = round(frac(std::fabs(seconds)) * FRAC_SECONDS_UPPER_LIMIT);
   
   if (tz != NULL)
     dt.the_time_zone = *tz;
@@ -177,12 +179,12 @@
 {
   dt.facet = DATETIME_FACET;
   dt.data[YEAR_DATA] = years;
-  dt.data[MONTH_DATA] = abs<int>(months);
-  dt.data[DAY_DATA] = abs<int>(days);
-  dt.data[HOUR_DATA] = abs<int>(hours);
-  dt.data[MINUTE_DATA] = abs<int>(minutes);
-  dt.data[SECONDS_DATA] = abs<int>(seconds);
-  dt.data[FRACSECONDS_DATA] = abs<int>(fractional_seconds);
+  dt.data[MONTH_DATA] = std::abs(months);
+  dt.data[DAY_DATA] = std::abs(days);
+  dt.data[HOUR_DATA] = std::abs(hours);
+  dt.data[MINUTE_DATA] = std::abs(minutes);
+  dt.data[SECONDS_DATA] = std::abs(seconds);
+  dt.data[FRACSECONDS_DATA] = std::abs(fractional_seconds);
       
   if (tz != NULL)
     dt.the_time_zone = *tz;
@@ -200,8 +202,8 @@
 {
   dt.facet = DATE_FACET;
   dt.data[YEAR_DATA] = years;
-  dt.data[MONTH_DATA] = abs<int>(months);
-  dt.data[DAY_DATA] = abs<int>(days);
+  dt.data[MONTH_DATA] = std::abs(months);
+  dt.data[DAY_DATA] = std::abs(days);
   dt.data[HOUR_DATA] = 0;
   dt.data[MINUTE_DATA] = 0;
   dt.data[SECONDS_DATA] = 0;
@@ -225,10 +227,10 @@
   dt.data[YEAR_DATA] = 1;
   dt.data[MONTH_DATA] = 1;
   dt.data[DAY_DATA] = 1;
-  dt.data[HOUR_DATA] = abs<int>(hours);
-  dt.data[MINUTE_DATA] = abs<int>(minutes);
-  dt.data[SECONDS_DATA] = floor<double>(abs<double>(seconds));
-  dt.data[FRACSECONDS_DATA] = round(frac(abs<double>(seconds)) * FRAC_SECONDS_UPPER_LIMIT);
+  dt.data[HOUR_DATA] = std::abs(hours);
+  dt.data[MINUTE_DATA] = std::abs(minutes);
+  dt.data[SECONDS_DATA] = std::floor(std::fabs(seconds));
+  dt.data[FRACSECONDS_DATA] = round(frac(std::fabs(seconds)) * FRAC_SECONDS_UPPER_LIMIT);
       
   if (tz != NULL)
     dt.the_time_zone = *tz;
@@ -241,7 +243,7 @@
 {
   dt.facet = GYEARMONTH_FACET;
   dt.data[YEAR_DATA] = years;
-  dt.data[MONTH_DATA] = abs<int>(months);
+  dt.data[MONTH_DATA] = std::abs(months);
   dt.data[DAY_DATA] = 1;
   dt.data[HOUR_DATA] = 0;
   dt.data[MINUTE_DATA] = 0;
@@ -271,7 +273,7 @@
 {
   dt.facet = GMONTH_FACET;
   dt.data[YEAR_DATA] = 1;
-  dt.data[MONTH_DATA] = abs<int>(months);
+  dt.data[MONTH_DATA] = std::abs(months);
   dt.data[DAY_DATA] = 1;
   dt.data[HOUR_DATA] = 0;
   dt.data[MINUTE_DATA] = 0;
@@ -286,8 +288,8 @@
 {
   dt.facet = GMONTHDAY_FACET;
   dt.data[YEAR_DATA] = 1;
-  dt.data[MONTH_DATA] = abs<int>(months);
-  dt.data[DAY_DATA] = abs<int>(days);
+  dt.data[MONTH_DATA] = std::abs(months);
+  dt.data[DAY_DATA] = std::abs(days);
   dt.data[HOUR_DATA] = 0;
   dt.data[MINUTE_DATA] = 0;
   dt.data[SECONDS_DATA] = 0;
@@ -302,7 +304,7 @@
   dt.facet = GDAY_FACET;
   dt.data[YEAR_DATA] = 1;
   dt.data[MONTH_DATA] = 1;
-  dt.data[DAY_DATA] = abs<int>(days);
+  dt.data[DAY_DATA] = std::abs(days);
   dt.data[HOUR_DATA] = 0;
   dt.data[MINUTE_DATA] = 0;
   dt.data[SECONDS_DATA] = 0;
@@ -341,29 +343,29 @@
 }
 
 
-int DateTime::parseDateTime(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseDateTime(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
 
   // DateTime is of form: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = DATETIME_FACET;
   
   if (parse_date(str,
-                 strlen,
+                 len,
                  pos,
                  dt.data[YEAR_DATA],
                  dt.data[MONTH_DATA],
                  dt.data[DAY_DATA]))
     return 1;
 
-  if (pos == strlen || str[pos++] != 'T')
+  if (pos == len || str[pos++] != 'T')
     return 1;
   
   if (parse_time(str,
-                 strlen,
+                 len,
                  pos,
                  dt.data[HOUR_DATA],
                  dt.data[MINUTE_DATA],
@@ -373,15 +375,15 @@
     
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
     if (0 != TimeZone::parseTimeZone(str + pos,
-                                     strlen - pos,
+                                     len - pos,
                                      dt.the_time_zone))
       return 1;
   }
@@ -398,17 +400,17 @@
 }
 
 
-int DateTime::parseDate(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseDate(const char* str, ascii::size_type len, DateTime& dt)
 {
   TimeZone tz;
   ascii::size_type pos = 0;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = DATE_FACET;
   
   if (parse_date(str,
-                 strlen,
+                 len,
                  pos,
                  dt.data[YEAR_DATA],
                  dt.data[MONTH_DATA],
@@ -417,14 +419,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
   
@@ -432,15 +434,15 @@
 }
 
 
-int DateTime::parseTime(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseTime(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = TIME_FACET;
   
-  if (parse_time(str, strlen, pos,
+  if (parse_time(str, len, pos,
                  dt.data[HOUR_DATA],
                  dt.data[MINUTE_DATA],
                  dt.data[SECONDS_DATA],
@@ -449,14 +451,14 @@
     
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
   
@@ -467,7 +469,7 @@
 }
 
 
-int DateTime::parseGYearMonth(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseGYearMonth(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
   ascii::size_type temp_pos = 0;
@@ -475,18 +477,18 @@
 
   // GYearMonth of form: '-'? yyyy '-' mm zzzzzz?
   
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = GYEARMONTH_FACET;
   
   if (str[pos] == '-')
   {
-    temp.append(str + pos, (8 < strlen - pos ? 8 : strlen - pos));
+    temp.append(str + pos, (8 < len - pos ? 8 : len - pos));
     ++pos;
   }
   else
   {
-    temp.append(str + pos, (7 < strlen - pos ? 7 : strlen - pos));
+    temp.append(str + pos, (7 < len - pos ? 7 : len - pos));
   }
 
   temp += "-01";
@@ -503,14 +505,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
 
@@ -518,7 +520,7 @@
 }
 
 
-int DateTime::parseGYear(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseGYear(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
   ascii::size_type temp_pos = 0;
@@ -526,7 +528,7 @@
 
   // GYear of form: '-'? yyyy zzzzzz?
   
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = GYEAR_FACET;
   
@@ -534,12 +536,12 @@
 
   if (str[pos] == '-')
   {
-    temp.append(str + pos, (5 < strlen - pos ? 5 : strlen - pos));
+    temp.append(str + pos, (5 < len - pos ? 5 : len - pos));
     ++pos;
   }
   else
   {
-    temp.append(str + pos, (4 < strlen - pos ? 4 : strlen - pos));
+    temp.append(str + pos, (4 < len - pos ? 4 : len - pos));
   }
 
   temp += "-01-01";
@@ -556,14 +558,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
 
@@ -571,7 +573,7 @@
 }
 
 
-int DateTime::parseGMonth(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseGMonth(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
   ascii::size_type temp_pos = 0;
@@ -580,7 +582,7 @@
   // GMonth of form: --MM zzzzzz?
   // preceding - is not allowed.
   
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = GMONTH_FACET;
   
@@ -604,14 +606,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
 
@@ -619,7 +621,7 @@
 }
 
 
-int DateTime::parseGMonthDay(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseGMonthDay(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
   ascii::size_type temp_pos = 0;
@@ -628,7 +630,7 @@
   // GMonthDay of form: --MM-DD zzzzzz?
   // preceding - is not allowed.
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = GMONTHDAY_FACET;
   
@@ -653,14 +655,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
 
@@ -668,7 +670,7 @@
 }
 
 
-int DateTime::parseGDay(const char* str, ascii::size_type strlen, DateTime& dt)
+int DateTime::parseGDay(const char* str, ascii::size_type len, DateTime& dt)
 {
   ascii::size_type pos = 0;
   ascii::size_type temp_pos = 0;
@@ -677,7 +679,7 @@
   // GDay of form: ---DD zzzzzz?
   // preceding - is not allowed.
   
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
   dt.facet = GDAY_FACET;
   
@@ -702,14 +704,14 @@
 
   ascii::size_type savepos = pos;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (savepos != pos && pos != strlen)
+  if (savepos != pos && pos != len)
     return 1;
 
-  if (pos < strlen)
+  if (pos < len)
   {
-    if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone))
+    if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone))
       return 1;
   }
 
@@ -720,7 +722,7 @@
 // Returns 0 on success
 int DateTime::parse_date(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     ascii::size_type& pos,
     long& year,
     long& month,
@@ -729,7 +731,7 @@
   bool is_negative = false;
   ascii::size_type temp_pos;
   
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == '-')
@@ -741,7 +743,7 @@
   // Parse year
   temp_pos = pos;
 
-  if (pos == strlen || parse_long(str, strlen, pos, year, 4))
+  if (pos == len || parse_long(str, len, pos, year, 4))
     return 1;
 
   if (pos - temp_pos > 4 && str[temp_pos] == '0')
@@ -750,18 +752,18 @@
   if (is_negative)
     year = -year;
 
-  if (pos == strlen || str[pos++] != '-')
+  if (pos == len || str[pos++] != '-')
     return 1;
 
   // Parse month
-  if (pos == strlen || parse_long(str, strlen, pos, month, 2, 2))
+  if (pos == len || parse_long(str, len, pos, month, 2, 2))
     return 1;
 
-  if (pos == strlen || str[pos++] != '-')
+  if (pos == len || str[pos++] != '-')
     return 1;
 
   // Parse day
-  if (pos == strlen || parse_long(str, strlen, pos, day, 2, 2))
+  if (pos == len || parse_long(str, len, pos, day, 2, 2))
     return 1;
   
   // Validate the date
@@ -782,40 +784,40 @@
 // Returns 0 on success
 int DateTime::parse_time(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     ascii::size_type& position,
     long& hour,
     long& minute,
     long& seconds,
     long& frac_seconds)
 {
-  if (position == strlen)
+  if (position == len)
     return 1;
   
   // Parse hour
-  if (position == strlen || parse_long(str, strlen, position, hour, 2, 2))
+  if (position == len || parse_long(str, len, position, hour, 2, 2))
     return 1;
 
-  if (position == strlen || str[position++] != ':')
+  if (position == len || str[position++] != ':')
     return 1;
 
   // Parse minute
-  if (position == strlen || parse_long(str, strlen, position, minute, 2, 2))
+  if (position == len || parse_long(str, len, position, minute, 2, 2))
     return 1;
 
-  if (position == strlen || str[position++] != ':')
+  if (position == len || str[position++] != ':')
     return 1;
 
   // Parse seconds
-  if (position == strlen || parse_long(str, strlen, position, seconds, 2, 2))
+  if (position == len || parse_long(str, len, position, seconds, 2, 2))
     return 1;
   
-  if (position < strlen && str[position] == '.')
+  if (position < len && str[position] == '.')
   {
     double temp_frac_seconds;
     position++;
 
-    if (parse_frac(str, strlen, position, temp_frac_seconds))
+    if (parse_frac(str, len, position, temp_frac_seconds))
       return 1;
 
     frac_seconds = round(temp_frac_seconds * FRAC_SECONDS_UPPER_LIMIT);
@@ -885,7 +887,7 @@
   {
     if (FACET_MEMBERS[facet][i])
     {
-      result.append(to_string(abs<int>(data[i]), min_length[i]));
+      result.append(zero_pad(std::abs(data[i]), min_length[i]));
       if (FACET_MEMBERS[facet][i+1] && i<=4)
         result.push_back(separators[i]);
     }
@@ -909,7 +911,7 @@
     while (temp%10 == 0 && temp > 0)
       temp = temp / 10;
     
-    result.append(to_string(temp));
+    result.append(ztd::to_string(temp));
   }
   
   result.append(the_time_zone.toString());
@@ -1060,7 +1062,7 @@
 {
   if (data[YEAR_DATA] >= 0)
     return new Duration(Duration::DAYTIMEDURATION_FACET, false, 0, 0,
-                        365 * (abs<int>(data[YEAR_DATA]) - 1) +
+                        365 * (std::abs(data[YEAR_DATA]) - 1) +
                           leap_years_count(data[YEAR_DATA]) +
                           DateTime::getDayOfYear(data[YEAR_DATA],
                             data[MONTH_DATA],
@@ -1072,7 +1074,7 @@
   else
   {
     Duration days(Duration::DAYTIMEDURATION_FACET, true, 0, 0,
-                         365 * abs<int>(data[YEAR_DATA]) -
+                         365 * std::abs(data[YEAR_DATA]) -
                          leap_years_count(data[YEAR_DATA]) -
                          DateTime::getDayOfYear(data[YEAR_DATA],
                                                data[MONTH_DATA],
@@ -1144,7 +1146,7 @@
     else
       break;
 
-    years = years + quotient<int>(months + carry-1, 12);
+    years += quotient<int>(months + carry-1, 12);
     months = modulo<int>(months + carry -1, 12) + 1;
   }
   

=== modified file 'src/zorbatypes/datetime/duration.cpp'
--- src/zorbatypes/datetime/duration.cpp	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/datetime/duration.cpp	2013-02-26 05:27:25 +0000
@@ -15,8 +15,9 @@
  */
 #include "stdafx.h"
 
+#include <cmath>
+#include <memory>
 #include <string>
-#include <memory>
 
 #include "zorbautils/hashfun.h"
 #include "zorbatypes/duration.h"
@@ -47,26 +48,26 @@
 *******************************************************************************/
 static int parse_s_string(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     ascii::size_type& pos,
     long& seconds,
     long& frac_seconds)
 {
   ascii::size_type savepos = pos;
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
   int err;
 
   if (pos != savepos) {
-    return (pos != strlen ? 1 : 0);
+    return (pos != len ? 1 : 0);
   }
 
   long result;
 
-  if ((err = parse_long(str, strlen, pos, result)) != 0) {
+  if ((err = parse_long(str, len, pos, result)) != 0) {
     return err;
   }
 
-  if (pos == strlen) {
+  if (pos == len) {
     return 1;
   }
 
@@ -78,11 +79,11 @@
     seconds = result;
 
     double temp_frac_seconds = 0;
-    if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0) {
+    if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0) {
       return err;
     }
 
-    if (pos == strlen || str[pos] != 'S') {
+    if (pos == len || str[pos] != 'S') {
       return 1;
     }
 
@@ -99,25 +100,25 @@
 *******************************************************************************/
 static int parse_ms_string(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     ascii::size_type& pos,
     long& minutes,
     long& seconds,
     long& frac_seconds)
 {
   ascii::size_type savepos = pos;
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
   int err;
 
   if (pos != savepos)
-    return (pos != strlen ? 1 : 0);
+    return (pos != len ? 1 : 0);
 
   long result;
 
-  if ((err = parse_long(str, strlen, pos, result)) != 0)
+  if ((err = parse_long(str, len, pos, result)) != 0)
     return err;
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == 'M')
@@ -125,7 +126,7 @@
     pos++;
     minutes = result;
 
-    if (pos < strlen && (err = parse_s_string(str, strlen, pos, seconds, frac_seconds)) != 0)
+    if (pos < len && (err = parse_s_string(str, len, pos, seconds, frac_seconds)) != 0)
       return err;
   }
   else if (str[pos] == 'S')
@@ -139,10 +140,10 @@
     seconds = result;
 
     double temp_frac_seconds = 0;
-    if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0)
+    if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0)
       return err;
 
-    if (pos == strlen || str[pos] != 'S')
+    if (pos == len || str[pos] != 'S')
       return 1;
 
     pos++;
@@ -158,7 +159,7 @@
 *******************************************************************************/
 static int parse_hms_string(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     ascii::size_type& pos,
     long& hours,
     long& minutes,
@@ -168,10 +169,10 @@
   long result;
   int err;
 
-  if ((err = parse_long(str, strlen, pos, result)) != 0)
+  if ((err = parse_long(str, len, pos, result)) != 0)
     return err;
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == 'H')
@@ -180,7 +181,7 @@
 
     hours = result;
 
-    if (pos < strlen && (err = parse_ms_string(str, strlen, pos, minutes, seconds, frac_seconds)) != 0)
+    if (pos < len && (err = parse_ms_string(str, len, pos, minutes, seconds, frac_seconds)) != 0)
       return err;
   }
   else if (str[pos] == 'M')
@@ -189,7 +190,7 @@
 
     minutes = result;
 
-    if (pos < strlen && (err = parse_s_string(str, strlen, pos, seconds, frac_seconds)) != 0)
+    if (pos < len && (err = parse_s_string(str, len, pos, seconds, frac_seconds)) != 0)
       return err;
   }
   else if (str[pos] == 'S')
@@ -203,10 +204,10 @@
     seconds = result;
 
     double temp_frac_seconds;
-    if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0)
+    if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0)
       return err;
 
-    if (pos == strlen || str[pos] != 'S')
+    if (pos == len || str[pos] != 'S')
       return 1;
 
     pos++;
@@ -217,14 +218,14 @@
 }
 
 
-int Duration::parseDuration(const char* str, ascii::size_type strlen, Duration& d)
+int Duration::parseDuration(const char* str, ascii::size_type len, Duration& d)
 {
   zstring::size_type ym_pos;
   zstring::size_type t_pos;
   int err;
 
   zstring_b wrap;
-  wrap.wrap_memory(const_cast<char*>(str), strlen);
+  wrap.wrap_memory(const_cast<char*>(str), len);
 
   t_pos = wrap.find('T');
   ym_pos = wrap.find('M');
@@ -241,16 +242,16 @@
       return err;
 
     ascii::size_type pos = ym_pos+1;
-    ascii::skip_whitespace(str, strlen, &pos);
+    ascii::skip_whitespace(str, len, &pos);
 
-    if (pos > ym_pos + 1 && pos != strlen)
+    if (pos > ym_pos + 1 && pos != len)
       return 1;
 
-    if (pos < strlen)
+    if (pos < len)
     {
       Duration dtd;
 
-      if ((err = parseDayTimeDuration(str + pos, strlen - ym_pos -1, dtd, true)) != 0)
+      if ((err = parseDayTimeDuration(str + pos, len - ym_pos -1, dtd, true)) != 0)
         return err;
 
       for (int i = DAY_DATA; i <= FRACSECONDS_DATA; ++i)
@@ -260,7 +261,7 @@
   else
   {
     // No month or year -- parse DayTime
-    if ((err = parseDayTimeDuration(str, strlen, d)) != 0)
+    if ((err = parseDayTimeDuration(str, len, d)) != 0)
       return err;
   }
 
@@ -269,7 +270,7 @@
 }
 
 
-int Duration::parseYearMonthDuration(const char* str, ascii::size_type strlen, Duration& d)
+int Duration::parseYearMonthDuration(const char* str, ascii::size_type len, Duration& d)
 {
   bool negative = false;
   ascii::size_type pos = 0;
@@ -277,9 +278,9 @@
   long months = 0;
   int err;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == '-')
@@ -288,13 +289,13 @@
     pos++;
   }
 
-  if (pos == strlen || str[pos++] != 'P')
+  if (pos == len || str[pos++] != 'P')
     return 1;
 
-  if ((err = parse_long(str, strlen, pos, result)) != 0)
+  if ((err = parse_long(str, len, pos, result)) != 0)
     return err;
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == 'Y')
@@ -302,9 +303,9 @@
     pos++;
     months = result * 12;
 
-    if (pos < strlen)
+    if (pos < len)
     {
-      if ((err = parse_long(str, strlen, pos, result)) != 0)
+      if ((err = parse_long(str, len, pos, result)) != 0)
         return err;
 
       if (str[pos++] != 'M')
@@ -322,9 +323,9 @@
     return 1;
   }
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (strlen != pos)
+  if (len != pos)
     return 1;
 
   d = Duration(YEARMONTHDURATION_FACET, negative, 0, months, 0, 0, 0, 0);
@@ -338,7 +339,7 @@
 ********************************************************************************/
 int Duration::parseDayTimeDuration(
     const char* str,
-    ascii::size_type strlen,
+    ascii::size_type len,
     Duration& d,
     bool dont_check_letter_p)
 {
@@ -347,9 +348,9 @@
   long days = 0, hours = 0, minutes = 0, seconds = 0, frac_seconds = 0;
   int err;
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   if (str[pos] == '-')
@@ -358,38 +359,38 @@
     pos++;
   }
 
-  if (!dont_check_letter_p && (pos == strlen || str[pos++] != 'P'))
+  if (!dont_check_letter_p && (pos == len || str[pos++] != 'P'))
     return 1;
 
-  if (pos == strlen)
+  if (pos == len)
     return 1;
 
   // It must be either 'T' or 'nD'
   if (str[pos] != 'T')
   {
     long result = 0;
-    if ((err = parse_long(str, strlen, pos, result)) != 0)
+    if ((err = parse_long(str, len, pos, result)) != 0)
       return err;
 
     days = result;
 
-    if (pos == strlen || str[pos++] != 'D')
+    if (pos == len || str[pos++] != 'D')
       return 1;
   }
 
   // Either 'T', or whitespace, or end
 
-  if (pos < strlen && str[pos] == 'T')
+  if (pos < len && str[pos] == 'T')
   {
     pos++;
 
-    if ((err = parse_hms_string(str, strlen, pos, hours, minutes, seconds, frac_seconds)) != 0)
+    if ((err = parse_hms_string(str, len, pos, hours, minutes, seconds, frac_seconds)) != 0)
       return err;
   }
 
-  ascii::skip_whitespace(str, strlen, &pos);
+  ascii::skip_whitespace(str, len, &pos);
 
-  if (strlen != pos)
+  if (len != pos)
     return 1;
 
   long carry = seconds / 60;
@@ -461,7 +462,7 @@
     long minutes,
     double seconds)
 {
-  seconds = abs<double>(seconds);
+  seconds = std::fabs(seconds);
 
   is_negative = false;
   if (years != 0 && years < 0)
@@ -478,12 +479,12 @@
     is_negative = true;
 
   facet = facet_type;
-  data[YEAR_DATA] = abs<long>(years);
-  data[MONTH_DATA] = abs<long>(months);
-  data[DAY_DATA] = abs<long>(days);
-  data[HOUR_DATA] = abs<long>(hours);
-  data[MINUTE_DATA] = abs<long>(minutes);
-  data[SECONDS_DATA] = floor<double>(seconds);
+  data[YEAR_DATA] = std::abs(years);
+  data[MONTH_DATA] = std::abs(months);
+  data[DAY_DATA] = std::abs(days);
+  data[HOUR_DATA] = std::abs(hours);
+  data[MINUTE_DATA] = std::abs(minutes);
+  data[SECONDS_DATA] = std::floor(seconds);
   data[FRACSECONDS_DATA] = round(frac(seconds) * FRAC_SECONDS_UPPER_LIMIT);
 
   normalize();
@@ -500,16 +501,16 @@
     long minutes,
     double seconds)
 {
-  seconds = abs<double>(seconds);
+  seconds = std::fabs(seconds);
 
   facet = facet_type;
   is_negative = negative;
-  data[YEAR_DATA] = abs<long>(years);
-  data[MONTH_DATA] = abs<long>(months);
-  data[DAY_DATA] = abs<long>(days);
-  data[HOUR_DATA] = abs<long>(hours);
-  data[MINUTE_DATA] = abs<long>(minutes);
-  data[SECONDS_DATA] = floor<double>(seconds);
+  data[YEAR_DATA] = std::abs(years);
+  data[MONTH_DATA] = std::abs(months);
+  data[DAY_DATA] = std::abs(days);
+  data[HOUR_DATA] = std::abs(hours);
+  data[MINUTE_DATA] = std::abs(minutes);
+  data[SECONDS_DATA] = std::floor(seconds);
   data[FRACSECONDS_DATA] = round(frac(seconds) * FRAC_SECONDS_UPPER_LIMIT);
 
   normalize();
@@ -523,13 +524,13 @@
 {
   facet = facet_type;
   is_negative = negative;
-  data[YEAR_DATA] = abs<long>(years);
-  data[MONTH_DATA] = abs<long>(months);
-  data[DAY_DATA] = abs<long>(days);
-  data[HOUR_DATA] = abs<long>(hours);
-  data[MINUTE_DATA] = abs<long>(minutes);
-  data[SECONDS_DATA] = abs<long>(seconds);
-  data[FRACSECONDS_DATA] = abs<long>(frac_seconds);
+  data[YEAR_DATA] = std::abs(years);
+  data[MONTH_DATA] = std::abs(months);
+  data[DAY_DATA] = std::abs(days);
+  data[HOUR_DATA] = std::abs(hours);
+  data[MINUTE_DATA] = std::abs(minutes);
+  data[SECONDS_DATA] = std::abs(seconds);
+  data[FRACSECONDS_DATA] = std::abs(frac_seconds);
 
   normalize();
 }
@@ -693,7 +694,7 @@
     {
       double sum = double(data[i] + (right_operand_sign? -1 : 1) * d.data[i]) / FRAC_SECONDS_UPPER_LIMIT;
       result->data[FRACSECONDS_DATA] = round(frac(sum)*FRAC_SECONDS_UPPER_LIMIT);
-      carry = floor<double>(sum);
+      carry = std::floor(sum);
     }
     else
     {
@@ -977,7 +978,7 @@
         while (frac_seconds%10 == 0 && frac_seconds > 0)
           frac_seconds = frac_seconds / 10;
 
-        result.append(to_string(frac_seconds));
+        result.append(ztd::to_string(frac_seconds));
       }
 
       result.append("S", 1);

=== modified file 'src/zorbatypes/datetime/parse.cpp'
--- src/zorbatypes/datetime/parse.cpp	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/datetime/parse.cpp	2013-02-26 05:27:25 +0000
@@ -15,8 +15,13 @@
  */
 #include "stdafx.h"
 
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+#include "util/ascii_util.h"
+#include "util/time_util.h"
 #include "zorbatypes/datetime/parse.h"
-#include <string>
 
 namespace zorba
 {
@@ -29,7 +34,7 @@
   must obey these conditions, or the function will return an error.
 
   @param str The source string to parse
-  @param str_len the length of the input string
+  @param len the length of the input string
   @param position The position to start parsing from
   @param result Contains the result of the parsing
   @param min_digits Minimum number of digits
@@ -41,16 +46,16 @@
 ********************************************************************************/
 int parse_long(
     const char* str,
-    ascii::size_type str_len,
-    ascii::size_type& position,
+    size_t len,
+    size_t& position,
     long& result,
     long min_digits,
     long max_digits,
-    long delta)
+    size_t delta)
 {
   long digits = 0;
 
-  if (position + delta >= str_len)
+  if (position + delta >= len)
     return 1;
 
   if (str[position+delta] < '0' || str[position+delta] > '9')
@@ -58,8 +63,7 @@
 
   result = 0;
 
-  while (position + delta < str_len &&
-         str[position+delta] >= '0' && str[position+delta] <= '9')
+  while ( position + delta < len && ascii::is_digit( str[position+delta] ) )
   {
     result = 10 * result + str[position + delta] - '0';
     position++;
@@ -80,45 +84,11 @@
 
 
 
-bool is_digit(char ch)
-{
-  return (ch >= '0' && ch <= '9');
-}
-
-
-// checks if a number of count chars, starting with position, are digits
-bool are_digits(std::string& s, unsigned int& position, int count)
-{
-  for(unsigned int i = position; i < position+count; i++)
-    if (s[i] < '0' || s[i] > '9')
-      return false;
-
-  return true;
-}
-
-
-static bool is_leap_year(int year)
-{
-  if (((year%4 == 0) && (year%100 != 0))
-        ||
-        (year%400 == 0))
-    return true;
-  else
-    return false;
-}
-
-
-int get_last_day(int year, int month)
-{
-  static const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-  year = year + quotient<int>(month-1, 12);
-  month = modulo<int>(month-1, 12) + 1;
-
-  if (is_leap_year(year) && month == 2)
-    return 29;
-  else
-    return days[month-1];
+int get_last_day( int year, int month ) {
+  --month;
+  year += quotient<int>( month, 12 );
+  month = modulo<int>( month, 12 );
+  return time::days_in_month( month, year );
 }
 
 int leap_years_count(int year)
@@ -127,5 +97,32 @@
   return year/4 - year/100 + year/400;
 }
 
+
+int parse_frac( char const *str, size_t len, size_t &pos, double &result )
+{
+  if (pos >= len)
+    return 1;
+
+  if ( !ascii::is_digit( str[pos] ) )
+    return 1;
+
+  double temp = 0.1;
+  result = 0;
+  while ( pos < len && ascii::is_digit( str[pos] ) ) {
+    result += temp * (str[pos] - '0');
+    temp /= 10;
+    ++pos;
+  }
+
+  return 0;
+}
+
+std::string zero_pad(int value, unsigned int min_digits)
+{
+  std::ostringstream oss;
+  oss << std::setfill('0') << std::setw( min_digits ) << value;
+  return oss.str();
+}
+
 } // namespace zorba
 /* vim:set et sw=2 ts=2: */

=== modified file 'src/zorbatypes/datetime/parse.h'
--- src/zorbatypes/datetime/parse.h	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/datetime/parse.h	2013-02-26 05:27:25 +0000
@@ -17,12 +17,14 @@
 #ifndef ZORBA_DATETIME_UTILS_H
 #define ZORBA_DATETIME_UTILS_H
 
+#include <cmath>
 #include <string>
+#include <sys/types.h>
+
 #include <zorba/config.h>
 
 #include "zorbatypes/numconversions.h"
 
-#include "util/ascii_util.h"
 #include "util/string_util.h"
 
 namespace zorba
@@ -36,7 +38,7 @@
   must obey these conditions, or the function will return an error.
 
   @param str The source string to parse
-  @param str_len the length of the input string
+  @param len the length of the input string
   @param position The position to start parsing from
   @param result Contains the result of the parsing
   @param min_digits Minimum number of digits
@@ -48,12 +50,12 @@
 ********************************************************************************/
 int parse_long(
     const char* str,
-    ascii::size_type str_len,
-    ascii::size_type& position,
+    size_t len,
+    size_t& position,
     long& result,
     long min_digits = -1,
     long max_digits = -1,
-    long delta = 0);
+    size_t delta = 0);
 
 
 /*******************************************************************************
@@ -64,43 +66,13 @@
   @param result
   @return Returns 0 on success and a positive value on an error
 ********************************************************************************/
-ZORBA_DLL_PUBLIC inline int parse_frac(
+int parse_frac(
     const char* str,
-    ascii::size_type strlen,
-    ascii::size_type& position,
-    double& result)
-{
-  if (position >= strlen) {
-    return 1;
-  }
-
-  if (str[position] < '0' || str[position] > '9') {
-    return 1;
-  }
-
-  double temp = 0.1;
-  result = 0;
-  while (position < strlen && str[position] >= '0' && str[position] <= '9') {
-    result += temp * (str[position] - '0');
-    temp /= 10;
-    position++;
-  }
-
-  return 0;
-}
-
-
-ZORBA_DLL_PUBLIC inline std::string to_string(int value, unsigned int min_digits = 0)
-{
-  std::string zeros;
-  std::string temp;
-  ztd::to_string(value, &temp);
-
-  for (unsigned int i=(unsigned int)temp.size(); i<min_digits; i++)
-    zeros += '0';
-
-  return zeros + temp;
-}
+    size_t len,
+    size_t& position,
+    double& result);
+
+std::string zero_pad(int value, unsigned int min_digits = 0);
 
 
 /**
@@ -108,84 +80,48 @@
  * @param year
  * @return
  */
-ZORBA_DLL_PUBLIC int leap_years_count(int year);
-
-
-template <typename T>
+int leap_years_count(int year);
+
+
+template <typename T> inline
 T quotient(T a, T b)
 {
-  if (a >= 0)
-    return a / b;
-  else
-    return (a+1) / b - 1;
+  return a >= 0 ? a / b : (a + 1) / b - 1;
 }
 
 
-template <typename T>
+template <typename T> inline
 T modulo(T a, T b)
 {
-  a = a % b;
+  a %= b;
   if (a<0)
     a += b;
-
   return a;
 }
 
 
-template <typename T>
-int floor(T a)
-{
-  if (a>=0)
-    return (int)a;
-  else if (a - ((int)a) == 0)
-    return (int)a;
-  else
-    return (int)(a-1);
-}
-
-
-template <typename T>
-T abs(T value)
-{
-  if (value < 0)
-    return -value;
-  else
-    return value;
-}
-
-
 /**
  * Rounds to the nearest integer
  */
-ZORBA_DLL_PUBLIC inline int round(double value)
-{
-  if (value >= 0)
-    return int(value+0.5);
-  else
-    return int(value-0.5);
-}
-
-
-ZORBA_DLL_PUBLIC inline double frac(double value)
-{
-  return value - floor<double>(value);
-}
-
-
-ZORBA_DLL_PUBLIC bool is_digit(char ch);
-
-
-ZORBA_DLL_PUBLIC bool are_digits(std::string& s, unsigned int& position, int count);
+inline int round(double value)
+{
+  return int( value >= 0 ? value + 0.5 : value - 0.5 );
+}
+
+
+inline double frac(double value)
+{
+  return value - std::floor(value);
+}
 
 
 // Returns the last day of the given year and month. E.g. for 1980 and 2 it
 // will return 29. Returns 0 on an error
-ZORBA_DLL_PUBLIC int get_last_day(int year, int month);
+int get_last_day(int year, int month);
 
 } // namespace zorba
 
-#endif
-
+#endif /* ZORBA_DATETIME_UTILS_H */
 /*
  * Local variables:
  * mode: c++

=== modified file 'src/zorbatypes/datetime/timezone.cpp'
--- src/zorbatypes/datetime/timezone.cpp	2012-09-19 21:16:15 +0000
+++ src/zorbatypes/datetime/timezone.cpp	2013-02-26 05:27:25 +0000
@@ -15,6 +15,7 @@
  */
 #include "stdafx.h"
 
+#include <cstdlib>
 #include <string>
 #include <exception>
 
@@ -38,7 +39,7 @@
   if (hours < 0)
     is_negative = true;
 
-  data[HOUR_DATA] = abs<long>(hours);
+  data[HOUR_DATA] = std::abs(hours);
 }
 
 
@@ -105,8 +106,8 @@
 int TimeZone::createTimeZone(int hours, int minutes, int seconds, TimeZone& tz)
 {
   tz = TimeZone(hours);
-  tz.data[MINUTE_DATA] = abs<long>(minutes);
-  tz.data[SECONDS_DATA] = abs<long>(seconds);
+  tz.data[MINUTE_DATA] = std::abs(minutes);
+  tz.data[SECONDS_DATA] = std::abs(seconds);
   tz.normalize(); 
   return 0;
 }
@@ -134,14 +135,10 @@
   if (data[HOUR_DATA] == 0 && data[MINUTE_DATA] == 0)
     return "Z";
 
-  if (isNegative())
-    result.append("-", 1);
-  else
-    result.append("+", 1);
-
-  result.append(to_string(data[HOUR_DATA], 2));
-  result.append(":", 1);
-  result.append(to_string(data[MINUTE_DATA], 2));
+  result += isNegative() ? '-' : '+';
+  result += zero_pad(data[HOUR_DATA], 2);
+  result += ':';
+  result += zero_pad(data[MINUTE_DATA], 2);
     
   return result;
 }


Follow ups