Project

General

Profile

Bug #11037 ยป time_parse.patch

nkmrya (Yasuhiro Nakamura), 09/06/2015 01:56 AM

View differences:

lib/time.rb
256 256
      off = nil
257 257
      off = zone_offset(zone, off_year) if zone
258 258

  
259
      if off
260
        now = now.getlocal(off) if now.utc_offset != off
261
      else
262
        now = now.getlocal
259
      if now.kind_of?(Time)
260
        if off
261
          now = now.getlocal(off) if now.utc_offset != off
262
        else
263
          now = now.getlocal
264
        end
263 265
      end
264 266

  
265 267
      usec = nil
test/test_time.rb
497 497
    define_method(test) {__send__(sub, :xmlschema)}
498 498
    define_method(test.sub(/xmlschema/, 'iso8601')) {__send__(sub, :iso8601)}
499 499
  end
500

  
501
  def test_parse_with_various_object
502
    d  = Date.new(2010, 10, 28)
503
    dt = DateTime.new(2010, 10, 28)
504
    md = MyDate.new(10, 28, 2010)
505

  
506
    t = Time.local(2010, 10, 28, 21, 26, 00)
507
    assert_equal(t, Time.parse("21:26",  d))
508
    assert_equal(t, Time.parse("21:26", dt))
509
    assert_equal(t, Time.parse("21:26", md))
510
  end
511

  
512
  class MyDate
513
    attr_reader :mon, :day, :year
514

  
515
    def initialize(mon, day, year)
516
      @mon, @day, @year = mon, day, year
517
    end
518
  end
500 519
end