lib/et-orbi.rb in et-orbi-1.0.9 vs lib/et-orbi.rb in et-orbi-1.1.0
- old
+ new
@@ -5,11 +5,11 @@
require 'tzinfo'
module EtOrbi
- VERSION = '1.0.9'
+ VERSION = '1.1.0'
#
# module methods
class << self
@@ -289,10 +289,20 @@
def make(o)
EtOrbi.make_time(o)
end
+
+ def utc(*a)
+
+ EtOrbi.make_from_array(a, EtOrbi.get_tzone('UTC'))
+ end
+
+ def local(*a)
+
+ EtOrbi.make_from_array(a, EtOrbi.local_tzone)
+ end
end
#
# instance methods
@@ -406,11 +416,10 @@
%w[
year month day wday hour min sec usec asctime
].each do |m|
define_method(m) { to_time.send(m) }
end
- def iso8601(fraction_digits=0); to_time.iso8601(fraction_digits); end
def ==(o)
o.is_a?(EoTime) &&
o.seconds == @seconds &&
@@ -460,10 +469,16 @@
def to_s
strftime('%Y-%m-%d %H:%M:%S %z')
end
+ def iso8601(fraction_digits=0)
+
+ s = (fraction_digits || 0) > 0 ? ".%#{fraction_digits}N" : ''
+ strftime("%Y-%m-%dT%H:%M:%S#{s}%:z")
+ end
+
# Debug current time by showing local time / delta / utc time
# for example: "0120-7(0820)"
#
def to_utc_comparison_s
@@ -501,10 +516,12 @@
def localtime(zone=nil)
EoTime.new(self.to_f, zone)
end
+ alias translate localtime
+
def wday_in_month
[ count_weeks(-1), - count_weeks(1) ]
end
@@ -545,10 +562,12 @@
sn = off < 0 ? '-' : '+'; off = off.abs
hr = off / 3600
mn = (off % 3600) / 60
sc = 0
- if code == '%z'
+ if @zone.name == 'UTC'
+ 'Z' # align on Ruby ::Time#iso8601
+ elsif code == '%z'
'%s%02d%02d' % [ sn, hr, mn ]
elsif code == '%:z'
'%s%02d:%02d' % [ sn, hr, mn ]
else
'%s%02d:%02d:%02d' % [ sn, hr, mn, sc ]