datebox 0.4.3 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f867ee46d817fd7925ee67d2b7da65c77e9a0b3d
4
- data.tar.gz: 765f0d7e2873bd6196baa5d2215e1c0128796f84
3
+ metadata.gz: 6071a7b6da73c9da933aff8b600cacea6321752e
4
+ data.tar.gz: 631fb91950d16f1fc7b4c5627a01ea95019bec3c
5
5
  SHA512:
6
- metadata.gz: 1ea5e6dc0cb49ac0ba631177595f1a20b84c32d2f726f0a5abfa79377f40158dcb83b92a5ff8eaadbc5ceb42f2a88c081419ebd3b13af3c9807568137b91e76d
7
- data.tar.gz: 404b27cd4d7d1938ae8cc47e3df2bb6e57b8ea52a3a690b3af79f865ab8b51d6758c97cf960cc521d033e4e1e98ad7acb039cb946af5f613730049d58588c048
6
+ metadata.gz: f423d81e2082ec4c9f6a0399916ae97bb4d1b7926096a95b2b0eaba66afc84b109f21886a8cdc3dd237a157237f440eeb58bbfc92161ddb1d318f21e6a56edc0
7
+ data.tar.gz: 574081389efcd498ab4b19af4933cc90863e51c2b9a9fb36b50efc491b244596ce38b2412256b0cadbbcfef624966a09b526c54b348506730f2a7894cd2b92c3
@@ -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
 
@@ -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 day_before
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 day_before
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[:exclusive] || options['exclusive']) ? false : true # inclusive by default
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) } :
@@ -1,3 +1,3 @@
1
1
  module Datebox
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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, {:days => 30}).to('2014-06-30')
22
- assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {days: 30, exclusive: true}).to('2014-07-01')
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
- # andything, up to date
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.3
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: 2017-09-12 00:00:00.000000000 Z
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: