parsi-date 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/lib/parsi-date-accessors.rb +14 -0
- data/lib/parsi-date.rb +2 -0
- data/lib/version.rb +1 -1
- data/parsi-date.gemspec +2 -0
- data/spec/parsi-date/accessor_spec.rb +0 -2
- data/spec/parsi-date/accessors_helper_spec.rb +71 -0
- data/spec/parsi-date/add_month_spec.rb +1 -3
- data/spec/parsi-date/add_spec.rb +1 -3
- data/spec/parsi-date/comp_spec.rb +1 -2
- data/spec/parsi-date/constants_spec.rb +0 -2
- data/spec/parsi-date/construction_spec.rb +0 -2
- data/spec/parsi-date/conversion_spec.rb +1 -3
- data/spec/parsi-date/leap_spec.rb +0 -2
- data/spec/parsi-date/step_spec.rb +1 -3
- data/spec/parsi-date/strftime_spec.rb +1 -3
- data/spec/parsi-date/week_methods_spec.rb +0 -2
- data/spec/spec_helper.rb +0 -6
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f6591ac27ee5b75937f1c0009193a2365581714
|
4
|
+
data.tar.gz: c8f6ff22752cffe88c9c7a53f31bb2b18771ad15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9b2772a0a521e5c28d3b48b47730e383cfea864953c0a76deaa0827826552afdca71cc7535fde7b8eb79f50c7ce9838bb616d735938e784fa4cc4b42aa7ed4a
|
7
|
+
data.tar.gz: 821b2229b82af844d9cb1b0cdd2daac1fce70ad7d433e795e951fc8b741c8a31e26e5276626ce7de1a85dae7aaccdfbfde42bf0e52feeee17df66b153ff4c3ae
|
data/.rspec
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Parsi::DateAccessors
|
2
|
+
def parsi_date_accessor(*names)
|
3
|
+
names.each do |name|
|
4
|
+
define_method("#{name}_parsi") do
|
5
|
+
send(name).to_parsi rescue nil
|
6
|
+
end
|
7
|
+
|
8
|
+
define_method("#{name}_parsi=") do |value|
|
9
|
+
value = Parsi::Date.parse(value) if value.is_a?(String)
|
10
|
+
send("#{name}=", value.to_gregorian)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/parsi-date.rb
CHANGED
data/lib/version.rb
CHANGED
data/parsi-date.gemspec
CHANGED
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency("bundler", "~> 1.4")
|
22
22
|
s.add_development_dependency("rake", "~> 10.0")
|
23
23
|
s.add_development_dependency("rspec", "~> 2.0")
|
24
|
+
s.add_development_dependency("activerecord", "~> 4.2")
|
25
|
+
s.add_development_dependency("sqlite3", "~> 1.3")
|
24
26
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'sqlite3'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
5
|
+
|
6
|
+
ActiveRecord::Schema.verbose = false
|
7
|
+
ActiveRecord::Schema.define do
|
8
|
+
create_table :models do |t|
|
9
|
+
t.date :start_date
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Model < ActiveRecord::Base
|
14
|
+
extend Parsi::DateAccessors
|
15
|
+
parsi_date_accessor :start_date
|
16
|
+
end
|
17
|
+
|
18
|
+
class Record
|
19
|
+
extend Parsi::DateAccessors
|
20
|
+
attr_accessor :created_at, :updated_at
|
21
|
+
parsi_date_accessor :created_at, :updated_at
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Record extended with Parsi::Date::Accessors" do
|
25
|
+
it "has parsi postfixed accessor for giver attributes" do
|
26
|
+
record = Record.new
|
27
|
+
%i(created_at_parsi created_at_parsi= updated_at_parsi updated_at_parsi).each do |name|
|
28
|
+
expect(record.respond_to?(name)).to be_truthy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "created getter" do
|
33
|
+
it "returen given date converted to jalali" do
|
34
|
+
record = Record.new
|
35
|
+
record.created_at = Date.today
|
36
|
+
expect(record.created_at_parsi).to be == Parsi::Date.today
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "created setter" do
|
41
|
+
it "sets date attribute to given date concerted to gregorian" do
|
42
|
+
record = Record.new
|
43
|
+
record.created_at_parsi = Parsi::Date.today
|
44
|
+
expect(record.created_at).to be == Date.today
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with string arg" do
|
48
|
+
it "sets date attribute to given date when parsable" do
|
49
|
+
record = Record.new
|
50
|
+
record.created_at_parsi = "1393-12-12"
|
51
|
+
date = Parsi::Date.parse "1393-12-12"
|
52
|
+
expect(record.created_at_parsi).to be == date
|
53
|
+
expect(record.created_at).to be == date.to_gregorian
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises error when string is not a date" do
|
57
|
+
record = Record.new
|
58
|
+
expect {record.created_at_parsi = "1393-13-11" }.to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "for active_record subclasses" do
|
64
|
+
it "saves attributes to datebase" do
|
65
|
+
model = Model.new start_date_parsi: Parsi::Date.today
|
66
|
+
expect(model[:start_date]).to be == Date.today
|
67
|
+
model.save
|
68
|
+
expect(Model.first.start_date).to be == Date.today
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Parsi::Date#>>" do
|
4
2
|
it "adds the number of months to a Parsi::Date" do
|
5
3
|
d = Parsi::Date.civil(1391, 2, 27) >> 10
|
@@ -26,4 +24,4 @@ describe "Parsi::Date#>>" do
|
|
26
24
|
it "raise a TypeError when passed an Object" do
|
27
25
|
lambda { Parsi::Date.civil(1391, 2, 27) >> Object.new }.should raise_error(TypeError)
|
28
26
|
end
|
29
|
-
end
|
27
|
+
end
|
data/spec/parsi-date/add_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Parsi::Date#+" do
|
4
2
|
it "adds the number of days to a Parsi::Date" do
|
5
3
|
d = Parsi::Date.civil(1391, 2, 27) + 10
|
@@ -26,4 +24,4 @@ describe "Parsi::Date#+" do
|
|
26
24
|
it "raises a TypeError when passed an Object" do
|
27
25
|
lambda { Parsi::Date.civil(1391, 2, 27) + Object.new }.should raise_error(TypeError)
|
28
26
|
end
|
29
|
-
end
|
27
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
1
|
require 'date'
|
3
2
|
|
4
3
|
describe "Parsi::Date#<=>" do
|
@@ -28,4 +27,4 @@ describe "Parsi::Date#<=>" do
|
|
28
27
|
it "returns 1 when self is greater than a Numeric" do
|
29
28
|
(Parsi::Date.civil(1391, 4, 6) <=> Rational(4912208,2)).should == 1
|
30
29
|
end
|
31
|
-
end
|
30
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
|
3
1
|
describe "Parsi::Date.jd" do
|
4
2
|
it "constructs a date form given Chronological Julian day number" do
|
5
3
|
Parsi::Date.jd(2456228).should == Parsi::Date.civil(1391, 8, 6)
|
@@ -35,4 +33,4 @@ describe "Date#to_parsi" do
|
|
35
33
|
date.should be_a(Parsi::Date)
|
36
34
|
date.should == Parsi::Date.civil(1391, 8, 7)
|
37
35
|
end
|
38
|
-
end
|
36
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
3
|
-
|
4
2
|
describe "Parsi::Date#strftime" do
|
5
3
|
|
6
4
|
it "should be able to print the date" do
|
@@ -107,4 +105,4 @@ describe "Parsi::Date#strftime" do
|
|
107
105
|
Parsi::Date.civil(1390, 4, 6).strftime("%x").should == Parsi::Date.civil(1390, 4, 6).strftime('%y/%m/%d')
|
108
106
|
end
|
109
107
|
|
110
|
-
end
|
108
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,4 @@ require 'parsi-date'
|
|
3
3
|
RSpec.configure do |config|
|
4
4
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
5
|
config.run_all_when_everything_filtered = true
|
6
|
-
|
7
|
-
# Run specs in random order to surface order dependencies. If you find an
|
8
|
-
# order dependency and want to debug it, you can fix the order by providing
|
9
|
-
# the seed, which is printed after each run.
|
10
|
-
# --seed 1234
|
11
|
-
# config.order = 'random'
|
12
6
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsi-date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
55
83
|
description: A Solar Hijri (Jalali) date library for Ruby, whitch provides much of
|
56
84
|
Ruby's built-in date class
|
57
85
|
email: hsn.zamani@gmail.com
|
@@ -66,11 +94,13 @@ files:
|
|
66
94
|
- MIT-LICENSE
|
67
95
|
- README.rdoc
|
68
96
|
- TODO
|
97
|
+
- lib/parsi-date-accessors.rb
|
69
98
|
- lib/parsi-date.rb
|
70
99
|
- lib/parsi-datetime.rb
|
71
100
|
- lib/version.rb
|
72
101
|
- parsi-date.gemspec
|
73
102
|
- spec/parsi-date/accessor_spec.rb
|
103
|
+
- spec/parsi-date/accessors_helper_spec.rb
|
74
104
|
- spec/parsi-date/add_month_spec.rb
|
75
105
|
- spec/parsi-date/add_spec.rb
|
76
106
|
- spec/parsi-date/comp_spec.rb
|
@@ -108,6 +138,7 @@ specification_version: 4
|
|
108
138
|
summary: Solar Hijri (Jalali, Persian, Parsi) date library for Ruby
|
109
139
|
test_files:
|
110
140
|
- spec/parsi-date/accessor_spec.rb
|
141
|
+
- spec/parsi-date/accessors_helper_spec.rb
|
111
142
|
- spec/parsi-date/add_month_spec.rb
|
112
143
|
- spec/parsi-date/add_spec.rb
|
113
144
|
- spec/parsi-date/comp_spec.rb
|