diff options
Diffstat (limited to 'libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx')
-rw-r--r-- | libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx b/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx new file mode 100644 index 0000000..8f374cf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx @@ -0,0 +1,65 @@ +// file : xsde/cxx/serializer/non-validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + namespace bits + { + int + serialize_time_zone (char* s, const time_zone& z) + { + // time-zone := Z|(+|-)HH:MM + // + + short h = z.zone_hours (); + short m = z.zone_minutes (); + + if (h == 0 && m == 0) + { + *s = 'Z'; + return 1; + } + else + { + const char* fmt = "+%.2u:%.2u"; + + if (h < 0 || m < 0) + { + fmt = "-%.2u:%.2u"; + h = -h; + m = -m; + } + + if (h >= 0 && h <= 14 && m >= 0 && m <= 59) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (s, 7, fmt, h, m); +#else + int n = sprintf (s, fmt, h, m); +#endif + if (n > 0 && n < 7) + return n; + } + + return 0; + } + } + } + } + } + } +} |