Project

General

Profile

Bug #4005 ยป 0001-Make-syck-s-Time-timestamps-write-nsec-precision-fra.patch

syck nsec timestamps - pweldon (Peter Weldon), 11/10/2010 02:04 AM

View differences:

ChangeLog
Tue Nov 9 09:51:10 2010 Peter Weldon <peter.weldon@null.net>
* ext/syck/lib/syck/rubytypes.rb (Time#to_yaml): emit nsec
precision fractional seconds.
* ext/syck/rubyext.c (mktime_do): support parsing of arbitary
precision fractional seconds.
Sat Nov 6 07:33:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (rb_cv_export_prefix): check for prefixed
ext/syck/lib/syck/rubytypes.rb
tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60]
end
standard = self.strftime( "%Y-%m-%d %H:%M:%S" )
standard += ".%06d" % [usec] if usec.nonzero?
standard += ".%09d" % [nsec] if nsec.nonzero?
standard += " %s" % [tz]
if to_yaml_properties.empty?
out.scalar( taguri, standard, :plain )
ext/syck/rubyext.c
VALUE hour = INT2FIX(0);
VALUE min = INT2FIX(0);
VALUE sec = INT2FIX(0);
long usec;
VALUE usec = INT2FIX(0);
/* Year*/
if ( ptr[0] != '\0' && len > 0 ) {
......
/* Millisecond */
ptr += 2;
if ( len > ptr - str && *ptr == '.' )
{
char padded[] = "000000";
const char *end = ptr + 1;
const char *p = end;
while ( isdigit( *end ) ) end++;
if (end - p < (int)sizeof(padded)) {
MEMCPY(padded, ptr + 1, char, end - (ptr + 1));
p = padded;
}
usec = strtol(p, NULL, 10);
}
else
{
usec = 0;
if ( len > ptr - str && *ptr == '.' ) {
const char *p = ptr;
ptr++;
while ( isdigit( *ptr ) ) ptr++;
usec = rb_Rational1(rb_str_new(p, ptr - p));
usec = rb_funcall(usec, '*', 1, INT2FIX(1000000));
}
/* Time Zone*/
......
time = rb_funcall(rb_cTime, s_utc, 6, year, mon, day, hour, min, sec);
tmp = rb_funcall(time, s_to_i, 0);
tmp = rb_funcall(tmp, '-', 1, LONG2FIX(tz_offset));
return rb_funcall(rb_cTime, s_at, 2, tmp, LONG2NUM(usec));
return rb_funcall(rb_cTime, s_at, 2, tmp, usec);
}
else
{
/* Make UTC time*/
return rb_funcall(rb_cTime, s_utc, 7, year, mon, day, hour, min, sec, LONG2NUM(usec));
return rb_funcall(rb_cTime, s_utc, 7, year, mon, day, hour, min, sec, usec);
}
}
test/syck/test_yaml.rb
hour = zone[0,3].to_i * 3600
min = zone[3,2].to_i * 60
ofs = (hour + min)
val = Time.at( val.tv_sec - ofs, val.tv_nsec / 1000.0 )
val = val - ofs
end
return val
end
......
assert_parse_only(
{ "space separated" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ),
"canonical" => mktime( 2001, 12, 15, 2, 59, 43, ".10" ),
"nsec" => mktime( 2001, 12, 15, 2, 59, 43, ".000000001" ),
"date (noon UTC)" => Date.new( 2002, 12, 14),
"valid iso8601" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ) }, <<EOY
canonical: 2001-12-15T02:59:43.1Z
nsec: 2001-12-15T02:59:43.000000001Z
valid iso8601: 2001-12-14t21:59:43.10-05:00
space separated: 2001-12-14 21:59:43.10 -05:00
date (noon UTC): 2002-12-14
    (1-1/1)