date_time_precision 0.6.0 → 0.7.0
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/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/README.md +32 -12
- data/gemfiles/activesupport2.gemfile +1 -1
- data/gemfiles/activesupport3.gemfile +1 -1
- data/gemfiles/activesupport4.gemfile +10 -0
- data/lib/date_time_precision/format/iso8601.rb +99 -1
- data/lib/date_time_precision/format/string.rb +8 -0
- data/lib/date_time_precision/format/xsd.rb +1 -0
- data/lib/date_time_precision/lib.rb +8 -1
- data/lib/date_time_precision/patch/1.8.7/date.rb +34 -28
- data/lib/date_time_precision/patch/1.8.7/date_time.rb +42 -28
- data/lib/date_time_precision/patch/1.9.3/date.rb +4 -0
- data/lib/date_time_precision/patch/1.9.3/date_time.rb +12 -0
- data/lib/date_time_precision/version.rb +1 -1
- data/spec/active_support_spec.rb +11 -4
- data/spec/date_time_precision_spec.rb +4 -1
- data/spec/format_spec.rb +50 -23
- metadata +54 -32
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
@@ -11,6 +11,7 @@ rvm:
|
|
11
11
|
gemfile:
|
12
12
|
- gemfiles/activesupport2.gemfile
|
13
13
|
- gemfiles/activesupport3.gemfile
|
14
|
+
- gemfiles/activesupport4.gemfile
|
14
15
|
matrix:
|
15
16
|
exclude:
|
16
17
|
- rvm: 1.9.2
|
@@ -23,3 +24,13 @@ matrix:
|
|
23
24
|
gemfile: gemfiles/activesupport2.gemfile
|
24
25
|
- rvm: rbx-19mode
|
25
26
|
gemfile: gemfiles/activesupport2.gemfile
|
27
|
+
- rvm: 1.8.7
|
28
|
+
gemfile: gemfiles/activesupport4.gemfile
|
29
|
+
- rvm: 1.9.2
|
30
|
+
gemfile: gemfiles/activesupport4.gemfile
|
31
|
+
- rvm: ree
|
32
|
+
gemfile: gemfiles/activesupport4.gemfile
|
33
|
+
- rvm: rbx-18mode
|
34
|
+
gemfile: gemfiles/activesupport4.gemfile
|
35
|
+
- rvm: jruby-18mode
|
36
|
+
gemfile: gemfiles/activesupport4.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -32,17 +32,29 @@ dt.year? # => false
|
|
32
32
|
dt.month? # => true
|
33
33
|
```
|
34
34
|
|
35
|
-
The gem adds the following
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
35
|
+
The gem adds the following (possibly missing) methods to Date, Time, and/or DateTime:
|
36
|
+
|
37
|
+
### Instance Methods
|
38
|
+
|
39
|
+
* precision
|
40
|
+
* precision=
|
41
|
+
* partial_match?
|
42
|
+
* year?
|
43
|
+
* month?
|
44
|
+
* day?
|
45
|
+
* hour?
|
46
|
+
* min?
|
47
|
+
* sec?
|
48
|
+
* to_date
|
49
|
+
* to_time
|
50
|
+
* to_datetime
|
51
|
+
* utc
|
52
|
+
* local
|
53
|
+
|
54
|
+
### Class Methods
|
55
|
+
|
56
|
+
* utc
|
57
|
+
* local
|
46
58
|
|
47
59
|
## Formats
|
48
60
|
|
@@ -57,6 +69,9 @@ require 'date_time_precision/format/string'
|
|
57
69
|
|
58
70
|
Date.new(2000, 5).to_s(:long)
|
59
71
|
# => "May 2000"
|
72
|
+
|
73
|
+
Date.new(nil, 5, 10).to_s(:long)
|
74
|
+
# => "May 10"
|
60
75
|
```
|
61
76
|
|
62
77
|
```ruby
|
@@ -90,6 +105,9 @@ require 'date_time_precision/format/iso8601'
|
|
90
105
|
|
91
106
|
Date.new(2000, 5).iso8601
|
92
107
|
# => "2000-05"
|
108
|
+
|
109
|
+
Time.iso8601("2000-05").precision
|
110
|
+
# => 2
|
93
111
|
```
|
94
112
|
|
95
113
|
## Ruby Compatibility
|
@@ -106,6 +124,8 @@ Sometimes other gems will use the Date/Time class in ways that don't preserve pr
|
|
106
124
|
gems, any compatibility issues will most likely need to be patched within DateTimePrecision itself. This is because DateTimePrecision makes some
|
107
125
|
modifications to how the core Date/Time classes work. (For example, by allowing nil values to be passed to constructors.)
|
108
126
|
|
127
|
+
This gem should work with Rails/ActiveSupport 2, 3, and 4 (but perhaps missing some edge cases).
|
128
|
+
|
109
129
|
So far, the following gems are on the compatibility watch list:
|
110
130
|
|
111
131
|
- [.] [ActiveSupport](https://github.com/rails/rails/tree/master/activesupport)
|
@@ -136,7 +156,7 @@ Or install it yourself as:
|
|
136
156
|
- [x] Time::mktime
|
137
157
|
- [x] Time::utc and Time#utc
|
138
158
|
- [x] Time::local
|
139
|
-
- [
|
159
|
+
- [x] Correct generation and parsing of the ISO 8601 format, which supports partial dates and times
|
140
160
|
- [ ] The various time zone methods (partially done)
|
141
161
|
- [.] Easy string formatting based on precision
|
142
162
|
- [ ] [ActiveSupport::TimeWithZone](http://apidock.com/rails/ActiveSupport/TimeWithZone)
|
@@ -14,8 +14,9 @@ end
|
|
14
14
|
end
|
15
15
|
|
16
16
|
if method_defined?(:iso8601)
|
17
|
-
alias_method :
|
17
|
+
alias_method :iso8601_original, :iso8601
|
18
18
|
end
|
19
|
+
|
19
20
|
def iso8601
|
20
21
|
precision = self.precision || 0
|
21
22
|
format = ""
|
@@ -49,4 +50,101 @@ end
|
|
49
50
|
output
|
50
51
|
end
|
51
52
|
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Date.instance_eval do
|
56
|
+
if method_defined? :_xmlschema
|
57
|
+
def xmlschema(val)
|
58
|
+
date = _xmlschema(val).to_date
|
59
|
+
if date.precision == DateTimePrecision::NONE
|
60
|
+
raise ArgumentError.new("invalid date")
|
61
|
+
end
|
62
|
+
date
|
63
|
+
end
|
64
|
+
else
|
65
|
+
def xmlschema(val)
|
66
|
+
Time.xmlschema(val).to_date
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if method_defined? :iso8601
|
71
|
+
alias_method :iso8601_original, :iso8601
|
72
|
+
def iso8601(val)
|
73
|
+
date = iso8601_original(val)
|
74
|
+
rescue
|
75
|
+
xmlschema(val)
|
76
|
+
end
|
77
|
+
else
|
78
|
+
def iso8601(val)
|
79
|
+
xmlschema(val)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
Time.instance_eval do
|
85
|
+
def xmlschema(date)
|
86
|
+
if /\A\s*
|
87
|
+
(-?\d+)(?:-(\d\d)(?:-(\d\d)
|
88
|
+
(?:T
|
89
|
+
(\d\d)(?::(\d\d)(?::(\d\d)
|
90
|
+
(\.\d+)?
|
91
|
+
)?)?)?
|
92
|
+
(Z|[+-]\d\d:\d\d)?
|
93
|
+
)?)?
|
94
|
+
\s*\z/ix =~ date
|
95
|
+
year = $1 && $1.to_i
|
96
|
+
mon = $2 && $2.to_i
|
97
|
+
day = $3 && $3.to_i
|
98
|
+
hour = $4 && $4.to_i
|
99
|
+
min = $5 && $5.to_i
|
100
|
+
sec = $6 && $6.to_i
|
101
|
+
usec = 0
|
102
|
+
if $7
|
103
|
+
usec = Rational($7) * 1000000
|
104
|
+
end
|
105
|
+
if $8
|
106
|
+
zone = $8
|
107
|
+
year, mon, day, hour, min, sec =
|
108
|
+
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
|
109
|
+
self.utc(year, mon, day, hour, min, sec, usec)
|
110
|
+
else
|
111
|
+
self.local(year, mon, day, hour, min, sec, usec)
|
112
|
+
end
|
113
|
+
else
|
114
|
+
raise ArgumentError.new("invalid date: #{date.inspect}")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def iso8601(date)
|
119
|
+
xmlschema(date)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
DateTime.instance_eval do
|
124
|
+
if method_defined? :_xmlschema
|
125
|
+
def xmlschema(val)
|
126
|
+
date = _xmlschema(val).to_datetime
|
127
|
+
if date.precision == DateTimePrecision::NONE
|
128
|
+
raise ArgumentError.new("invalid date")
|
129
|
+
end
|
130
|
+
date
|
131
|
+
end
|
132
|
+
else
|
133
|
+
def xmlschema(val)
|
134
|
+
Time.xmlschema(val).to_datetime
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
if method_defined? :iso8601
|
139
|
+
alias_method :iso8601_original, :iso8601
|
140
|
+
def iso8601(val)
|
141
|
+
date = iso8601_original(val)
|
142
|
+
rescue
|
143
|
+
xmlschema(val)
|
144
|
+
end
|
145
|
+
else
|
146
|
+
def iso8601(val)
|
147
|
+
xmlschema(val)
|
148
|
+
end
|
149
|
+
end
|
52
150
|
end
|
@@ -8,6 +8,10 @@ Date::DATE_FORMATS[:long] = lambda do |date|
|
|
8
8
|
date.strftime("%B %Y")
|
9
9
|
when date.precision == DateTimePrecision::YEAR
|
10
10
|
date.strftime("%Y")
|
11
|
+
when date.month? && date.day?
|
12
|
+
date.strftime("%B %e")
|
13
|
+
when date.month?
|
14
|
+
date.strftime("%B")
|
11
15
|
else
|
12
16
|
""
|
13
17
|
end
|
@@ -25,6 +29,10 @@ Time::DATE_FORMATS[:long] = lambda do |time|
|
|
25
29
|
time.strftime("%B %Y")
|
26
30
|
when time.precision == DateTimePrecision::YEAR
|
27
31
|
time.strftime("%Y")
|
32
|
+
when time.month? && time.day?
|
33
|
+
time.strftime("%B %e")
|
34
|
+
when time.month?
|
35
|
+
time.strftime("%B")
|
28
36
|
else
|
29
37
|
""
|
30
38
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'date_time_precision/format/iso8601'
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'time'
|
3
|
+
|
1
4
|
if defined?(ActiveSupport)
|
2
5
|
['active_support/core_ext/date', 'active_support/core_ext/datetime', 'active_support/core_ext/time', 'active_support/time', 'active_support/time_with_zone'].each do |f|
|
3
6
|
begin
|
@@ -145,6 +148,7 @@ module DateTimePrecision
|
|
145
148
|
def self.included(base)
|
146
149
|
# Redefine any conversion methods so precision is preserved
|
147
150
|
[:to_date, :to_time, :to_datetime].each do |conversion_method|
|
151
|
+
# If the conversion method is already defined, patch it
|
148
152
|
orig = :"orig_#{conversion_method}"
|
149
153
|
if base.method_defined?(conversion_method) && !base.instance_methods(false).map(&:to_sym).include?(orig)
|
150
154
|
base.class_eval do
|
@@ -167,12 +171,15 @@ module DateTimePrecision
|
|
167
171
|
end
|
168
172
|
end
|
169
173
|
end
|
174
|
+
|
175
|
+
base.send :public, conversion_method
|
170
176
|
end
|
171
177
|
|
172
178
|
# Extend with this module's class methods
|
173
179
|
base.extend(ClassMethods)
|
174
180
|
|
175
|
-
# Define attribute query methods
|
181
|
+
# Define attribute query methods, including:
|
182
|
+
# year?, mon?, day?, hour?, min?, sec?, sec_frac?
|
176
183
|
DATE_ATTRIBUTE_PRECISIONS.each do |attribute_name, precision|
|
177
184
|
#next unless precision <= base::MAX_PRECISION
|
178
185
|
|
@@ -6,39 +6,45 @@ class Date
|
|
6
6
|
|
7
7
|
include DateTimePrecision
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
class << self
|
10
|
+
def parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=Date::ITALY)
|
11
|
+
elem = _parse(str, comp)
|
12
|
+
precision = DateTimePrecision::precision(elem)
|
13
|
+
d = new_by_frags(elem, sg)
|
14
|
+
d.precision = precision
|
15
|
+
d
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def strptime(str='-4712-01-01', fmt='%F', sg=Date::ITALY)
|
19
|
+
elem = _strptime(str, fmt)
|
20
|
+
precision = DateTimePrecision::precision(elem)
|
21
|
+
d = new_by_frags(elem, sg)
|
22
|
+
d.precision = precision
|
23
|
+
d
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def civil(y=nil, m=nil, d=nil, sg=Date::ITALY)
|
27
|
+
args = [y,m,d]
|
28
|
+
precision = self.precision(args)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
args = normalize_new_args(args)
|
31
|
+
|
32
|
+
unless jd = valid_civil?(*args)
|
33
|
+
raise ArgumentError, 'invalid date'
|
34
|
+
end
|
35
|
+
|
36
|
+
date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
37
|
+
date.precision = precision
|
38
|
+
date.attributes_set(y,m,d)
|
39
|
+
date
|
33
40
|
end
|
34
|
-
|
35
|
-
date = new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
36
|
-
date.precision = precision
|
37
|
-
date.attributes_set(y,m,d)
|
38
|
-
date
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
+
alias_method :new, :civil
|
43
|
+
|
44
|
+
def utc(*args)
|
45
|
+
Time.utc(*args).to_date
|
46
|
+
end
|
47
|
+
end
|
42
48
|
|
43
49
|
=begin
|
44
50
|
Following code is unneccessary, but keeping it as an example
|
@@ -6,38 +6,52 @@ class DateTime < Date
|
|
6
6
|
|
7
7
|
include DateTimePrecision
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
class << self
|
10
|
+
def parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=DateTime::ITALY)
|
11
|
+
elem = _parse(str, comp)
|
12
|
+
precision = DateTimePrecision::precision(elem)
|
13
|
+
dt = new_by_frags(elem, sg)
|
14
|
+
dt.precision = precision
|
15
|
+
dt
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def civil(y=nil, m=nil, d=nil, h=nil, min=nil, s=nil, of=0, sg=DateTime::ITALY)
|
19
|
+
time_args = [y,m,d,h,min,s]
|
20
|
+
precision = self.precision(time_args)
|
21
|
+
time_args = normalize_new_args(time_args)
|
22
|
+
|
23
|
+
unless (jd = valid_civil?(time_args[0], time_args[1], time_args[2], sg)) && (fr = valid_time?(time_args[3], time_args[4], time_args[5]))
|
24
|
+
raise ArgumentError, 'invalid date'
|
25
|
+
end
|
26
|
+
if String === of
|
27
|
+
of = Rational(zone_to_diff(of) || 0, 86400)
|
28
|
+
end
|
29
|
+
dt = new!(jd_to_ajd(jd, fr, of), of, sg)
|
30
|
+
dt.precision = precision
|
31
|
+
dt.attributes_set(y,m,d,h,min,s)
|
32
|
+
dt
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :new, :civil
|
36
|
+
|
37
|
+
def strptime(str='-4712-01-01', fmt='%F', sg=DateTime::ITALY)
|
38
|
+
elem = _strptime(str, fmt)
|
39
|
+
precision = DateTimePrecision::precision(elem)
|
40
|
+
d = new_by_frags(elem, sg)
|
41
|
+
d.precision = precision
|
42
|
+
d
|
24
43
|
end
|
25
|
-
|
26
|
-
|
44
|
+
|
45
|
+
def utc(*args)
|
46
|
+
Time.utc(*args).to_datetime
|
27
47
|
end
|
28
|
-
dt = new!(jd_to_ajd(jd, fr, of), of, sg)
|
29
|
-
dt.precision = precision
|
30
|
-
dt.attributes_set(y,m,d,h,min,s)
|
31
|
-
dt
|
32
|
-
end
|
33
48
|
|
34
|
-
|
49
|
+
def local(*args)
|
50
|
+
Time.local(*args).to_datetime
|
51
|
+
end
|
52
|
+
end
|
35
53
|
|
36
|
-
def
|
37
|
-
|
38
|
-
precision = DateTimePrecision::precision(elem)
|
39
|
-
d = new_by_frags(elem, sg)
|
40
|
-
d.precision = precision
|
41
|
-
d
|
54
|
+
def utc
|
55
|
+
self.to_time.utc.to_datetime
|
42
56
|
end
|
43
57
|
end
|
@@ -46,6 +46,18 @@ class DateTime < Date
|
|
46
46
|
d.precision = precision
|
47
47
|
d
|
48
48
|
end
|
49
|
+
|
50
|
+
def utc(*args)
|
51
|
+
Time.utc(*args).to_datetime
|
52
|
+
end
|
53
|
+
|
54
|
+
def local(*args)
|
55
|
+
Time.local(*args).to_datetime
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def utc
|
60
|
+
self.to_time.utc.to_datetime
|
49
61
|
end
|
50
62
|
|
51
63
|
end
|
data/spec/active_support_spec.rb
CHANGED
@@ -45,21 +45,28 @@ describe DateTimePrecision, 'Conversions' do
|
|
45
45
|
Date.new(2000).to_s(:long).should == "2000"
|
46
46
|
Date.new(2000, 8).to_s(:long).should == "August 2000"
|
47
47
|
Date.new(2000, 3, 9).to_s(:long).should == "March 9, 2000"
|
48
|
+
Date.new(nil, 5, 13).to_s(:long).should == "May 13"
|
49
|
+
Date.new(nil, 6).to_s(:long).should == "June"
|
48
50
|
|
49
51
|
DateTime.new(1800).to_s(:long).should == "1800"
|
50
52
|
DateTime.new(1990, 8).to_s(:long).should == "August 1990"
|
51
53
|
DateTime.new(-50, 3, 9).to_s(:long).should == "March 09, -0050"
|
52
54
|
DateTime.new(2004, 7, 8, 10).to_s(:long).should == "July 08, 2004"
|
53
55
|
DateTime.new(2004, 7, 8, 10, 5).to_s(:long).should == "July 08, 2004 10:05"
|
56
|
+
DateTime.new(nil, 5, 13).to_s(:long).should == "May 13"
|
57
|
+
DateTime.new(nil, 6).to_s(:long).should == "June"
|
54
58
|
|
55
59
|
Time.mktime(1800).to_s(:long).should == "1800"
|
56
|
-
Time
|
60
|
+
Time.mktime(1990, 8).to_s(:long).should == "August 1990"
|
57
61
|
|
58
62
|
# Every Ruby seems to have a different idea about how to format this exactly
|
59
|
-
Time
|
63
|
+
Time.mktime(-50, 3, 9).to_s(:long).should match /^March 09, 0*\-0*50$/
|
60
64
|
|
61
|
-
Time
|
62
|
-
Time
|
65
|
+
Time.mktime(2004, 7, 8, 10).to_s(:long).should == "July 08, 2004"
|
66
|
+
Time.mktime(2004, 7, 8, 10, 5).to_s(:long).should == "July 08, 2004 10:05"
|
67
|
+
|
68
|
+
Time.mktime(nil, 5, 13).to_s(:long).should == "May 13"
|
69
|
+
Time.mktime(nil, 6).to_s(:long).should == "June"
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|
@@ -84,9 +84,12 @@ describe DateTimePrecision do
|
|
84
84
|
Time.mktime(2000).gmtime.precision.should == DateTimePrecision::YEAR
|
85
85
|
end
|
86
86
|
|
87
|
-
it 'should track precision when creating a time in UTC' do
|
87
|
+
it 'should track precision when creating a date, time, or datetime in UTC' do
|
88
88
|
Time.utc(1945, 10).precision.should == DateTimePrecision::MONTH
|
89
89
|
Time.gm(1945, 10).precision.should == DateTimePrecision::MONTH
|
90
|
+
|
91
|
+
Date.utc(1945, 10).precision.should == DateTimePrecision::MONTH
|
92
|
+
DateTime.utc(1945, 10).precision.should == DateTimePrecision::MONTH
|
90
93
|
end
|
91
94
|
|
92
95
|
it 'should track precision when creating a time in the local timezone' do
|
data/spec/format_spec.rb
CHANGED
@@ -12,31 +12,58 @@ describe DateTimePrecision do
|
|
12
12
|
Time.mktime(*args)
|
13
13
|
end
|
14
14
|
|
15
|
-
context 'ISO 8601' do
|
15
|
+
context 'ISO 8601 or XSD' do
|
16
16
|
require 'date_time_precision/format/iso8601'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
DateTime.new(1990, 5).iso8601.should == "1990-05"
|
28
|
-
DateTime.new(1990, 5, 2).iso8601.should == "1990-05-02"
|
29
|
-
DateTime.new(1990, 5, 2, 12).iso8601.should == "1990-05-02T12Z"
|
30
|
-
DateTime.new(1990, 5, 2, 12, 30).iso8601.should == "1990-05-02T12:30Z"
|
17
|
+
|
18
|
+
before(:all) do
|
19
|
+
@table = [
|
20
|
+
[[1989], "1989"],
|
21
|
+
[[1990, 5], "1990-05"],
|
22
|
+
[[1800, 5, 6], "1800-05-06"],
|
23
|
+
[[1990, 5, 2, 12], "1990-05-02T12Z"],
|
24
|
+
[[1990, 5, 2, 12, 30], "1990-05-02T12:30Z"],
|
25
|
+
[[1990, 5, 2, 12, 30, 45], "1990-05-02T12:30:45Z"]
|
26
|
+
]
|
31
27
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
|
29
|
+
[:iso8601, :xmlschema].each do |format_method|
|
30
|
+
it 'converts a date to and from ISO 8601' do
|
31
|
+
date.send(format_method).should == "1989-03-11"
|
32
|
+
|
33
|
+
@table.take(3).each do |args, format_string|
|
34
|
+
Date.new(*args).send(format_method).should == format_string
|
35
|
+
|
36
|
+
d = Date.send(format_method, format_string)
|
37
|
+
d.should == Date.new(*args)
|
38
|
+
d.precision.should == args.length
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'converts a datetime to and from ISO 8601' do
|
43
|
+
datetime.send(format_method).should == "1989-03-11T08:30:15Z"
|
44
|
+
|
45
|
+
@table.each do |args, format_string|
|
46
|
+
DateTime.new(*args).send(format_method).should == format_string
|
47
|
+
|
48
|
+
d = DateTime.send(format_method, format_string)
|
49
|
+
constructor = args.length > 3 ? :utc : :local
|
50
|
+
d.should == DateTime.send(constructor, *args)
|
51
|
+
d.precision.should == args.length
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'converts a time to ISO 8601' do
|
56
|
+
Time.mktime(1900).send(format_method).should == "1900"
|
57
|
+
|
58
|
+
@table.each do |args, format_string|
|
59
|
+
Time.utc(*args).send(format_method).should == format_string
|
60
|
+
|
61
|
+
t = Time.send(format_method, format_string)
|
62
|
+
constructor = args.length > 3 ? :utc : :local
|
63
|
+
t.should == Time.send(constructor, *args)
|
64
|
+
t.precision.should == args.length
|
65
|
+
end
|
66
|
+
end
|
40
67
|
end
|
41
68
|
end
|
42
69
|
|
metadata
CHANGED
@@ -1,99 +1,112 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_time_precision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- David Butler
|
8
|
-
autorequire:
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
15
22
|
requirement: !ruby/object:Gem::Requirement
|
16
23
|
requirements:
|
17
24
|
- - '>='
|
18
25
|
- !ruby/object:Gem::Version
|
19
26
|
version: '0'
|
20
|
-
|
27
|
+
none: false
|
21
28
|
prerelease: false
|
29
|
+
type: :development
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
22
32
|
version_requirements: !ruby/object:Gem::Requirement
|
23
33
|
requirements:
|
24
34
|
- - '>='
|
25
35
|
- !ruby/object:Gem::Version
|
26
36
|
version: '0'
|
27
|
-
|
28
|
-
name: rspec
|
37
|
+
none: false
|
29
38
|
requirement: !ruby/object:Gem::Requirement
|
30
39
|
requirements:
|
31
40
|
- - '>='
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: '0'
|
34
|
-
|
43
|
+
none: false
|
35
44
|
prerelease: false
|
45
|
+
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
36
48
|
version_requirements: !ruby/object:Gem::Requirement
|
37
49
|
requirements:
|
38
50
|
- - '>='
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: '0'
|
41
|
-
|
42
|
-
name: activesupport
|
53
|
+
none: false
|
43
54
|
requirement: !ruby/object:Gem::Requirement
|
44
55
|
requirements:
|
45
56
|
- - '>='
|
46
57
|
- !ruby/object:Gem::Version
|
47
58
|
version: '0'
|
48
|
-
|
59
|
+
none: false
|
49
60
|
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
|
56
|
-
name: json
|
69
|
+
none: false
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
58
71
|
requirements:
|
59
72
|
- - '>='
|
60
73
|
- !ruby/object:Gem::Version
|
61
74
|
version: '0'
|
62
|
-
|
75
|
+
none: false
|
63
76
|
prerelease: false
|
64
|
-
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
77
|
+
type: :development
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: virtus
|
71
|
-
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
81
|
requirements:
|
73
82
|
- - '='
|
74
83
|
- !ruby/object:Gem::Version
|
75
84
|
version: 0.5.4
|
76
|
-
|
77
|
-
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
79
87
|
requirements:
|
80
88
|
- - '='
|
81
89
|
- !ruby/object:Gem::Version
|
82
90
|
version: 0.5.4
|
91
|
+
none: false
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: coercible
|
85
|
-
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
97
|
requirements:
|
87
98
|
- - '='
|
88
99
|
- !ruby/object:Gem::Version
|
89
100
|
version: 0.0.1
|
90
|
-
|
91
|
-
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
93
103
|
requirements:
|
94
104
|
- - '='
|
95
105
|
- !ruby/object:Gem::Version
|
96
106
|
version: 0.0.1
|
107
|
+
none: false
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
97
110
|
description: Patches Date, Time, and DateTime ruby classes to keep track of precision
|
98
111
|
email:
|
99
112
|
- dwbutler@ucla.edu
|
@@ -112,6 +125,7 @@ files:
|
|
112
125
|
- gem_tasks/rspec.rake
|
113
126
|
- gemfiles/activesupport2.gemfile
|
114
127
|
- gemfiles/activesupport3.gemfile
|
128
|
+
- gemfiles/activesupport4.gemfile
|
115
129
|
- lib/date_time_precision.rb
|
116
130
|
- lib/date_time_precision/compat/coercible.rb
|
117
131
|
- lib/date_time_precision/compat/virtus.rb
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- lib/date_time_precision/format/json.rb
|
121
135
|
- lib/date_time_precision/format/nil.rb
|
122
136
|
- lib/date_time_precision/format/string.rb
|
137
|
+
- lib/date_time_precision/format/xsd.rb
|
123
138
|
- lib/date_time_precision/lib.rb
|
124
139
|
- lib/date_time_precision/patch.rb
|
125
140
|
- lib/date_time_precision/patch/1.8.7/date.rb
|
@@ -139,8 +154,7 @@ files:
|
|
139
154
|
- spec/spec_helper.rb
|
140
155
|
homepage: http://github.com/Spokeo/date_time_precision
|
141
156
|
licenses: []
|
142
|
-
|
143
|
-
post_install_message:
|
157
|
+
post_install_message:
|
144
158
|
rdoc_options: []
|
145
159
|
require_paths:
|
146
160
|
- lib
|
@@ -148,17 +162,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
162
|
requirements:
|
149
163
|
- - '>='
|
150
164
|
- !ruby/object:Gem::Version
|
165
|
+
segments:
|
166
|
+
- 0
|
151
167
|
version: '0'
|
168
|
+
hash: 2
|
169
|
+
none: false
|
152
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
171
|
requirements:
|
154
172
|
- - '>='
|
155
173
|
- !ruby/object:Gem::Version
|
174
|
+
segments:
|
175
|
+
- 0
|
156
176
|
version: '0'
|
177
|
+
hash: 2
|
178
|
+
none: false
|
157
179
|
requirements: []
|
158
|
-
rubyforge_project:
|
159
|
-
rubygems_version:
|
160
|
-
signing_key:
|
161
|
-
specification_version:
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 1.8.24
|
182
|
+
signing_key:
|
183
|
+
specification_version: 3
|
162
184
|
summary: Patches Date, Time, and DateTime ruby classes to keep track of precision
|
163
185
|
test_files:
|
164
186
|
- spec/active_support_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: d9e306c98b83f8d976c0f1499b17b3fe57503797
|
4
|
-
data.tar.gz: cf7744903d1a1ea1c3aa8fef6bc98896853bf27a
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 5ec71030888d088622a1a30e92767beb730e10a4168da758b7ac623e188c9d995d9daf5b83b5c402a1106e681bf7be70dd49630e0d870963327aca95cd439500
|
7
|
-
data.tar.gz: b832c62848bae15b69ed22b1c7111d97916458b7f84f0ae8884d00ec35a260e3e95ca482bd1c6166d28f6aecb564ad3c20b988b2e002874facf9c5ed75299ee4
|