Permalink
Browse files

fixed time zone issue with date format

  • Loading branch information...
1 parent 802fa99 commit 1693f07ccd43422c19bbf10e32a209145fb7ba8a Peter Ohler committed Jul 13, 2012
Showing with 60 additions and 26 deletions.
  1. +4 −2 README.md
  2. +17 −17 build_test.sh
  3. +35 −6 ext/oj/dump.c
  4. +2 −0 ext/oj/oj.c
  5. +1 −0 ext/oj/oj.h
  6. +1 −1 lib/oj/version.rb
View
6 README.md
@@ -32,9 +32,11 @@ A fast JSON parser and Object marshaller as a Ruby gem.
## <a name="release">Release Notes</a>
-### Release 1.3.0
+### Release 1.3.1
- - Added an option to control the time format output when in :compat mode.
+ - Fixed time zone issue with :xmlschema date format.
+
+ - extconf.rb fixed to not pause on some OSs when checking CentOS special case.
## <a name="description">Description</a>
View
34 build_test.sh
@@ -1,22 +1,5 @@
#!/bin/sh
-
-PATH=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin:$PATH
-echo "\n********************************************************************************"
-echo "Building OS X Ruby\n"
-cd ext/oj
-ruby extconf.rb
-make
-
-echo "\nRunning tests for OS X Ruby"
-cd ../../test
-./tests.rb
-./test_mimic.rb
-./test_fast.rb
-cd ..
-
-echo "\n"
-
for ruby in \
1.8.7-p358\
1.9.2-p290\
@@ -43,3 +26,20 @@ do
echo "\n"
done
+
+PATH=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin:$PATH
+echo "\n********************************************************************************"
+echo "Building OS X Ruby\n"
+cd ext/oj
+ruby extconf.rb
+make
+
+echo "\nRunning tests for OS X Ruby"
+cd ../../test
+./tests.rb
+./test_mimic.rb
+./test_fast.rb
+cd ..
+
+echo "\n"
+
View
41 ext/oj/dump.c
@@ -970,14 +970,27 @@ dump_xml_time(VALUE obj, Out out) {
long nsec = NUM2LONG(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
#endif
#endif
+ long tz_secs = NUM2LONG(rb_funcall2(obj, oj_utc_offset_id, 0, 0));
int tzhour, tzmin;
char tzsign = '+';
if (out->end - out->cur <= 36) {
grow(out, 36);
}
// 2012-01-05T23:58:07.123456000+09:00
- tm = localtime(&sec);
+ //tm = localtime(&sec);
+ sec += tz_secs;
+ tm = gmtime(&sec);
+#if 1
+ if (0 > tz_secs) {
+ tzsign = '-';
+ tzhour = (int)(tz_secs / -3600);
+ tzmin = (int)(tz_secs / -60) - (tzhour * 60);
+ } else {
+ tzhour = (int)(tz_secs / 3600);
+ tzmin = (int)(tz_secs / 60) - (tzhour * 60);
+ }
+#else
if (0 > tm->tm_gmtoff) {
tzsign = '-';
tzhour = (int)(tm->tm_gmtoff / -3600);
@@ -986,11 +999,27 @@ dump_xml_time(VALUE obj, Out out) {
tzhour = (int)(tm->tm_gmtoff / 3600);
tzmin = (int)(tm->tm_gmtoff / 60) - (tzhour * 60);
}
- sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02d.%09ld%c%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec, nsec,
- tzsign, tzhour, tzmin);
- dump_cstr(buf, 35, 0, 0, out);
+#endif
+ if (0 == nsec) {
+ if (0 == tzhour && 0 == tzmin) {
+ sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02dZ",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ dump_cstr(buf, 20, 0, 0, out);
+ } else {
+ sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec,
+ tzsign, tzhour, tzmin);
+ dump_cstr(buf, 25, 0, 0, out);
+ }
+ } else {
+ sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02d.%09ld%c%02d:%02d",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec, nsec,
+ tzsign, tzhour, tzmin);
+ dump_cstr(buf, 35, 0, 0, out);
+ }
}
static void
View
2 ext/oj/oj.c
@@ -64,6 +64,7 @@ ID oj_to_time_id;
ID oj_tv_nsec_id;
ID oj_tv_sec_id;
ID oj_tv_usec_id;
+ID oj_utc_offset_id;
ID oj_write_id;
VALUE oj_bag_class;
@@ -872,6 +873,7 @@ void Init_oj() {
oj_tv_nsec_id = rb_intern("tv_nsec");
oj_tv_sec_id = rb_intern("tv_sec");
oj_tv_usec_id = rb_intern("tv_usec");
+ oj_utc_offset_id = rb_intern("utc_offset");
oj_write_id = rb_intern("write");
oj_bag_class = rb_const_get_at(Oj, rb_intern("Bag"));
View
1 ext/oj/oj.h
@@ -182,6 +182,7 @@ extern ID oj_to_time_id;
extern ID oj_tv_nsec_id;
extern ID oj_tv_sec_id;
extern ID oj_tv_usec_id;
+extern ID oj_utc_offset_id;
extern Cache oj_class_cache;
extern Cache oj_attr_cache;
View
2 lib/oj/version.rb
@@ -1,5 +1,5 @@
module Oj
# Current version of the module.
- VERSION = '1.3.0'
+ VERSION = '1.3.1'
end

0 comments on commit 1693f07

Please sign in to comment.