forked from feedjira/feedjira
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gorillib was being required for a single method that was pretty easily reimplemented internally. Also expanded the meta programming for loading core extensions.
- Loading branch information
Showing
4 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
95e2f87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaffneyc Feel free to open a pull request. :)
95e2f87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezkl Done and done! Finally got a chance to test the change against our app that uses feedzirra