pseudo_date 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pseudo_date/pseudo_date.rb +58 -0
- data/pseudo_date.gemspec +1 -1
- metadata +3 -3
@@ -38,10 +38,16 @@ class PseudoDate
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# =====================
|
42
|
+
# = Boolean Questions =
|
43
|
+
# =====================
|
41
44
|
def valid?
|
42
45
|
!(@date_hash.nil? || @date_hash.empty?)
|
43
46
|
end
|
44
47
|
|
48
|
+
# ====================
|
49
|
+
# = Export Functions =
|
50
|
+
# ====================
|
45
51
|
def to_date
|
46
52
|
self.valid? ? Date.parse("#{@year}-#{@month}-#{@day}") : nil rescue nil
|
47
53
|
end
|
@@ -63,6 +69,58 @@ class PseudoDate
|
|
63
69
|
@date_hash
|
64
70
|
end
|
65
71
|
|
72
|
+
# ========================
|
73
|
+
# = Comparison Operators =
|
74
|
+
# ========================
|
75
|
+
def <(other)
|
76
|
+
case self.comparison_mode(other)
|
77
|
+
when 'exact'
|
78
|
+
self.to_date < other.to_date
|
79
|
+
when 'year_month'
|
80
|
+
self.year == other.year ? (self.month < other.month) : (self.year < other.year)
|
81
|
+
when 'year'
|
82
|
+
self.year < other.year
|
83
|
+
when 'mixed'
|
84
|
+
if self.precision == 'invalid'
|
85
|
+
true
|
86
|
+
elsif other.precision == 'invalid'
|
87
|
+
false
|
88
|
+
elsif self.year == other.year
|
89
|
+
if self.month == other.month
|
90
|
+
self.day.to_i < other.day.to_i
|
91
|
+
else
|
92
|
+
self.month < other.month
|
93
|
+
end
|
94
|
+
else
|
95
|
+
self.year < other.year
|
96
|
+
end
|
97
|
+
else
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def >(other)
|
103
|
+
other < self
|
104
|
+
end
|
105
|
+
|
106
|
+
def ==(other)
|
107
|
+
(self.year == other.year) && (self.month == other.month) && (self.day == other.day)
|
108
|
+
end
|
109
|
+
|
110
|
+
def <=>(other)
|
111
|
+
self == other ? 0 : (self < other ? -1 : 1)
|
112
|
+
end
|
113
|
+
|
114
|
+
protected
|
115
|
+
|
116
|
+
def comparison_mode(other)
|
117
|
+
if self.precision == other.precision
|
118
|
+
self.precision
|
119
|
+
else
|
120
|
+
'mixed'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
66
124
|
private
|
67
125
|
|
68
126
|
def correct_digits
|
data/pseudo_date.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pseudo_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Tulskie
|