Module: Adyen::Formatter::DateTime

Defined in:
lib/adyen/formatter.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) fmt_date(date)

Returns a valid Adyen string representation for a date



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/adyen/formatter.rb', line 7

def self.fmt_date(date)
  case date
  when Date, DateTime, Time
    date.strftime('%Y-%m-%d')
  when String
    raise ArgumentError, "Invalid date notation: #{date.inspect}!" unless /^\d{4}-\d{2}-\d{2}$/ =~ date
    date
  else
    raise ArgumentError, "Cannot convert #{date.inspect} to date!"
  end
end

+ (Object) fmt_time(time)

Returns a valid Adyen string representation for a timestamp



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/adyen/formatter.rb', line 20

def self.fmt_time(time)
  case time
  when Date, DateTime, Time
    time.strftime('%Y-%m-%dT%H:%M:%SZ')
  when String
    raise ArgumentError, "Invalid timestamp notation: #{time.inspect}!" unless /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z$/ =~ time
    time
  else
    raise ArgumentError, "Cannot convert #{time.inspect} to timestamp!"
  end
end