Module: Adyen::Formatter::DateTime

Defined in:
lib/adyen/formatter.rb

Class Method Summary collapse

Class Method Details

.fmt_date(date) ⇒ Object

Returns a valid Adyen string representation for a date



5
6
7
8
9
10
11
12
13
# File 'lib/adyen/formatter.rb', line 5

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

.fmt_time(time) ⇒ Object

Returns a valid Adyen string representation for a timestamp



16
17
18
19
20
21
22
23
24
# File 'lib/adyen/formatter.rb', line 16

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