Project

General

Profile

Bug #10588 ยป SmartTime.rb

NorthernLights (Imran ""), 01/07/2015 04:28 PM

 
1
# 2015/01/07
2
# Ruby Bug patch: Invalid Dates *** By: Imran
3
# For feedback and comments: twitter/otherimran
4

    
5
class SmartTime < Time
6
  def self.mktime year, month, day
7
    case month
8
    when 4, 6, 9, 11
9
      if day == 31
10
        raise ArgumentError, 'argument out of range _ APR, JUNE, SEP, NOV', caller
11
      else
12
        super
13
      end
14
    when 2
15
        case day
16
        when 30, 31
17
          raise ArgumentError, 'argument out of range _ FEB', caller
18
        when 29
19
          if year%100 == 0
20
            if year%400 == 0
21
              super
22
            else
23
              raise ArgumentError, 'argument out of range _ FEB', caller
24
            end
25
          else
26
            if year%4 == 0
27
              super
28
            else
29
              raise ArgumentError, 'argument out of range _ FEB', caller
30
            end
31
          end
32
        else
33
          super
34
        end
35
    else
36
      super
37
    end
38
  end
39
end