Guest User

Untitled

a guest
Jul 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. require 'date'
  2.  
  3. module ActiveMerchant
  4. module Billing
  5. class CreditCard
  6. class ExpiryDate #:nodoc:
  7. attr_reader :month, :year
  8. def initialize(month, year)
  9. @month = month.to_i
  10. @year = year.to_i
  11. end
  12.  
  13. def expired? #:nodoc:
  14. Time.now.utc > expiration
  15. end
  16.  
  17. def expiration #:nodoc:
  18. begin
  19. Time.utc(year, month, month_days, 23, 59, 59)
  20. rescue ArgumentError
  21. Time.at(0).utc
  22. end
  23. end
  24.  
  25. private
  26. def month_days
  27. mdays = [nil,31,28,31,30,31,30,31,31,30,31,30,31]
  28. mdays[2] = 29 if Date.leap?(year)
  29. mdays[month]
  30. end
  31. end
  32. end
  33. end
  34. end
Add Comment
Please, Sign In to add comment