mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Fix mday overflow
[ruby-core:90897] [Bug #15506] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									6e1d498ac7
								
							
						
					
					
						commit
						6629588aa5
					
				
					 2 changed files with 14 additions and 1 deletions
				
			
		
							
								
								
									
										11
									
								
								lib/time.rb
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								lib/time.rb
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -201,6 +201,9 @@ class Time
 | 
			
		|||
      end
 | 
			
		||||
 | 
			
		||||
      if yday
 | 
			
		||||
        unless (1..366) === yday
 | 
			
		||||
          raise ArgumentError, "yday #{yday} out of range"
 | 
			
		||||
        end
 | 
			
		||||
        mon, day = (yday-1).divmod(31)
 | 
			
		||||
        mon += 1
 | 
			
		||||
        day += 1
 | 
			
		||||
| 
						 | 
				
			
			@ -208,6 +211,12 @@ class Time
 | 
			
		|||
        diff = yday - t.yday
 | 
			
		||||
        return t if diff.zero?
 | 
			
		||||
        day += diff
 | 
			
		||||
        if day > 28 and day > (mday = month_days(off_year, mon))
 | 
			
		||||
          if (mon += 1) > 12
 | 
			
		||||
            raise ArgumentError, "yday #{yday} out of range"
 | 
			
		||||
          end
 | 
			
		||||
          day -= mday
 | 
			
		||||
        end
 | 
			
		||||
        return make_time(date, year, nil, mon, day, hour, min, sec, sec_fraction, zone, now)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -433,7 +442,7 @@ class Time
 | 
			
		|||
    #
 | 
			
		||||
    def strptime(date, format, now=self.now)
 | 
			
		||||
      d = Date._strptime(date, format)
 | 
			
		||||
      raise ArgumentError, "invalid strptime format - `#{format}'" unless d
 | 
			
		||||
      raise ArgumentError, "invalid date or strptime format - `#{date}' `#{format}'" unless d
 | 
			
		||||
      if seconds = d[:seconds]
 | 
			
		||||
        if sec_fraction = d[:sec_fraction]
 | 
			
		||||
          usec = sec_fraction * 1000000
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -503,6 +503,10 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
 | 
			
		|||
    assert_equal(0, t.hour)
 | 
			
		||||
    assert_equal(0, t.min)
 | 
			
		||||
    assert_equal(0, t.sec)
 | 
			
		||||
    t = Time.strptime("2018-091", "%Y-%j")
 | 
			
		||||
    assert_equal(2018, t.year)
 | 
			
		||||
    assert_equal(4, t.mon)
 | 
			
		||||
    assert_equal(1, t.day)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_nsec
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue