datebox 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/datebox/period.rb +4 -1
- data/lib/datebox/relative.rb +3 -1
- data/lib/datebox/version.rb +1 -1
- data/test/unit/test_period.rb +1 -0
- data/test/unit/test_relative.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8f9797007395a67f85af5df4b2772f8cd19e261
|
4
|
+
data.tar.gz: bfe77be8897b4cd70ce2d84ca87c1c28843f034c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9adf391fdc13d71f26192c9ed439b904dbb4d306961fb42e4ca2e1aa019ecaf7087a8457fc60dcfc1c899c8560e0e9aa134158154e9c5f49c7f0f3700457474
|
7
|
+
data.tar.gz: 9636eb62528967d2052ecc8e5f1c3e86213d4e20f3799c6aac25c3219901a7820b6522a826bbcb852a75f7520ec2c504d876d8fc330545c4de6cdb8b40ca0dde
|
data/lib/datebox/period.rb
CHANGED
@@ -23,8 +23,11 @@ module Datebox
|
|
23
23
|
class << self
|
24
24
|
def split_dates(start_date, end_date, period, options = {})
|
25
25
|
return (start_date..end_date).to_a if period == "day"
|
26
|
-
return split_weekly_dates(start_date, end_date, options) if period == "week"
|
27
26
|
return split_monthly_dates(start_date, end_date) if period == "month"
|
27
|
+
if period =~ /week/
|
28
|
+
return split_weekly_dates(start_date, end_date, options.merge({last_weekday: "Saturday"})) if period == "week_ss"
|
29
|
+
return split_weekly_dates(start_date, end_date, options)
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
def split_weekly_dates(start_date, end_date, options = {})
|
data/lib/datebox/relative.rb
CHANGED
@@ -10,11 +10,13 @@ module Datebox
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def last(period)
|
13
|
-
periods = [:day, :week, :month, :year]
|
13
|
+
periods = [:day, :week, :week_ms, :week_ss, :month, :year] # week monday-sunday & week sunday-saturday
|
14
14
|
raise "Expected one of: #{periods}" unless periods.include?(period)
|
15
15
|
case period
|
16
16
|
when :day then day_before
|
17
17
|
when :week then last_week
|
18
|
+
when :week_ms then last_week
|
19
|
+
when :week_ss then last_week("Saturday")
|
18
20
|
when :month then last_month
|
19
21
|
when :year then last_year
|
20
22
|
end
|
data/lib/datebox/version.rb
CHANGED
data/test/unit/test_period.rb
CHANGED
@@ -10,6 +10,7 @@ class TestPeriod < Test::Unit::TestCase
|
|
10
10
|
assert_equal [], Datebox::Period.split_dates(Date.parse("2013-06-15"), Date.parse("2013-06-22"), "week") #sat to sat
|
11
11
|
assert_equal [Date.parse("2013-06-23")], Datebox::Period.split_dates(Date.parse("2013-06-14"), Date.parse("2013-06-27"), "week") #fri to thu
|
12
12
|
assert_equal [Date.parse("2013-06-23")], Datebox::Period.split_dates(Date.parse("2013-06-17"), Date.parse("2013-06-23"), "week") #mon to sun
|
13
|
+
assert_equal [Date.parse("2014-02-15")], Datebox::Period.split_dates(Date.parse("2014-02-09"), Date.parse("2014-02-15"), "week_ss") #sun to sat
|
13
14
|
assert_equal [Date.parse("2013-06-16"), Date.parse("2013-06-23")], Datebox::Period.split_dates(Date.parse("2013-06-10"), Date.parse("2013-06-27"), "week") #mon to thu
|
14
15
|
#month
|
15
16
|
assert_equal [], Datebox::Period.split_dates(Date.parse("2013-01-02"), Date.parse("2013-01-31"), "month")
|
data/test/unit/test_relative.rb
CHANGED
@@ -9,6 +9,7 @@ class TestRelative < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
# week
|
11
11
|
assert_equal Datebox::Period.new('2013-07-01', '2013-07-07'), Datebox::Relative.new.last_week.to('2013-07-09') #tue
|
12
|
+
assert_equal Datebox::Period.new('2013-06-30', '2013-07-06'), Datebox::Relative.new.last_week("Saturday").to('2013-07-09') #tue
|
12
13
|
assert_equal Datebox::Period.new('2013-07-01', '2013-07-05'), Datebox::Relative.new.last_weekdays_between("Monday", "Friday").to('2013-07-09') #tue
|
13
14
|
assert_equal Datebox::Period.new('2013-07-08', '2013-07-09'), Datebox::Relative.new.last_weekdays_between("Monday", "Tuesday").to('2013-07-09') #tue
|
14
15
|
|
@@ -23,6 +24,8 @@ class TestRelative < Test::Unit::TestCase
|
|
23
24
|
# anything
|
24
25
|
assert_equal Datebox::Period.new('2013-06-01', '2013-06-01'), Datebox::Relative.new.last(:day).to('2013-06-02')
|
25
26
|
assert_equal Datebox::Period.new('2013-06-01', '2013-06-30'), Datebox::Relative.new.last(:month).to('2013-07-09')
|
27
|
+
assert_equal Datebox::Period.new('2014-02-03', '2014-02-09'), Datebox::Relative.new.last(:week).to('2014-02-10')
|
28
|
+
assert_equal Datebox::Period.new('2014-02-02', '2014-02-08'), Datebox::Relative.new.last(:week_ss).to('2014-02-10')
|
26
29
|
|
27
30
|
# the one that's different
|
28
31
|
assert_equal [Date.parse('2013-07-01'), Date.parse('2013-07-03')], Datebox::Relative.new.last_weeks_weekdays_as!("Monday", "Wednesday").to('2013-07-05') #fri
|