quality_time 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/core_ext/date.rb +32 -0
- data/lib/core_ext/time.rb +29 -0
- data/lib/quality_time.rb +4 -0
- data/quality_time.gemspec +62 -0
- data/spec/lib/core_ext/date_spec.rb +102 -0
- data/spec/lib/core_ext/time_spec.rb +126 -0
- data/spec/spec_helper.rb +12 -0
- metadata +133 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.4)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.8.0)
|
12
|
+
rake (10.0.4)
|
13
|
+
rdoc (4.0.1)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.13.0)
|
16
|
+
rspec-core (~> 2.13.0)
|
17
|
+
rspec-expectations (~> 2.13.0)
|
18
|
+
rspec-mocks (~> 2.13.0)
|
19
|
+
rspec-core (2.13.1)
|
20
|
+
rspec-expectations (2.13.0)
|
21
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
22
|
+
rspec-mocks (2.13.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler
|
29
|
+
jeweler
|
30
|
+
rdoc
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Riley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= QualityTime
|
2
|
+
|
3
|
+
QualityTime extends Ruby's standard Time and Date classes to facilitate
|
4
|
+
safer and more deliberate manipulation of chronological and calendar
|
5
|
+
values, especially for values that precede the introduction of the
|
6
|
+
Gregorian calendar.
|
7
|
+
|
8
|
+
== Extensions to Date and Time
|
9
|
+
|
10
|
+
Date#to_local_time is a Julian-safe replacement for Date#to_time from
|
11
|
+
the Ruby standard library. Date#to_utc_time is an equivalent method that
|
12
|
+
returns the UTC time corresponding to the beginning of the day denoted
|
13
|
+
by Date.
|
14
|
+
|
15
|
+
Time#to_gregorian_date and Time#to_julian_date are convenience methods
|
16
|
+
which supplement Time#to_date from the Ruby standard library. Unlike
|
17
|
+
Time#to_date, these methods return Date objects which use a fixed
|
18
|
+
calendar.
|
19
|
+
|
20
|
+
== Why Date#to_time is unsafe for Julian values
|
21
|
+
|
22
|
+
Dates constructed with a value on or before 1582-10-04 (Julian day 2299160)
|
23
|
+
using the default calendar reform day, as well as any Date constructed
|
24
|
+
explicitly to use the Julian calendar (Date::JULIAN), are unsafe for use
|
25
|
+
with Date#to_time.
|
26
|
+
|
27
|
+
Unlike Date objects, which can use either the Julian or Gregorian calendars,
|
28
|
+
and are freely convertible between the two, Time objects always use the
|
29
|
+
Gregorian calendar, or the "proleptic" Gregorian calendar as it is known
|
30
|
+
when it is applied to values before 1582-10-15 (Julian day 2299161).
|
31
|
+
|
32
|
+
Ruby standard library Date#to_time does not respect this limitation, with
|
33
|
+
the effect that the values of Time objects instantiated from Julian calendar
|
34
|
+
Date objects bear only a misleading relationship to the values of the Date
|
35
|
+
objects that produce them.
|
36
|
+
|
37
|
+
Such an instance of Time will appear to denote the same calendar year,
|
38
|
+
month, and day as the Date object it was derived from, but these attributes
|
39
|
+
belong to a different calendar than is used by the Date object they were
|
40
|
+
derived from.
|
41
|
+
|
42
|
+
As one consequence, the Time object cannot be converted back into a
|
43
|
+
Date object equivalent to the one it was derived from:
|
44
|
+
|
45
|
+
d = Date.new(1582, 10, 4) # Julian day 229160
|
46
|
+
d == d.to_time.to_date # false! (Julian day 229150)
|
47
|
+
|
48
|
+
Other operations on the Time object derived in this fashion are likely
|
49
|
+
to yield misleading results:
|
50
|
+
|
51
|
+
d = Date.new(1582, 10, 4)
|
52
|
+
d.to_time + (60 * 60 * 24) # Minus 9 days: 2299151j
|
53
|
+
Time.now - d.to_time # Includes 10 day error
|
54
|
+
d.to_time.to_date < Date.new(1582, 9, 30) # true
|
55
|
+
|
56
|
+
== Why Date#to_local_time and Date#to_utc_time are safe for all values
|
57
|
+
|
58
|
+
Date#to_local_time and Date#to_utc_time preserve the relationship between
|
59
|
+
the value of the Date object, its chronological Julian day, and the value
|
60
|
+
of the Time object, epoch seconds and nanoseconds. By maintaining the
|
61
|
+
relationship between these values rather than relying on their
|
62
|
+
representations in the Julian or Gregorian calendars, the products of
|
63
|
+
these conversions are interoperable:
|
64
|
+
|
65
|
+
d = Date.new(1582, 10, 4)
|
66
|
+
d == d.to_local_time.to_date # true
|
67
|
+
Time.now - d.to_local_time # Secs since 2299160j
|
68
|
+
d.to_local_time + (60 * 60 * 24) # Plus 1 day: 2299161j
|
69
|
+
d.to_local_time.to_date < Date.new(1582, 9, 30) # false
|
70
|
+
|
71
|
+
== Copyright
|
72
|
+
|
73
|
+
Copyright (c) 2013 Riley Lynch. See LICENSE.txt for further details.
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "quality_time"
|
17
|
+
gem.homepage = "http://github.com/teleological/quality_time"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Patches Ruby's Time and Date classes to do the right thing}
|
20
|
+
gem.description = <<-TXT
|
21
|
+
QualityTime extends Ruby's standard Time and Date classes to facilitate safer and more deliberate manipulation of chronological and calendar values, especially for values that precede the introduction of the Gregorian calendar.
|
22
|
+
TXT
|
23
|
+
gem.email = "oss+time@teleological.net"
|
24
|
+
gem.authors = ["Riley Lynch"]
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "quality_time #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
class Date
|
5
|
+
|
6
|
+
# Returns a local Time object denoting the start (in local time) of the
|
7
|
+
# chronological Julian day represented by the Date. Note that Time objects
|
8
|
+
# always use the Gregorian calendar to calculate civil coordinates such as
|
9
|
+
# month, day and year. This method is intended to replace the standard
|
10
|
+
# Date#to_time method, which produces invalid Time objects for Dates which
|
11
|
+
# use the Julian calendar.
|
12
|
+
def to_local_time
|
13
|
+
Time.local(*gregorian_civil_coordinates)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a UTC Time object denoting the start (in UTC) of the
|
17
|
+
# chronological Julian day represented by the Date. Note that Time objects
|
18
|
+
# always use the Gregorian calendar to calculate civil coordinates such as
|
19
|
+
# month, day and year.
|
20
|
+
def to_utc_time
|
21
|
+
Time.utc(*gregorian_civil_coordinates)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def gregorian_civil_coordinates
|
27
|
+
d = gregorian? ? self : gregorian
|
28
|
+
[ d.year, d.month, d.day ]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require 'date'
|
3
|
+
# Time#to_date defined in date library extension
|
4
|
+
|
5
|
+
class Time
|
6
|
+
|
7
|
+
# Returns a Date object denoting the chronological Julian day corresponding
|
8
|
+
# to the Time value's Gregorian date. Date objects returned by this method
|
9
|
+
# use the Gregorian calendar or proleptic Gregorian calendar for any value.
|
10
|
+
def to_gregorian_date
|
11
|
+
to_date_with_start(Date::GREGORIAN)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a Date object denoting the chronological Julian day corresponding
|
15
|
+
# to the Time value's Gregorian date. Date objects returned by this method
|
16
|
+
# use the Julian calendar for any value.
|
17
|
+
def to_julian_date
|
18
|
+
to_date_with_start(Date::JULIAN)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def to_date_with_start(start)
|
24
|
+
d = to_date
|
25
|
+
d.start == start ? d : d.new_start(start)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
data/lib/quality_time.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "quality_time"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Riley Lynch"]
|
12
|
+
s.date = "2013-05-17"
|
13
|
+
s.description = "QualityTime extends Ruby's standard Time and Date classes to facilitate safer and more deliberate manipulation of chronological and calendar values, especially for values that precede the introduction of the Gregorian calendar.\n"
|
14
|
+
s.email = "oss+time@teleological.net"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/core_ext/date.rb",
|
29
|
+
"lib/core_ext/time.rb",
|
30
|
+
"lib/quality_time.rb",
|
31
|
+
"spec/lib/core_ext/date_spec.rb",
|
32
|
+
"spec/lib/core_ext/time_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/teleological/quality_time"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.23"
|
39
|
+
s.summary = "Patches Ruby's Time and Date classes to do the right thing"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
51
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
52
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
53
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
58
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Date do
|
5
|
+
context "with QualityTime extensions" do
|
6
|
+
|
7
|
+
shared_examples_for "a symmetrically convertible Time value" do
|
8
|
+
|
9
|
+
it "returns an equivalent Time for Julian value, Julian start" do
|
10
|
+
d = Date.new(1582, 10, 4)
|
11
|
+
d.send(method).to_date.should == d
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an equivalent Time for Julian value, Gregorian start" do
|
15
|
+
d = Date.new(1582, 10, 4, Date::GREGORIAN)
|
16
|
+
d.send(method).to_date.should == d
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an equivalent Time for proleptic Gregorian gap value" do
|
20
|
+
d = Date.new(1582, 10, 14, Date::GREGORIAN)
|
21
|
+
d.send(method).to_date.should == d
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an equivalent Time for Gregorian value" do
|
25
|
+
d = Date.new(1582, 10, 15)
|
26
|
+
d.send(method).to_date.should == d
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns an equivalent Time for Gregorian value, Julian start" do
|
30
|
+
d = Date.new(1582, 10, 15, Date::JULIAN)
|
31
|
+
d.send(method).to_date.should == d
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#to_local_time" do
|
37
|
+
|
38
|
+
let(:method) { :to_local_time }
|
39
|
+
|
40
|
+
it_should_behave_like "a symmetrically convertible Time value"
|
41
|
+
|
42
|
+
it "returns a local Time object" do
|
43
|
+
Date.new.send(method).should_not be_utc
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#to_utc_time" do
|
49
|
+
|
50
|
+
let(:method) { :to_utc_time }
|
51
|
+
|
52
|
+
it_should_behave_like "a symmetrically convertible Time value"
|
53
|
+
|
54
|
+
it "returns a utc Time object" do
|
55
|
+
Date.new.send(method).should be_utc
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# The following examples do not specify the behavior of QualityTime
|
61
|
+
# but demonstrate why it's needed: Standard library Date#to_time
|
62
|
+
# doesn't play well with Julian dates
|
63
|
+
describe "#to_time" do
|
64
|
+
|
65
|
+
let(:method) { :to_time }
|
66
|
+
|
67
|
+
it "returns an equivalent Time for Julian value, Julian start" do
|
68
|
+
pending "Date#to_time does not return a valid Time for Julian dates"
|
69
|
+
d = Date.new(1582, 10, 4)
|
70
|
+
d.send(method).to_date.should == d
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns an equivalent Time for Julian value, Gregorian start" do
|
74
|
+
d = Date.new(1582, 10, 4, Date::GREGORIAN)
|
75
|
+
d.send(method).to_date.should == d
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns an equivalent Time for proleptic Gregorian gap value" do
|
79
|
+
d = Date.new(1582, 10, 14, Date::GREGORIAN)
|
80
|
+
d.send(method).to_date.should == d
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns an equivalent Time for Gregorian value" do
|
84
|
+
d = Date.new(1582, 10, 15)
|
85
|
+
d.send(method).to_date.should == d
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns an equivalent Time for Gregorian value, Julian start" do
|
89
|
+
pending "Date#to_time does not return a valid Time for Julian dates"
|
90
|
+
d = Date.new(1582, 10, 15, Date::JULIAN)
|
91
|
+
d.send(method).to_date.should == d
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns a local Time object" do
|
95
|
+
Date.new.to_time.should_not be_utc
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Time do
|
5
|
+
context "with QualityTime extensions" do
|
6
|
+
|
7
|
+
shared_examples_for "a symmetrically convertible Date value" do
|
8
|
+
|
9
|
+
it "returns an equivalent Date for value in Julian range" do
|
10
|
+
t = Time.send(constructor, 1582, 10, 4)
|
11
|
+
t.send(method).send(reconverter).should == t
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an equivalent Date for value in proleptic Gregorian range" do
|
15
|
+
t = Time.send(constructor, 1582, 10, 14)
|
16
|
+
t.send(method).send(reconverter).should == t
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an equivalent Date for value in Gregorian range" do
|
20
|
+
t = Time.send(constructor, 1582, 10, 15)
|
21
|
+
t.send(method).send(reconverter).should == t
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
shared_examples_for "a value convertible to a fixed calendar Date" do
|
27
|
+
|
28
|
+
it "returns an equivalent Date for value in Julian range" do
|
29
|
+
t = Time.send(constructor, 1582, 10, 4)
|
30
|
+
t.send(method).start.should == start_day
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns an equivalent Date for value in proleptic Gregorian range" do
|
34
|
+
t = Time.send(constructor, 1582, 10, 14)
|
35
|
+
t.send(method).start.should == start_day
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns an equivalent Date for value in Gregorian range" do
|
39
|
+
t = Time.send(constructor, 1582, 10, 15)
|
40
|
+
t.send(method).start.should == start_day
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#to_gregorian_date" do
|
46
|
+
|
47
|
+
let(:method) { :to_gregorian_date }
|
48
|
+
let(:start_day) { Date::GREGORIAN }
|
49
|
+
|
50
|
+
context "with UTC Time object" do
|
51
|
+
|
52
|
+
let(:constructor) { :utc }
|
53
|
+
let(:reconverter) { :to_utc_time }
|
54
|
+
|
55
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
56
|
+
it_should_behave_like "a value convertible to a fixed calendar Date"
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with local Date object" do
|
61
|
+
|
62
|
+
let(:constructor) { :local }
|
63
|
+
let(:reconverter) { :to_local_time }
|
64
|
+
|
65
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
66
|
+
it_should_behave_like "a value convertible to a fixed calendar Date"
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#to_julian_date" do
|
73
|
+
|
74
|
+
let(:method) { :to_julian_date }
|
75
|
+
let(:start_day) { Date::JULIAN }
|
76
|
+
|
77
|
+
context "with UTC Time object" do
|
78
|
+
|
79
|
+
let(:constructor) { :utc }
|
80
|
+
let(:reconverter) { :to_utc_time }
|
81
|
+
|
82
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
83
|
+
it_should_behave_like "a value convertible to a fixed calendar Date"
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with local Time object" do
|
88
|
+
|
89
|
+
let(:constructor) { :local }
|
90
|
+
let(:reconverter) { :to_local_time }
|
91
|
+
|
92
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
93
|
+
it_should_behave_like "a value convertible to a fixed calendar Date"
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#to_date" do
|
100
|
+
|
101
|
+
let(:method) { :to_date }
|
102
|
+
|
103
|
+
context "with UTC Time object" do
|
104
|
+
|
105
|
+
let(:constructor) { :utc }
|
106
|
+
let(:reconverter) { :to_utc_time }
|
107
|
+
|
108
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
109
|
+
# NOTE: start day of Date is variable
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
context "with local Time object" do
|
114
|
+
|
115
|
+
let(:constructor) { :local }
|
116
|
+
let(:reconverter) { :to_local_time }
|
117
|
+
|
118
|
+
it_should_behave_like "a symmetrically convertible Date value"
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'quality_time'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quality_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Riley Lynch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! 'QualityTime extends Ruby''s standard Time and Date classes to facilitate
|
79
|
+
safer and more deliberate manipulation of chronological and calendar values, especially
|
80
|
+
for values that precede the introduction of the Gregorian calendar.
|
81
|
+
|
82
|
+
'
|
83
|
+
email: oss+time@teleological.net
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files:
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.rdoc
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- lib/core_ext/date.rb
|
99
|
+
- lib/core_ext/time.rb
|
100
|
+
- lib/quality_time.rb
|
101
|
+
- quality_time.gemspec
|
102
|
+
- spec/lib/core_ext/date_spec.rb
|
103
|
+
- spec/lib/core_ext/time_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: http://github.com/teleological/quality_time
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: -3390765301944666235
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.8.23
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Patches Ruby's Time and Date classes to do the right thing
|
133
|
+
test_files: []
|