datebox 0.3.0 → 0.4.1

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: 5ba421c57845a9e337de05fdd2d99cdcdba0c711
4
- data.tar.gz: 5b4a07576517473b413a7fdc22a34b99a84919fe
3
+ metadata.gz: 8973e5e78c939fdc2aed702c51b3569fc246db78
4
+ data.tar.gz: 824c632d4044104e6f9a996f11999352f4e8e397
5
5
  SHA512:
6
- metadata.gz: 88524a579dae051b9270608d25d7cf0a966e8ae3d76d44d5e623fbf2e51be63d79393abb56f07d125727610194ad9d5c41631b4361fcda0818e20396bd302860
7
- data.tar.gz: 364f4bddd066f02dc929c90ed528565ff1d04914d6c620507d52c14552e77cee31611ae17ee6f11c9a1dec7bd54503722d11399653815cca17347b2c4504ff15
6
+ metadata.gz: da95609365d0055017a0f9dbe807ae0179bddd0c8142f524c00fddc6babd03bf3d6d85a370eed12b45f5c8994e1aca2bd82f1265b9cf1cd080bfba09be82cd7b
7
+ data.tar.gz: e49e7a934141d7f3ba9d06000db5815792f42a7720d632595bc13dbf5187f956676a4c5e52ffc15e015beb8fd311ab03f497f6d96d30c003862bff8e764731dd
data/README.md CHANGED
@@ -27,6 +27,6 @@ Allows splitting periods (returns ending dates of periods)
27
27
  It's also possible to calculate periods relative to given dates
28
28
 
29
29
  period_month = Datebox::Relative.last_month.to('2013-07-09') # uses period method
30
- preiod_week = Datebox::Relative.last(:week).to('2013-07-09') # uses peiod symbol
30
+ preiod_week = Datebox::Relative.last(:week).to('2013-07-09') # uses period symbol
31
31
 
32
32
  It's best to have a look at code & tests
@@ -45,6 +45,25 @@ module Datebox
45
45
  new Proc.new {|relative_to| Period.new(relative_to - 1, relative_to - 1) }, __method__.to_s
46
46
  end
47
47
 
48
+ def day_apart(difference)
49
+ new Proc.new {|relative_to| Period.new(relative_to + difference, relative_to + difference) }, __method__.to_s
50
+ end
51
+
52
+ def method_missing(m, *args, &block)
53
+ if (m.to_s =~ /^day_ago_\d+$/) or (m.to_s =~ /^day_in_\d+$/)
54
+ days = m.to_s.split('_').last.to_i
55
+ if m.to_s =~ /^day_ago_\d+$/
56
+ return new Proc.new {|relative_to| Period.new(relative_to - days, relative_to - days) }, m
57
+ elsif m.to_s =~ /^day_in_\d+$/
58
+ return new Proc.new {|relative_to| Period.new(relative_to + days, relative_to + days) }, m
59
+ end
60
+ relative.send(:period_name, m)
61
+ return relative
62
+ else
63
+ super
64
+ end
65
+ end
66
+
48
67
  def last_n_days(options = {})
49
68
  days = (options[:days] || options['days']).to_i
50
69
  inclusive = (options[:exclusive] || options['exclusive']) ? false : true # inclusive by default
@@ -1,3 +1,3 @@
1
1
  module Datebox
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,11 +1,21 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestRelative < Test::Unit::TestCase
4
+
5
+ def test_gives_back_correct_period_name_in_proc
6
+ assert_equal :day_in_19, Datebox::Relative.day_in_19.period_name
7
+ end
4
8
 
5
9
  def test_calculates_correctly
6
10
  # day
7
11
  assert_equal [Date.parse('2013-07-07')], Datebox::Relative.same_day.to('2013-07-07').dates
8
12
  assert_equal [Date.parse('2013-07-06')], Datebox::Relative.day_before.to('2013-07-07').dates
13
+ assert_equal [Date.parse('2013-07-02')], Datebox::Relative.day_apart(1).to('2013-07-01').dates
14
+ assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_apart(-2).to('2013-08-05').dates
15
+ assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_apart(-2).to('2013-08-05').dates
16
+ assert_equal [Date.parse('2013-08-03')], Datebox::Relative.day_ago_2.to('2013-08-05').dates
17
+ assert_equal [Date.parse('2013-08-08')], Datebox::Relative.day_in_3.to('2013-08-05').dates
18
+ assert_equal [Date.parse('2013-08-20')], Datebox::Relative.day_in_19.to('2013-08-01').dates
9
19
 
10
20
  # n days
11
21
  assert_equal Datebox::Period.new('2014-06-01', '2014-06-30'), Datebox::Relative.last(:n_days, {:days => 30}).to('2014-06-30')
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.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Borkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Offers help with managing dates and periods
14
14
  email: