Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generate unix timestamps using #to_i directly

  • Loading branch information...
commit 4f6ca94668cabd0cd6afc0f51913fd5274157dc1 1 parent 247ca8a
@jgwhite jgwhite authored
View
2  Gemfile.lock
@@ -60,6 +60,7 @@ GEM
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
+ tzinfo (0.3.37)
PLATFORMS
ruby
@@ -72,3 +73,4 @@ DEPENDENCIES
rspec-mocks
sinatra (~> 1.3.1)
thin (~> 1.4.1)
+ tzinfo
View
1  intercom-rails.gemspec
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry'
s.add_development_dependency 'sinatra', '~> 1.3.1'
s.add_development_dependency 'thin', '~> 1.4.1'
+ s.add_development_dependency 'tzinfo'
end
View
2  lib/intercom-rails/script_tag.rb
@@ -112,7 +112,7 @@ def widget_options_from_config
def convert_dates_to_unix_timestamps(object)
return Hash[object.map { |k, v| [k, convert_dates_to_unix_timestamps(v)] }] if object.is_a?(Hash)
- return object.strftime('%s').to_i if object.respond_to?(:strftime)
+ return object.to_i if object.is_a?(Time) || object.is_a?(DateTime)
object
end
View
7 test/intercom-rails/script_tag_test.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/string/output_safety'
+require 'active_support/time'
require 'test_setup'
class ScriptTagTest < MiniTest::Unit::TestCase
@@ -23,6 +24,12 @@ def test_converts_times_to_unix_timestamps
now = Time.now
nested_time = ScriptTag.new(:user_details => {:custom_data => {"something" => now}})
assert_equal now.to_i, nested_time.intercom_settings[:custom_data]["something"]
+
+ utc_time = Time.utc(2013,04,03)
+ time_zone = ActiveSupport::TimeZone.new('London')
+ time_with_zone = ActiveSupport::TimeWithZone.new(utc_time, time_zone)
+ time_from_time_with_zone = ScriptTag.new(:user_details => {:created_at => time_with_zone})
+ assert_equal utc_time.to_i, time_from_time_with_zone.intercom_settings[:created_at]
end
def test_strips_out_nil_entries_for_standard_attributes
Please sign in to comment.
Something went wrong with that request. Please try again.