Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
41e7c68d
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,发现更多精彩内容 >>
提交
41e7c68d
编写于
3月 28, 2010
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ruby 1.9.2: marshaling round-trips Time#zone
上级
40d90ed7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
15 deletion
+67
-15
activesupport/lib/active_support/core_ext/time/marshal.rb
activesupport/lib/active_support/core_ext/time/marshal.rb
+56
-0
activesupport/lib/active_support/time.rb
activesupport/lib/active_support/time.rb
+1
-1
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+8
-12
activesupport/test/message_encryptor_test.rb
activesupport/test/message_encryptor_test.rb
+1
-1
activesupport/test/message_verifier_test.rb
activesupport/test/message_verifier_test.rb
+1
-1
未找到文件。
activesupport/lib/active_support/core_ext/time/marshal
_with_utc_flag
.rb
→
activesupport/lib/active_support/core_ext/time/marshal.rb
浏览文件 @
41e7c68d
# Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
# unmarshalled in the local zone, instead of utc. We're layering behavior on the _dump and _load
# methods so that utc instances can be flagged on dump, and coerced back to utc on load.
if
RUBY_VERSION
<
'1.9'
if
!
Marshal
.
load
(
Marshal
.
dump
(
Time
.
now
.
utc
)).
utc?
class
Time
class
<<
self
alias_method
:_
original_load
,
:_load
alias_method
:_
load_without_utc_flag
,
:_load
def
_load
(
marshaled_time
)
time
=
_
original_load
(
marshaled_time
)
time
=
_
load_without_utc_flag
(
marshaled_time
)
time
.
instance_eval
do
if
defined?
(
@marshal_with_utc_coercion
)
val
=
remove_instance_variable
(
"@marshal_with_utc_coercion"
)
...
...
@@ -16,11 +16,41 @@ def _load(marshaled_time)
end
end
alias_method
:_
original_dump
,
:_dump
alias_method
:_
dump_without_utc_flag
,
:_dump
def
_dump
(
*
args
)
obj
=
dup
obj
.
instance_variable_set
(
'@marshal_with_utc_coercion'
,
utc?
)
obj
.
_original_dump
(
*
args
)
obj
.
_dump_without_utc_flag
(
*
args
)
end
end
end
# Ruby 1.9.2 adds utc_offset and zone to Time, but marshaling only
# preserves utc_offset. Preserve zone also, even though it may not
# work in some edge cases.
if
Time
.
local
(
2010
).
zone
!=
Marshal
.
load
(
Marshal
.
dump
(
Time
.
local
(
2010
))).
zone
class
Time
class
<<
self
alias_method
:_load_without_zone
,
:_load
def
_load
(
marshaled_time
)
time
=
_load_without_zone
(
marshaled_time
)
time
.
instance_eval
do
if
zone
=
defined?
(
@_zone
)
&&
remove_instance_variable
(
'@_zone'
)
ary
=
to_a
ary
[
-
1
]
=
zone
utc?
?
Time
.
utc
(
*
ary
)
:
Time
.
local
(
*
ary
)
else
self
end
end
end
end
alias_method
:_dump_without_zone
,
:_dump
def
_dump
(
*
args
)
obj
=
dup
obj
.
instance_variable_set
(
'@_zone'
,
zone
)
obj
.
_dump_without_zone
(
*
args
)
end
end
end
activesupport/lib/active_support/time.rb
浏览文件 @
41e7c68d
...
...
@@ -14,7 +14,7 @@ module ActiveSupport
require
'time'
require
'active_support/core_ext/time/publicize_conversion_methods'
require
'active_support/core_ext/time/marshal
_with_utc_flag
'
require
'active_support/core_ext/time/marshal'
require
'active_support/core_ext/time/acts_like'
require
'active_support/core_ext/time/calculations'
require
'active_support/core_ext/time/conversions'
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
41e7c68d
...
...
@@ -758,33 +758,29 @@ def time_is_64bits?
class
TimeExtMarshalingTest
<
Test
::
Unit
::
TestCase
def
test_marshaling_with_utc_instance
t
=
Time
.
utc
(
2000
)
marshaled
=
Marshal
.
dump
t
unmarshaled
=
Marshal
.
load
marshaled
assert_equal
t
,
unmarshaled
unmarshaled
=
Marshal
.
load
(
Marshal
.
dump
(
t
))
assert_equal
"UTC"
,
unmarshaled
.
zone
assert_equal
t
,
unmarshaled
end
def
test_marshaling_with_local_instance
t
=
Time
.
local
(
2000
)
marshaled
=
Marshal
.
dump
t
unmarshaled
=
Marshal
.
load
marshaled
assert_equal
t
,
unmarshaled
unmarshaled
=
Marshal
.
load
(
Marshal
.
dump
(
t
))
assert_equal
t
.
zone
,
unmarshaled
.
zone
assert_equal
t
,
unmarshaled
end
def
test_marshaling_with_frozen_utc_instance
t
=
Time
.
utc
(
2000
).
freeze
marshaled
=
Marshal
.
dump
t
unmarshaled
=
Marshal
.
load
marshaled
assert_equal
t
,
unmarshaled
unmarshaled
=
Marshal
.
load
(
Marshal
.
dump
(
t
))
assert_equal
"UTC"
,
unmarshaled
.
zone
assert_equal
t
,
unmarshaled
end
def
test_marshaling_with_frozen_local_instance
t
=
Time
.
local
(
2000
).
freeze
marshaled
=
Marshal
.
dump
t
unmarshaled
=
Marshal
.
load
marshaled
assert_equal
t
,
unmarshaled
unmarshaled
=
Marshal
.
load
(
Marshal
.
dump
(
t
))
assert_equal
t
.
zone
,
unmarshaled
.
zone
assert_equal
t
,
unmarshaled
end
end
activesupport/test/message_encryptor_test.rb
浏览文件 @
41e7c68d
...
...
@@ -4,7 +4,7 @@
class
MessageEncryptorTest
<
Test
::
Unit
::
TestCase
def
setup
@encryptor
=
ActiveSupport
::
MessageEncryptor
.
new
(
ActiveSupport
::
SecureRandom
.
hex
(
64
))
@data
=
{
:some
=>
"data"
,
:now
=>
Time
.
now
}
@data
=
{
:some
=>
"data"
,
:now
=>
Time
.
local
(
2010
)
}
end
def
test_simple_round_tripping
...
...
activesupport/test/message_verifier_test.rb
浏览文件 @
41e7c68d
...
...
@@ -12,7 +12,7 @@
class
MessageVerifierTest
<
Test
::
Unit
::
TestCase
def
setup
@verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
"Hey, I'm a secret!"
)
@data
=
{
:some
=>
"data"
,
:now
=>
Time
.
now
}
@data
=
{
:some
=>
"data"
,
:now
=>
Time
.
local
(
2010
)
}
end
def
test_simple_round_tripping
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录