Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simplify GoCardless::Utils.iso_format_time method #30

Closed
wants to merge 1 commit into from

1 participant

Tim Craft
Tim Craft

ISO 8601 formatting already exists so no need to re-implement that. Calling #to_time on the argument is easier than type checking, and also a bit more flexible in that it allows for custom time classes.

Cheers,
Tim

Tim Craft

Urgh, 1.8.7. Abort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 06, 2012
Tim Craft timcraft Simplify GoCardless::Utils.iso_format_time method 0b04d22
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 5 additions and 5 deletions. Show diff stats Hide diff stats

  1. +5 5 lib/gocardless/utils.rb
10 lib/gocardless/utils.rb
... ... @@ -1,4 +1,5 @@
1 1 require 'uri'
  2 +require 'time'
2 3
3 4 module GoCardless
4 5 module Utils
@@ -98,11 +99,10 @@ def sign_params(params, key)
98 99 #
99 100 # @param [Time] time the time object to format
100 101 # @return [String] the ISO-formatted time
101   - def iso_format_time(time)
102   - return time unless time.is_a? Time or time.is_a? Date
103   - time = time.getutc if time.is_a? Time
104   - time = time.new_offset(0) if time.is_a? DateTime
105   - time.strftime('%Y-%m-%dT%H:%M:%SZ')
  102 + def iso_format_time(object)
  103 + return object unless object.respond_to?(:to_time)
  104 +
  105 + object.to_time.getutc.iso8601
106 106 end
107 107
108 108 # Recursively ISO format all time and date values.

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.