* ext/syck/rubyext.c: usec round-tripping skew. [ruby-core:2305]
* lib/yaml/rubytypes.rb: character Range now round-trips. [ruby-core:2306] * test/yaml/test_yaml.rb: add Time and Range tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
46f6b20268
commit
877408163a
@ -1,3 +1,11 @@
|
|||||||
|
Thu Jan 29 01:56:02 2004 why the lucky stiff <why@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/syck/rubyext.c: usec round-tripping skew. [ruby-core:2305]
|
||||||
|
|
||||||
|
* lib/yaml/rubytypes.rb: character Range now round-trips. [ruby-core:2306]
|
||||||
|
|
||||||
|
* test/yaml/test_yaml.rb: add Time and Range tests.
|
||||||
|
|
||||||
Thu Jan 29 00:00:46 2004 Kouhei Sutou <kou@cozmixng.org>
|
Thu Jan 29 00:00:46 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss: rss/parser.rb is always required.
|
* lib/rss: rss/parser.rb is always required.
|
||||||
|
@ -198,7 +198,8 @@ rb_syck_mktime(str)
|
|||||||
{
|
{
|
||||||
VALUE time;
|
VALUE time;
|
||||||
char *ptr = str;
|
char *ptr = str;
|
||||||
VALUE year, mon, day, hour, min, sec, usec;
|
VALUE year, mon, day, hour, min, sec;
|
||||||
|
long usec;
|
||||||
|
|
||||||
/* Year*/
|
/* Year*/
|
||||||
ptr[4] = '\0';
|
ptr[4] = '\0';
|
||||||
@ -233,23 +234,23 @@ rb_syck_mktime(str)
|
|||||||
ptr += 2;
|
ptr += 2;
|
||||||
if ( *ptr == '.' )
|
if ( *ptr == '.' )
|
||||||
{
|
{
|
||||||
usec = INT2FIX( strtod( ptr, NULL ) * 1000000 );
|
char *padded = syck_strndup( "000000", 6 );
|
||||||
|
char *end = ptr + 1;
|
||||||
|
while ( isdigit( *end ) ) end++;
|
||||||
|
MEMCPY(padded, ptr + 1, char, end - (ptr + 1));
|
||||||
|
usec = strtol(padded, NULL, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
usec = INT2FIX( 0 );
|
usec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make UTC time*/
|
|
||||||
time = rb_funcall(rb_cTime, s_utc, 7, year, mon, day, hour, min, sec, usec);
|
|
||||||
|
|
||||||
/* Time Zone*/
|
/* Time Zone*/
|
||||||
while ( *ptr != 'Z' && *ptr != '+' && *ptr != '-' && *ptr != '\0' ) ptr++;
|
while ( *ptr != 'Z' && *ptr != '+' && *ptr != '-' && *ptr != '\0' ) ptr++;
|
||||||
if ( *ptr == '-' || *ptr == '+' )
|
if ( *ptr == '-' || *ptr == '+' )
|
||||||
{
|
{
|
||||||
double tz_offset = 0;
|
time_t tz_offset = strtol(ptr, NULL, 10) * 3600;
|
||||||
double utc_time = 0;
|
time_t tmp;
|
||||||
tz_offset += strtod(ptr, NULL) * 3600;
|
|
||||||
|
|
||||||
while ( *ptr != ':' && *ptr != '\0' ) ptr++;
|
while ( *ptr != ':' && *ptr != '\0' ) ptr++;
|
||||||
if ( *ptr == ':' )
|
if ( *ptr == ':' )
|
||||||
@ -257,21 +258,25 @@ rb_syck_mktime(str)
|
|||||||
ptr += 1;
|
ptr += 1;
|
||||||
if ( tz_offset < 0 )
|
if ( tz_offset < 0 )
|
||||||
{
|
{
|
||||||
tz_offset -= strtod(ptr, NULL) * 60;
|
tz_offset -= strtol(ptr, NULL, 10) * 60;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tz_offset += strtod(ptr, NULL) * 60;
|
tz_offset += strtol(ptr, NULL, 10) * 60;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make TZ time*/
|
/* Make TZ time*/
|
||||||
utc_time = NUM2DBL(rb_funcall(time, s_to_f, 0));
|
time = rb_funcall(rb_cTime, s_utc, 6, year, mon, day, hour, min, sec);
|
||||||
utc_time -= tz_offset;
|
tmp = NUM2LONG(rb_funcall(time, s_to_i, 0)) - tz_offset;
|
||||||
time = rb_funcall(rb_cTime, s_at, 1, rb_float_new(utc_time));
|
return rb_funcall(rb_cTime, s_at, 2, LONG2NUM(tmp), LONG2NUM(usec));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Make UTC time*/
|
||||||
|
return rb_funcall(rb_cTime, s_utc, 7, year, mon, day, hour, min, sec, LONG2NUM(usec));
|
||||||
|
|
||||||
return time;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -353,7 +353,7 @@ class Range
|
|||||||
def to_yaml( opts = {} )
|
def to_yaml( opts = {} )
|
||||||
YAML::quick_emit( nil, opts ) { |out|
|
YAML::quick_emit( nil, opts ) { |out|
|
||||||
out << "!ruby/range "
|
out << "!ruby/range "
|
||||||
self.inspect.to_yaml( :Emitter => out )
|
self.to_s.to_yaml( :Emitter => out )
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1051,6 +1051,28 @@ EOY
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Test of Ranges
|
||||||
|
#
|
||||||
|
def test_ranges
|
||||||
|
|
||||||
|
# Simple numeric
|
||||||
|
assert_to_yaml( 1..3, <<EOY )
|
||||||
|
--- !ruby/range 1..3
|
||||||
|
EOY
|
||||||
|
|
||||||
|
# Simple alphabetic
|
||||||
|
assert_to_yaml( 'a'..'z', <<EOY )
|
||||||
|
--- !ruby/range a..z
|
||||||
|
EOY
|
||||||
|
|
||||||
|
# Float
|
||||||
|
assert_to_yaml( 10.5...30.3, <<EOY )
|
||||||
|
--- !ruby/range 10.5...30.3
|
||||||
|
EOY
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def test_ruby_struct
|
def test_ruby_struct
|
||||||
# Ruby structures
|
# Ruby structures
|
||||||
book_struct = Struct::new( "BookStruct", :author, :title, :year, :isbn )
|
book_struct = Struct::new( "BookStruct", :author, :title, :year, :isbn )
|
||||||
@ -1159,6 +1181,20 @@ EOY
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Test Time.now cycle
|
||||||
|
#
|
||||||
|
def test_time_now_cycle
|
||||||
|
#
|
||||||
|
# From Minero Aoki [ruby-core:2305]
|
||||||
|
#
|
||||||
|
require 'yaml'
|
||||||
|
t = Time.now
|
||||||
|
5.times do
|
||||||
|
assert_equals( t, YAML.load( YAML.dump( t ) ) )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Circular references
|
# Circular references
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user