datebox 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ee3f21eef1adfc455da526dbbfd037f2b17e1d9
4
- data.tar.gz: 2760bf9e09bf08a526df3622eeab16f3ada22247
3
+ metadata.gz: 534c7045625091172d8375d28ad40df3da50fda6
4
+ data.tar.gz: ff7ce2e3dca7fb342c1427b68d0e16f66b0ba7ab
5
5
  SHA512:
6
- metadata.gz: 3cc78e68d9eacec4962e39137bd17df8d64156e2dc888b1a99e9c8f1da20d5742cef5f5a27de94ca43798da466a623836afc38e1853cff4fed8e053d7a6b5d53
7
- data.tar.gz: 15c4049a449cf389c75adf6c41d2ce17583effb1a12720dc5b6fa7caa685ca4469ad8e13302129c70749c04ee10e80d5b8ae44c5256f6a3af917f509cb1529a6
6
+ metadata.gz: 1780507857dd3e510748945757e95b5231280f786b0d3060c372369497e426bd5743599b1b5ad2f85d3d196a9a7fc1a995bfd6af6591e9414884c64d4af3d6d9
7
+ data.tar.gz: 045aa40f4ab00fab930882380dd2ac16651fb72dace765a128fee17e10067627ea5c7c0129baef20bc4147d3429b065487a6ce924f212a4d49937ed83706da4a
@@ -8,12 +8,28 @@ module Datebox
8
8
  relative_to = (relative_to.is_a?(Date) ? relative_to : Date.parse(relative_to))
9
9
  @period_proc.call relative_to
10
10
  end
11
+
12
+ def last(period)
13
+ periods = [:day, :week, :month, :year]
14
+ raise "Expected one of: #{periods}" unless periods.include?(period)
15
+ case period
16
+ when :day then day_before
17
+ when :week then last_week
18
+ when :month then last_month
19
+ when :year then last_year
20
+ end
21
+ end
11
22
 
12
23
  def same_day
13
24
  @period_proc = Proc.new {|relative_to| Period.new(relative_to, relative_to) }
14
25
  self
15
26
  end
16
27
 
28
+ def day_before
29
+ @period_proc = Proc.new {|relative_to| Period.new(relative_to - 1, relative_to - 1) }
30
+ self
31
+ end
32
+
17
33
  def last_week(last_weekday = "Sunday")
18
34
  @period_proc = Proc.new do |relative_to|
19
35
  end_date = (relative_to.downto relative_to - 6).to_a.find { |d| d.strftime("%A") == last_weekday }
@@ -1,3 +1,3 @@
1
1
  module Datebox
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,4 @@
1
- require '../test_helper'
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestPeriod < Test::Unit::TestCase
4
4
 
@@ -1,21 +1,29 @@
1
- require '../test_helper'
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestRelative < Test::Unit::TestCase
4
4
 
5
5
  def test_calculates_correctly
6
6
  # day
7
7
  assert_equal [Date.parse('2013-07-07')], Datebox::Relative.new.same_day.to('2013-07-07').dates
8
+ assert_equal [Date.parse('2013-07-06')], Datebox::Relative.new.day_before.to('2013-07-07').dates
9
+
8
10
  # week
9
11
  assert_equal Datebox::Period.new('2013-07-01', '2013-07-07'), Datebox::Relative.new.last_week.to('2013-07-09') #tue
10
12
  assert_equal Datebox::Period.new('2013-07-01', '2013-07-05'), Datebox::Relative.new.last_weekdays_between("Monday", "Friday").to('2013-07-09') #tue
11
13
  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
+
12
15
  # month
13
16
  assert_equal Datebox::Period.new('2013-06-01', '2013-06-30'), Datebox::Relative.new.last_month.to('2013-07-09')
14
17
  assert_equal Datebox::Period.new('2013-07-01', '2013-07-09'), Datebox::Relative.new.month_to_date.to('2013-07-09')
18
+
15
19
  # year
16
20
  assert_equal Datebox::Period.new('2012-01-01', '2012-12-31'), Datebox::Relative.new.last_year.to('2013-07-09')
17
21
  assert_equal Datebox::Period.new('2013-01-01', '2013-07-09'), Datebox::Relative.new.year_to_date.to('2013-07-09')
18
22
 
23
+ # anything
24
+ assert_equal Datebox::Period.new('2013-06-01', '2013-06-01'), Datebox::Relative.new.last(:day).to('2013-06-02')
25
+ assert_equal Datebox::Period.new('2013-06-01', '2013-06-30'), Datebox::Relative.new.last(:month).to('2013-07-09')
26
+
19
27
  # the one that's different
20
28
  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
21
29
  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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Borkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Offers help with managing dates and periods
14
14
  email: