date_time_precision 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/date_time_precision/lib.rb +17 -17
- data/lib/date_time_precision/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YjIwYmMzODc3M2I3OGQ1NDFmYTkwZWZlYTkyN2RiZDE2MmEwYWU4ZQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d201a91d3f2d08217016d5df57af32fc48dd427
|
4
|
+
data.tar.gz: 08528ce418c4e2e8856b16d221de467b7411d9c9
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MDI4OWI3YzlkM2IxMTM2N2VhNjFlYzI0MmI0YzI4NDk5NjljMzE1OWNlZjMw
|
11
|
-
MThkZWI5YTE4OGFlODU0YWIyMWMwNTc5NjEzNjYxMmIyNDc3MGE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWQ4NmFhNjVhNWE0MGIzY2U4MWEwMjcwZDI3NDQ2Y2M2MzJiMjdkMzdlYWU4
|
14
|
-
ZTUxZDNkYWE2MTUyMjgzM2I5MmI4MTg5MDkxYjE5YTQ2MTkxMTk3YjMxNTll
|
15
|
-
MjhhZTkyYzRkOTMzZWE2ZGI0NzNlNWU2YmRkZThmODMyYWVjZjI=
|
6
|
+
metadata.gz: ffe6af9a6d0591a7074a80d12a57f8a2f8e92316df2a433e92151405ab128f1decadf30cc487f63fc172e4f8ceeb80a720b7a385ab3001d2fbfb22f9a01949af
|
7
|
+
data.tar.gz: 264309f2a027830f03b8f138715a4cf4683efbe1f0010c7e02ac57de33258a26b7bbf7600b376ee62f88fa847c92182e00d006e5cb01c81860c47625ede584a1
|
@@ -15,7 +15,7 @@ class Date
|
|
15
15
|
offset == 0
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
unless method_defined?(:utc_offset)
|
20
20
|
def utc_offset
|
21
21
|
offset.numerator*3600
|
@@ -37,10 +37,10 @@ module DateTimePrecision
|
|
37
37
|
DECADE = 0.5
|
38
38
|
CENTURY = 0.25
|
39
39
|
NONE = 0
|
40
|
-
|
40
|
+
|
41
41
|
# Default values for y,m,d,h,m,s,frac
|
42
42
|
NEW_DEFAULTS = [-4712,1,1,0,0,0,0]
|
43
|
-
|
43
|
+
|
44
44
|
DATE_ATTRIBUTES = [
|
45
45
|
:year,
|
46
46
|
:mon,
|
@@ -50,7 +50,7 @@ module DateTimePrecision
|
|
50
50
|
:sec,
|
51
51
|
:usec
|
52
52
|
]
|
53
|
-
|
53
|
+
|
54
54
|
DATE_ATTRIBUTE_PRECISIONS = {
|
55
55
|
:century => CENTURY,
|
56
56
|
:decade => DECADE,
|
@@ -108,7 +108,7 @@ module DateTimePrecision
|
|
108
108
|
NONE
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def fragments
|
113
113
|
frags = []
|
114
114
|
frags << year if year?
|
@@ -120,12 +120,12 @@ module DateTimePrecision
|
|
120
120
|
frags << usec if usec?
|
121
121
|
frags
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
# Returns true if dates partially match (i.e. one is a partial date of the other)
|
125
125
|
def partial_match?(date2)
|
126
126
|
self.class::partial_match?(self, date2)
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
def normalize_new_args(args)
|
130
130
|
self.class.normalize_new_args(args)
|
131
131
|
end
|
@@ -141,7 +141,7 @@ module DateTimePrecision
|
|
141
141
|
end
|
142
142
|
|
143
143
|
protected :normalize_new_args
|
144
|
-
|
144
|
+
|
145
145
|
module ClassMethods
|
146
146
|
def partial_match?(date1, date2)
|
147
147
|
return true if date1.nil? or date2.nil?
|
@@ -150,12 +150,12 @@ module DateTimePrecision
|
|
150
150
|
min_precision = [frags1.length,frags2.length].min
|
151
151
|
frags1.slice(0,min_precision) == frags2.slice(0,min_precision)
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
def precision(val)
|
155
155
|
val = val.take(self::MAX_PRECISION) if val.is_a? Array
|
156
156
|
DateTimePrecision::precision(val)
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
def normalize_new_args(args)
|
160
160
|
unless args.all?
|
161
161
|
# Replace nil values with their corresponding default values
|
@@ -175,8 +175,8 @@ module DateTimePrecision
|
|
175
175
|
if base.method_defined?(conversion_method) && !base.instance_methods(false).map(&:to_sym).include?(orig)
|
176
176
|
base.class_eval do
|
177
177
|
alias_method orig, conversion_method
|
178
|
-
define_method(conversion_method) do
|
179
|
-
d = send(orig)
|
178
|
+
define_method(conversion_method) do |*args|
|
179
|
+
d = send(orig, *args)
|
180
180
|
d.precision = [self.precision, d.class::MAX_PRECISION].min
|
181
181
|
DATE_ATTRIBUTES.each do |attribute|
|
182
182
|
d.instance_variable_set(:"@#{attribute}_set", self.instance_variable_get(:"@#{attribute}_set"))
|
@@ -196,15 +196,15 @@ module DateTimePrecision
|
|
196
196
|
|
197
197
|
base.send :public, conversion_method
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
# Extend with this module's class methods
|
201
201
|
base.extend(ClassMethods)
|
202
|
-
|
202
|
+
|
203
203
|
# Define attribute query methods, including:
|
204
204
|
# year?, mon?, day?, hour?, min?, sec?, usec?
|
205
205
|
DATE_ATTRIBUTE_PRECISIONS.each do |attribute_name, precision|
|
206
206
|
#next unless precision <= base::MAX_PRECISION
|
207
|
-
|
207
|
+
|
208
208
|
base.class_eval <<-EOM, __FILE__, __LINE__
|
209
209
|
def #{attribute_name}?
|
210
210
|
return !@#{attribute_name}_set.nil? ? @#{attribute_name}_set : (self.precision >= #{precision})
|
@@ -222,7 +222,7 @@ module DateTimePrecision
|
|
222
222
|
#{DATE_ATTRIBUTES.map{|attribute| "@#{attribute}_set"}.join(', ')} = *(vals.flatten.map{|v| !!v})
|
223
223
|
end
|
224
224
|
EOM
|
225
|
-
|
225
|
+
|
226
226
|
base.instance_eval do
|
227
227
|
alias_method :month?, :mon?
|
228
228
|
|
@@ -230,4 +230,4 @@ module DateTimePrecision
|
|
230
230
|
alias_method :mday?, :day?
|
231
231
|
end
|
232
232
|
end
|
233
|
-
end
|
233
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_time_precision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: appraisal
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
@@ -115,8 +115,8 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .travis.yml
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
120
|
- Appraisals
|
121
121
|
- Gemfile
|
122
122
|
- LICENSE
|
@@ -167,17 +167,17 @@ require_paths:
|
|
167
167
|
- lib
|
168
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- -
|
170
|
+
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
174
|
requirements:
|
175
|
-
- -
|
175
|
+
- - ">="
|
176
176
|
- !ruby/object:Gem::Version
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
180
|
+
rubygems_version: 2.4.6
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Patches Date, Time, and DateTime ruby classes to keep track of precision
|