zoneless_time 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_record/zoneless_time_support.rb +1 -4
- data/lib/zoneless_time/date_extension.rb +10 -0
- data/lib/zoneless_time/railtie.rb +5 -1
- data/lib/zoneless_time/time_extension.rb +17 -0
- data/lib/zoneless_time/time_without_zone.rb +58 -1
- data/lib/zoneless_time.rb +4 -2
- metadata +6 -5
- data/lib/zoneless_time/equality_with_zoneless_time.rb +0 -11
@@ -4,8 +4,12 @@ require 'rails'
|
|
4
4
|
module ZonelessTime
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer 'zoneless_time.configure_rails_initialization' do
|
7
|
-
ActiveSupport::TimeWithZone.send :include,
|
7
|
+
ActiveSupport::TimeWithZone.send :include, ZonelessTime::TimeExtension::InstanceMethods
|
8
8
|
ActiveRecord::Base.send :extend, ActiveRecord::ZonelessTimeSupport
|
9
|
+
|
10
|
+
if config.time_zone_aware_attributes
|
11
|
+
require 'zoneless_time/warning'
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ZonelessTime
|
2
|
+
module TimeExtension
|
3
|
+
module InstanceMethods
|
4
|
+
def ==(other)
|
5
|
+
if other.is_a? self.class
|
6
|
+
self.without_zone.matches? other
|
7
|
+
else
|
8
|
+
super(other)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def without_zone
|
13
|
+
ZonelessTime::TimeWithoutZone.at(self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,6 +5,35 @@ module ZonelessTime
|
|
5
5
|
RFC2822_DAY_NAME = Time::RFC2822_DAY_NAME
|
6
6
|
RFC2822_MONTH_NAME = Time::RFC2822_MONTH_NAME
|
7
7
|
|
8
|
+
def xmlschema
|
9
|
+
to_time.xmlschema.gsub(/\+.*\Z/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def <=>(other)
|
13
|
+
to_i <=> other.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def >(other)
|
17
|
+
to_i > other.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def <(other)
|
21
|
+
to_i < other.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def +(amount)
|
25
|
+
(to_time + amount).without_zone
|
26
|
+
end
|
27
|
+
|
28
|
+
def -(amount)
|
29
|
+
result = if amount.is_a? Fixnum
|
30
|
+
to_time - amount
|
31
|
+
else
|
32
|
+
to_time - amount.to_time
|
33
|
+
end
|
34
|
+
(result.is_a? Time) ? result.without_zone : result
|
35
|
+
end
|
36
|
+
|
8
37
|
def initialize(year,month,day,hour,min,sec,usec=0)
|
9
38
|
@date = Date.new(year,month,day)
|
10
39
|
@hour = hour
|
@@ -26,6 +55,10 @@ module ZonelessTime
|
|
26
55
|
date.wday
|
27
56
|
end
|
28
57
|
|
58
|
+
def seconds_since_midnight
|
59
|
+
((60 * hour) + min) * 60 + sec
|
60
|
+
end
|
61
|
+
|
29
62
|
def to_s(type=nil)
|
30
63
|
if type == :db
|
31
64
|
"#{year}-#{two_char month}-#{two_char day} #{two_char hour}:#{two_char min}:#{two_char sec}"
|
@@ -38,14 +71,38 @@ module ZonelessTime
|
|
38
71
|
to_s
|
39
72
|
end
|
40
73
|
|
74
|
+
def to_i
|
75
|
+
to_time.to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
def without_zone
|
79
|
+
dup
|
80
|
+
end
|
81
|
+
|
82
|
+
def in_time_zone(*args)
|
83
|
+
dup
|
84
|
+
end
|
85
|
+
|
86
|
+
def local
|
87
|
+
dup
|
88
|
+
end
|
89
|
+
|
90
|
+
def strftime(*args)
|
91
|
+
to_time.strftime *args
|
92
|
+
end
|
93
|
+
|
41
94
|
def matches?(other)
|
42
95
|
[:year, :month, :day, :hour, :min, :sec].all? { |sym| other.send(sym) == self.send(sym) }
|
43
96
|
end
|
44
97
|
|
45
|
-
def
|
98
|
+
def to_time
|
46
99
|
Time.local(year, month, day, hour, min, sec, usec)
|
47
100
|
end
|
48
101
|
|
102
|
+
def to_date
|
103
|
+
Date.new(year, month, day)
|
104
|
+
end
|
105
|
+
|
49
106
|
def ==(other)
|
50
107
|
matches? other
|
51
108
|
end
|
data/lib/zoneless_time.rb
CHANGED
@@ -3,8 +3,10 @@ end
|
|
3
3
|
|
4
4
|
require 'active_record/zoneless_time_support'
|
5
5
|
require 'zoneless_time/time_without_zone'
|
6
|
-
require 'zoneless_time/
|
6
|
+
require 'zoneless_time/time_extension'
|
7
|
+
require 'zoneless_time/date_extension'
|
7
8
|
|
8
|
-
Time.send :include, ZonelessTime::
|
9
|
+
Time.send :include, ZonelessTime::TimeExtension::InstanceMethods
|
10
|
+
Date.send :include, ZonelessTime::DateExtension::InstanceMethods
|
9
11
|
|
10
12
|
require 'zoneless_time/railtie' if defined? Rails
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoneless_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Shaun Mangelsdorf
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-08-10 00:00:00 Z
|
18
18
|
dependencies: []
|
19
19
|
|
20
20
|
description:
|
@@ -28,8 +28,9 @@ extra_rdoc_files:
|
|
28
28
|
files:
|
29
29
|
- lib/active_record/zoneless_time_support.rb
|
30
30
|
- lib/zoneless_time.rb
|
31
|
-
- lib/zoneless_time/
|
31
|
+
- lib/zoneless_time/date_extension.rb
|
32
32
|
- lib/zoneless_time/railtie.rb
|
33
|
+
- lib/zoneless_time/time_extension.rb
|
33
34
|
- lib/zoneless_time/time_without_zone.rb
|
34
35
|
- lib/zoneless_time/warning.rb
|
35
36
|
- README
|