Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.5.5
-
Fix Version/s: JRuby 1.6RC1
-
Component/s: Ruby 1.8.7
-
Labels:None
-
Testcase included:yes
Description
jirb in 1.8 mode
irb(main):003:0> require 'date' => true irb(main):004:0> x=DateTime.now() => #<DateTime: 21215812251739/8640000,11/48,2299161>
%3N the length for N is ignored
irb(main):005:0> x.strftime("%Y%m%d %H:%M:%S.%3N")
=> "20101203 13:18:37.390000000"
irb(main):006:0> x.strftime("%Y%m%d %H:%M:%S.%N")
=> "20101203 13:18:37.390000000"
irb(main):007:0> x=Time.now()
=> Fri Dec 03 13:20:22 +0530 2010
irb(main):008:0> x.strftime("%Y%m%d %H:%M:%S.%N")
=> "20101203 13:20:22.944915345"
%3N not recognised for time objcet but %N is recognised as above
irb(main):009:0> x.strftime("%Y%m%d %H:%M:%S.%3N")
=> "20101203 13:20:22.%3N"
The default db format string is not used and does not have the fraction part of the second string %N in it
the datetime object insertion looses the fraction part of the second
for insert stmt in mssql the following format needs the %3N to work and
def quote(value, column = nil)
return value.quoted_id if value.respond_to?(:quoted_id)
case value
when String, ActiveSupport::Multibyte::Chars
value = value.to_s
if column && column.type == :binary
"'#{quote_string(JdbcSpec::MsSQL::Column.string_to_binary(value))}'" # ' (for ruby-mode)
elsif column && [:integer, :float].include?(column.type)
value = column.type == :integer ? value.to_i : value.to_f
value.to_s
else
"'#{quote_string(value)}'" # ' (for ruby-mode)
end
when TrueClass then '1'
when FalseClass then '0'
when Time, DateTime then "'#{value.strftime("%Y%m%d %H:%M:%S.%3N")[0,21]}'"
when Date then "'#{value.strftime("%Y%m%d")}'"
else super
end
end
Issue Links
- relates to
-
JRUBY-3871
strftime doesn't support %h
-
I reformatted the description. I assume that the last "and" before the code snippet was unintentionally left behind.