datebox 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +6 -0
- data/lib/datebox/relative.rb +7 -3
- data/lib/datebox/version.rb +1 -1
- data/test/unit/test_relative.rb +12 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6071a7b6da73c9da933aff8b600cacea6321752e
|
4
|
+
data.tar.gz: 631fb91950d16f1fc7b4c5627a01ea95019bec3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f423d81e2082ec4c9f6a0399916ae97bb4d1b7926096a95b2b0eaba66afc84b109f21886a8cdc3dd237a157237f440eeb58bbfc92161ddb1d318f21e6a56edc0
|
7
|
+
data.tar.gz: 574081389efcd498ab4b19af4933cc90863e51c2b9a9fb36b50efc491b244596ce38b2412256b0cadbbcfef624966a09b526c54b348506730f2a7894cd2b92c3
|
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.5.0
|
2
|
+
Changes to Relative
|
3
|
+
Change behaviour of last_n_days to return non-inclusive period of n days before provided
|
4
|
+
last_n_days :exclusive parameter is gone, :inclusive parameter replaces it. Returned result is not inclusive by default.
|
5
|
+
Introduced last_day for consistency (same as day_before)
|
6
|
+
|
1
7
|
0.4.3
|
2
8
|
Changed behaviour of last_week to be more consistent with other last_ methods particularly on Sunday
|
3
9
|
|
data/lib/datebox/relative.rb
CHANGED
@@ -19,7 +19,7 @@ module Datebox
|
|
19
19
|
def last(period, options = {})
|
20
20
|
raise "Expected one of: #{Period::PREDEFINED}" unless Period::PREDEFINED.include?(period.to_sym)
|
21
21
|
case period.to_sym
|
22
|
-
when :day then
|
22
|
+
when :day then last_day
|
23
23
|
when :n_days then last_n_days(options)
|
24
24
|
when :week then last_week(options)
|
25
25
|
when :month then last_month
|
@@ -41,10 +41,14 @@ module Datebox
|
|
41
41
|
new Proc.new {|relative_to| Period.new(relative_to, relative_to) }, __method__.to_s
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def last_day
|
45
45
|
new Proc.new {|relative_to| Period.new(relative_to - 1, relative_to - 1) }, __method__.to_s
|
46
46
|
end
|
47
47
|
|
48
|
+
# for backwards compatibility, we had only 'day_before' but last_day is more consistent with other calls
|
49
|
+
# @deprecated
|
50
|
+
def day_before; last_day; end
|
51
|
+
|
48
52
|
def day_apart(difference)
|
49
53
|
new Proc.new {|relative_to| Period.new(relative_to + difference, relative_to + difference) }, __method__.to_s
|
50
54
|
end
|
@@ -66,7 +70,7 @@ module Datebox
|
|
66
70
|
|
67
71
|
def last_n_days(options = {})
|
68
72
|
days = (options[:days] || options['days']).to_i
|
69
|
-
inclusive = (options[:
|
73
|
+
inclusive = (options[:inclusive] || options['inclusive']) ? true : false # NOT inclusive by default
|
70
74
|
days = 1 if days.nil? || days <= 0 # days should always > 0 since it only return last x days
|
71
75
|
proc = inclusive ?
|
72
76
|
Proc.new {|relative_to| Period.new(relative_to - days + 1, relative_to) } :
|
data/lib/datebox/version.rb
CHANGED
data/test/unit/test_relative.rb
CHANGED
@@ -10,16 +10,20 @@ class TestRelative < Test::Unit::TestCase
|
|
10
10
|
# day
|
11
11
|
assert_equal [Date.parse('2013-07-07')], Datebox::Relative.same_day.to('2013-07-07').dates
|
12
12
|
assert_equal [Date.parse('2013-07-06')], Datebox::Relative.day_before.to('2013-07-07').dates
|
13
|
+
assert_equal [Date.parse('2013-07-06')], Datebox::Relative.last_day.to('2013-07-07').dates
|
13
14
|
assert_equal [Date.parse('2013-07-02')], Datebox::Relative.day_apart(1).to('2013-07-01').dates
|
14
15
|
assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_apart(-2).to('2013-08-05').dates
|
15
16
|
assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_apart(-2).to('2013-08-05').dates
|
16
17
|
assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_ago_2.to('2013-08-05').dates
|
17
18
|
assert_equal [Date.parse('2013-08-08')], Datebox::Relative.day_in_3.to('2013-08-05').dates
|
18
19
|
assert_equal [Date.parse('2013-08-20')], Datebox::Relative.day_in_19.to('2013-08-01').dates
|
20
|
+
|
21
|
+
assert_equal Datebox::Period.new('2017-12-24', '2017-12-30'), Datebox::Relative.last_n_days({'days' => 7}).to('2017-12-31')
|
22
|
+
assert_equal Datebox::Period.new('2017-12-25', '2017-12-31'), Datebox::Relative.last_n_days({'days' => 7, 'inclusive' => true}).to('2017-12-31')
|
19
23
|
|
20
24
|
# n days
|
21
|
-
assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {:
|
22
|
-
assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {days: 30
|
25
|
+
assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {days: 30, inclusive: true}).to('2014-06-30')
|
26
|
+
assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {days: 30}).to('2014-07-01')
|
23
27
|
|
24
28
|
# week
|
25
29
|
assert_equal Datebox::Period.new('2013-07-01', '2013-07-07'), Datebox::Relative.last_week.to('2013-07-09') # tue
|
@@ -43,22 +47,23 @@ class TestRelative < Test::Unit::TestCase
|
|
43
47
|
assert_equal Datebox::Period.new('2014-02-03', '2014-02-09'), Datebox::Relative.last(:week).to('2014-02-10')
|
44
48
|
assert_equal Datebox::Period.new('2014-02-02', '2014-02-08'), Datebox::Relative.last(:week, {:last_weekday => "Saturday"}).to('2014-02-10')
|
45
49
|
|
46
|
-
#
|
50
|
+
# anything, up to date
|
47
51
|
assert_equal Datebox::Period.new('2015-03-15', '2015-03-21'), Datebox::Relative.to_date(:week, {:last_weekday => "Saturday"}).to('2015-03-21')
|
48
52
|
assert_equal Datebox::Period.new('2015-03-15', '2015-03-20'), Datebox::Relative.to_date(:week, {:last_weekday => "Saturday"}).to('2015-03-20')
|
53
|
+
assert_equal Datebox::Period.new('2015-03-16', '2015-03-20'), Datebox::Relative.to_date(:week, {:last_weekday => "Sunday"}).to('2015-03-20')
|
49
54
|
assert_equal Datebox::Period.new('2015-03-01', '2015-03-20'), Datebox::Relative.to_date(:month).to('2015-03-20')
|
50
55
|
assert_equal Datebox::Period.new('2015-01-01', '2015-03-20'), Datebox::Relative.to_date(:year).to('2015-03-20')
|
51
56
|
assert_equal Datebox::Period.new('2015-01-01', '2015-03-20'), Datebox::Relative.year_to_date.to('2015-03-20')
|
52
57
|
|
53
|
-
# the one that's different
|
54
|
-
assert_equal [Date.parse('2013-07-01'), Date.parse('2013-07-03')], Datebox::Relative.last_weeks_weekdays_as!("Monday", "Wednesday").to('2013-07-05') #fri
|
55
|
-
|
56
58
|
assert_equal Datebox::Period.new('2015-11-02', '2015-11-08'), Datebox::Relative.same_week.to('2015-11-02') # mon
|
57
59
|
assert_equal Datebox::Period.new('2015-11-02', '2015-11-08'), Datebox::Relative.same_week.to('2015-11-03') # tue
|
58
60
|
assert_equal Datebox::Period.new('2015-11-02', '2015-11-08'), Datebox::Relative.same_week.to('2015-11-08') # sun
|
59
|
-
|
61
|
+
assert_equal Datebox::Period.new('2015-11-01', '2015-11-07'), Datebox::Relative.same_week(last_weekday: 'Saturday').to('2015-11-07') # sat
|
60
62
|
|
61
63
|
assert_equal Datebox::Period.new('2015-11-01', '2015-11-30'), Datebox::Relative.same_month.to('2015-11-30')
|
64
|
+
|
65
|
+
# the one method that's different (does not return period but array)
|
66
|
+
assert_equal [Date.parse('2013-07-01'), Date.parse('2013-07-03')], Datebox::Relative.last_weeks_weekdays_as!("Monday", "Wednesday").to('2013-07-05') #fri
|
62
67
|
end
|
63
68
|
|
64
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Borkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Offers help with managing dates and periods
|
14
14
|
email:
|