Permalink
Browse files

Merge pull request #113 from collectiveidea/remove-gorillib

Remove gorillib as a dependency.
  • Loading branch information...
2 parents 021a8d7 + 95e2f87 commit 318c3bd17f5a4fe5f6aa9e1fc6767ab69881dbe9 @ezkl ezkl committed Jun 5, 2012
Showing with 32 additions and 5 deletions.
  1. +0 −1 feedzirra.gemspec
  2. +0 −1 lib/feedzirra.rb
  3. +3 −3 lib/feedzirra/core_ext.rb
  4. +29 −0 lib/feedzirra/core_ext/time.rb
View
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
s.add_dependency 'sax-machine', '~> 0.2.0.rc1'
s.add_dependency 'curb', '~> 0.8.0'
s.add_dependency 'loofah', '~> 1.2.1'
- s.add_dependency 'gorillib', '~> 0.1.9'
s.add_development_dependency 'rspec', '~> 2.10.0'
end
View
@@ -3,7 +3,6 @@
require 'sax-machine'
require 'loofah'
require 'uri'
-require 'gorillib/datetime/parse'
require 'feedzirra/core_ext'
require 'feedzirra/version'
@@ -1,3 +1,3 @@
-Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.each do |path|
- require "feedzirra/core_ext/#{File.basename(path, '.rb')}"
-end
+require "feedzirra/core_ext/time"
+require "feedzirra/core_ext/date"
+require "feedzirra/core_ext/string"
@@ -0,0 +1,29 @@
+require "time"
+require "date"
+
+class Time
+ # Parse a time string and convert it to UTC without raising errors.
+ # Parses a flattened 14-digit time (YYYYmmddHHMMMSS) as UTC.
+ #
+ # === Parameters
+ # [dt<String or Time>] Time definition to be parsed.
+ #
+ # === Returns
+ # A Time instance in UTC or nil if there were errors while parsing.
+ def self.parse_safely(dt)
+ if dt
+ case
+ when dt.is_a?(Time)
+ dt.utc
+ when dt.respond_to?(:empty?) && dt.empty?
+ nil
+ when dt.to_s =~ /\A\d{14}\z/
+ parse("#{dt.to_s}Z", true)
+ else
+ parse(dt.to_s, true).utc
+ end
+ end
+ rescue StandardError
+ nil
+ end unless method_defined?(:parse_safely)
+end

0 comments on commit 318c3bd

Please sign in to comment.