Sha256: a0e40e8f681b558c8edfec1ad355a75b4b3d93dcf96f2f0a0600d1e5d626608a

Contents?: true

Size: 747 Bytes

Versions: 2

Compression:

Stored size: 747 Bytes

Contents

require 'date'

module AbtainBilling
  module Billing
    class CreditCard
      class ExpiryDate #:nodoc:
        attr_reader :month, :year
        def initialize(month, year)
          @month = month.to_i
          @year = year.to_i
        end
        
        def expired? #:nodoc:
          Time.now.utc > expiration
        end
        
        def expiration #:nodoc:
          begin
            Time.utc(year, month, month_days, 23, 59, 59)
          rescue ArgumentError
            Time.at(0).utc
          end
        end
        
        private
        def month_days
          mdays = [nil,31,28,31,30,31,30,31,31,30,31,30,31]
          mdays[2] = 29 if Date.leap?(year)
          mdays[month]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
abtain_billing-1.03 lib/abtain_billing/billing/expiry_date.rb
abtain_billing-1.02 lib/abtain_billing/billing/expiry_date.rb