lib/teasy/floating_time.rb in teasy-0.1.2 vs lib/teasy/floating_time.rb in teasy-0.1.3
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'tzinfo'
require 'forwardable'
module Teasy
class FloatingTime
@@ -34,22 +36,22 @@
def inspect
strftime('%Y-%m-%d %H:%M:%S')
end
- alias_method :to_s, :inspect
+ alias to_s inspect
def strftime(format)
format = prefix_zone_info(format) if includes_zone_directive?(format)
time.strftime(format)
end
def asctime
strftime('%a %b %e %T %Y')
end
- alias_method :ctime, :asctime
+ alias ctime asctime
def <=>(other)
return nil unless other.respond_to?(:to_time) &&
other.respond_to?(:utc_offset)
to_time - other.utc_offset <=> other.to_time.utc
@@ -71,11 +73,11 @@
if other.is_a? Numeric
FloatingTime.from_time(time - other)
elsif other.respond_to? :to_time
to_time - other.to_time
else
- fail TypeError, "#{other.class} can't be coerced into FloatingTime"
+ raise TypeError, "#{other.class} can't be coerced into FloatingTime"
end
end
def to_a
time.to_a[0..7]
@@ -83,32 +85,32 @@
def to_time
time.dup
end
- alias_method :utc, :to_time
+ alias utc to_time
def utc_offset
0
end
private
- attr_reader :time
-
- def self.zone_directives_matcher
+ def zone_directives_matcher
@zone_directives_matcher ||= Regexp.union(
/(?<!%)%Z/, /(?<!%)%z/, /(?<!%)%:z/, /(?<!%)%::z/
)
end
+ attr_reader :time
+
def includes_zone_directive?(format)
- FloatingTime.zone_directives_matcher =~ format
+ zone_directives_matcher =~ format
end
def prefix_zone_info(format)
# prefixes zone directives with a % s.t. they are ignored in strftime
- format.gsub(FloatingTime.zone_directives_matcher) { |m| '%' + m }
+ format.gsub(zone_directives_matcher) { |m| '%' + m }
end
end
# rubocop:enable Metrics/ClassLength
end