lib/spark_api/models/subresource.rb in spark_api-1.1.2 vs lib/spark_api/models/subresource.rb in spark_api-1.2.0
- old
+ new
@@ -23,20 +23,22 @@
formatted_date = "#{attributes['Date']}T#{attributes[time]}"
datetime = nil
begin
datetime = DateTime.strptime(formatted_date, '%m/%d/%YT%l:%M %P')
+ dst_offset = 0
rescue => ex
; # Do nothing; doesn't matter
end
unless datetime
other_formats = ['%m/%d/%YT%H:%M%z', '%m/%d/%YT%H:%M:%S%z']
other_formats.each_with_index do |format, i|
begin
datetime = DateTime.strptime(formatted_date, format)
datetime = datetime.new_offset DateTime.now.offset
+ dst_offset = Time.now.dst? ? 0 : 1
break
rescue => ex
next
end
end
@@ -44,12 +46,14 @@
# if we still don't have a valid time, raise an error
unless datetime
raise ArgumentError.new('invalid date')
end
+
+
attributes[time] = Time.local(datetime.year, datetime.month, datetime.day,
- datetime.hour, datetime.min, datetime.sec)
+ datetime.hour + dst_offset, datetime.min, datetime.sec)
end
attributes['Date'] = date
end
end