Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
899d0063
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
899d0063
编写于
4月 11, 2020
作者:
A
akinomaeni
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Show subsec of Time.zone.now [ci skip]
上级
1e799f23
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
31 deletion
+31
-31
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+31
-31
未找到文件。
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
899d0063
...
...
@@ -18,7 +18,7 @@ module ActiveSupport
# Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
# Time.zone.parse('2007-02-10 15:30:45') # => Sat, 10 Feb 2007 15:30:45 EST -05:00
# Time.zone.at(1171139445) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
# Time.zone.now # => Sun, 18 May 2008 13:07:55 EDT -04:00
# Time.zone.now # => Sun, 18 May 2008 13:07:55
.754107581
EDT -04:00
# Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45 EST -05:00
#
# See Time and TimeZone for further documentation of these methods.
...
...
@@ -26,13 +26,13 @@ module ActiveSupport
# TimeWithZone instances implement the same API as Ruby Time instances, so
# that Time and TimeWithZone instances are interchangeable.
#
# t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00
# t = Time.zone.now # => Sun, 18 May 2008 13:27:25
.031505668
EDT -04:00
# t.hour # => 13
# t.dst? # => true
# t.utc_offset # => -14400
# t.zone # => "EDT"
# t.to_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
# t + 1.day # => Mon, 19 May 2008 13:27:25 EDT -04:00
# t + 1.day # => Mon, 19 May 2008 13:27:25
.031505668
EDT -04:00
# t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00 EST -05:00
# t > Time.utc(1999) # => true
# t.is_a?(Time) # => true
...
...
@@ -137,7 +137,7 @@ def zone
# Returns a string of the object's date, time, zone, and offset from UTC.
#
# Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25 EST -05:00"
# Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25
.624541392
EST -05:00"
def
inspect
"
#{
time
.
strftime
(
'%a, %d %b %Y %H:%M:%S'
)
}#{
formatted_subsec_with_delimiter
}
#{
zone
}
#{
formatted_offset
}
"
end
...
...
@@ -277,8 +277,8 @@ def hash
# value as a new TimeWithZone object.
#
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
# now + 1000 # => Sun, 02 Nov 2014 01:43:08 EDT -04:00
# now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28
.725182881
EDT -04:00
# now + 1000 # => Sun, 02 Nov 2014 01:43:08
.725182881
EDT -04:00
#
# If we're adding a Duration of variable length (i.e., years, months, days),
# move forward from #time, otherwise move forward from #utc, for accuracy
...
...
@@ -287,8 +287,8 @@ def hash
# For instance, a time + 24.hours will advance exactly 24 hours, while a
# time + 1.day will advance 23-25 hours, depending on the day.
#
# now + 24.hours # => Mon, 03 Nov 2014 00:26:28 EST -05:00
# now + 1.day # => Mon, 03 Nov 2014 01:26:28 EST -05:00
# now + 24.hours # => Mon, 03 Nov 2014 00:26:28
.725182881
EST -05:00
# now + 1.day # => Mon, 03 Nov 2014 01:26:28
.725182881
EST -05:00
def
+
(
other
)
if
duration_of_variable_length?
(
other
)
method_missing
(:
+
,
other
)
...
...
@@ -306,8 +306,8 @@ def +(other)
# object's time and the +other+ time.
#
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28 EST -05:00
# now - 1000 # => Mon, 03 Nov 2014 00:09:48 EST -05:00
# now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28
.725182881
EST -05:00
# now - 1000 # => Mon, 03 Nov 2014 00:09:48
.725182881
EST -05:00
#
# If subtracting a Duration of variable length (i.e., years, months, days),
# move backward from #time, otherwise move backward from #utc, for accuracy
...
...
@@ -316,8 +316,8 @@ def +(other)
# For instance, a time - 24.hours will go subtract exactly 24 hours, while a
# time - 1.day will subtract 23-25 hours, depending on the day.
#
# now - 24.hours # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
# now - 1.day # => Sun, 02 Nov 2014 00:26:28 EDT -04:00
# now - 24.hours # => Sun, 02 Nov 2014 01:26:28
.725182881
EDT -04:00
# now - 1.day # => Sun, 02 Nov 2014 00:26:28
.725182881
EDT -04:00
#
# If both the TimeWithZone object and the other value act like Time, a Float
# will be returned.
...
...
@@ -339,8 +339,8 @@ def -(other)
# the result as a new TimeWithZone object.
#
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28 EST -05:00
# now.ago(1000) # => Mon, 03 Nov 2014 00:09:48 EST -05:00
# now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28
.725182881
EST -05:00
# now.ago(1000) # => Mon, 03 Nov 2014 00:09:48
.725182881
EST -05:00
#
# If we're subtracting a Duration of variable length (i.e., years, months,
# days), move backward from #time, otherwise move backward from #utc, for
...
...
@@ -350,8 +350,8 @@ def -(other)
# while <tt>time.ago(1.day)</tt> will move back 23-25 hours, depending on
# the day.
#
# now.ago(24.hours) # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
# now.ago(1.day) # => Sun, 02 Nov 2014 00:26:28 EDT -04:00
# now.ago(24.hours) # => Sun, 02 Nov 2014 01:26:28
.725182881
EDT -04:00
# now.ago(1.day) # => Sun, 02 Nov 2014 00:26:28
.725182881
EDT -04:00
def
ago
(
other
)
since
(
-
other
)
end
...
...
@@ -367,12 +367,12 @@ def ago(other)
# or <tt>:nsec</tt>, not both. Similarly, pass either <tt>:zone</tt> or
# <tt>:offset</tt>, not both.
#
# t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15 EST -05:00
# t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15 EST -05:00
# t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00 EST -05:00
# t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00 EST -05:00
# t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15 HST -10:00
# t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15 HST -10:00
# t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15
.116992711
EST -05:00
# t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15
.116992711
EST -05:00
# t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00
.116992711
EST -05:00
# t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00
.116992711
EST -05:00
# t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15
.116992711
HST -10:00
# t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15
.116992711
HST -10:00
def
change
(
options
)
if
options
[
:zone
]
&&
options
[
:offset
]
raise
ArgumentError
,
"Can't change both :offset and :zone at the same time:
#{
options
.
inspect
}
"
...
...
@@ -405,14 +405,14 @@ def change(options)
# accuracy when moving across DST boundaries.
#
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
# now.advance(seconds: 1) # => Sun, 02 Nov 2014 01:26:29 EDT -04:00
# now.advance(minutes: 1) # => Sun, 02 Nov 2014 01:27:28 EDT -04:00
# now.advance(hours: 1) # => Sun, 02 Nov 2014 01:26:28 EST -05:00
# now.advance(days: 1) # => Mon, 03 Nov 2014 01:26:28 EST -05:00
# now.advance(weeks: 1) # => Sun, 09 Nov 2014 01:26:28 EST -05:00
# now.advance(months: 1) # => Tue, 02 Dec 2014 01:26:28 EST -05:00
# now.advance(years: 1) # => Mon, 02 Nov 2015 01:26:28 EST -05:00
# now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28
.558049687
EDT -04:00
# now.advance(seconds: 1) # => Sun, 02 Nov 2014 01:26:29
.558049687
EDT -04:00
# now.advance(minutes: 1) # => Sun, 02 Nov 2014 01:27:28
.558049687
EDT -04:00
# now.advance(hours: 1) # => Sun, 02 Nov 2014 01:26:28
.558049687
EST -05:00
# now.advance(days: 1) # => Mon, 03 Nov 2014 01:26:28
.558049687
EST -05:00
# now.advance(weeks: 1) # => Sun, 09 Nov 2014 01:26:28
.558049687
EST -05:00
# now.advance(months: 1) # => Tue, 02 Dec 2014 01:26:28
.558049687
EST -05:00
# now.advance(years: 1) # => Mon, 02 Nov 2015 01:26:28
.558049687
EST -05:00
def
advance
(
options
)
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
# otherwise advance from #utc, for accuracy when moving across DST boundaries
...
...
@@ -434,7 +434,7 @@ def #{method_name} # def month
# Returns Array of parts of Time in sequence of
# [seconds, minutes, hours, day, month, year, weekday, yearday, dst?, zone].
#
# now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27 UTC +00:00
# now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27
.485278555
UTC +00:00
# now.to_a # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"]
def
to_a
[
time
.
sec
,
time
.
min
,
time
.
hour
,
time
.
day
,
time
.
mon
,
time
.
year
,
time
.
wday
,
time
.
yday
,
dst?
,
zone
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录