anytime 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/anytime.rb +30 -3
- metadata +1 -1
data/lib/anytime.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'mocha'
|
2
|
+
|
1
3
|
class Anytime
|
2
|
-
require 'mocha'
|
3
4
|
def self.freeze_at(year, month, date, hour=0, min=0, sec=0)
|
4
|
-
|
5
|
+
p "-------------#{year}, #{month}, #{date}"
|
6
|
+
DateTime.stubs(:now).returns(DateTime.new(year, month, date, hour, min, sec, self.utc_offset))
|
7
|
+
Time.stubs(:now).returns(Time.send(self.time_mode, year, month, date, hour, min, sec))
|
5
8
|
Date.stubs(:today).returns(Date.new(year, month, date))
|
6
|
-
|
9
|
+
p "=============#{Time.now}"
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.unfreeze!
|
@@ -11,4 +14,28 @@ class Anytime
|
|
11
14
|
Date.unstub(:today)
|
12
15
|
DateTime.unstub(:now)
|
13
16
|
end
|
17
|
+
|
18
|
+
def self.setup
|
19
|
+
yield self
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_frozen?
|
23
|
+
Time.now == Time.now
|
24
|
+
end
|
25
|
+
|
26
|
+
mattr_accessor :time_mode
|
27
|
+
|
28
|
+
mattr_accessor :environments
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.utc_offset
|
33
|
+
case self.time_mode
|
34
|
+
when :local
|
35
|
+
ActiveSupport::TimeZone.seconds_to_utc_offset(Time.new.utc_offset)
|
36
|
+
else
|
37
|
+
"00:00"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
14
41
|
end
|