diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6185834..484dcf0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.3.3
+
+* Add current? to check if the period containts the current date.
+
+ *Edwin Vlieg*
+
## 0.3.2
* Add this_month?, this_quarter? and this_year? to check if a period is the current month, quarter or year
diff --git a/lib/active_date_range/date_range.rb b/lib/active_date_range/date_range.rb
index 6b99560..cb8a635 100644
--- a/lib/active_date_range/date_range.rb
+++ b/lib/active_date_range/date_range.rb
@@ -232,26 +232,15 @@ def same_year?
end
end
- # Return true when the range is equal to the current month
- def this_month?
- memoize(:@this_month) do
- self == DateRange.this_month
+ def current?
+ memoize(:@current) do
+ cover?(Time.zone.today)
end
end
- # Return true when the range is equal to the current quarter
- def this_quarter?
- memoize(:@this_quarter) do
- self == DateRange.this_quarter
- end
- end
-
- # Return true when the range is equal to the current year
- def this_year?
- memoize(:@this_year) do
- self == DateRange.this_year
- end
- end
+ alias :this_month? :current?
+ alias :this_quarter? :current?
+ alias :this_year? :current?
# Returns true when the date range is before the given date. Accepts both a Date
# and DateRange as input.
diff --git a/test/active_date_range/date_range_test.rb b/test/active_date_range/date_range_test.rb
index 4b94fdf..bc61192 100644
--- a/test/active_date_range/date_range_test.rb
+++ b/test/active_date_range/date_range_test.rb
@@ -193,6 +193,18 @@ def test_same_year
assert_not described_class.parse("202001..202112").same_year?
end
+ def test_current
+ assert described_class.this_month.current?
+ assert described_class.this_quarter.current?
+ assert described_class.this_year.current?
+ assert_not described_class.prev_month.current?
+ assert_not described_class.prev_quarter.current?
+ assert_not described_class.prev_year.current?
+ assert_not described_class.next_month.current?
+ assert_not described_class.next_quarter.current?
+ assert_not described_class.next_year.current?
+ end
+
def test_this_month
assert described_class.this_month.this_month?
assert_not described_class.prev_month.this_month?