datebox 0.0.3 → 0.0.4

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: 534c7045625091172d8375d28ad40df3da50fda6
4
- data.tar.gz: ff7ce2e3dca7fb342c1427b68d0e16f66b0ba7ab
3
+ metadata.gz: a8f9797007395a67f85af5df4b2772f8cd19e261
4
+ data.tar.gz: bfe77be8897b4cd70ce2d84ca87c1c28843f034c
5
5
  SHA512:
6
- metadata.gz: 1780507857dd3e510748945757e95b5231280f786b0d3060c372369497e426bd5743599b1b5ad2f85d3d196a9a7fc1a995bfd6af6591e9414884c64d4af3d6d9
7
- data.tar.gz: 045aa40f4ab00fab930882380dd2ac16651fb72dace765a128fee17e10067627ea5c7c0129baef20bc4147d3429b065487a6ce924f212a4d49937ed83706da4a
6
+ metadata.gz: c9adf391fdc13d71f26192c9ed439b904dbb4d306961fb42e4ca2e1aa019ecaf7087a8457fc60dcfc1c899c8560e0e9aa134158154e9c5f49c7f0f3700457474
7
+ data.tar.gz: 9636eb62528967d2052ecc8e5f1c3e86213d4e20f3799c6aac25c3219901a7820b6522a826bbcb852a75f7520ec2c504d876d8fc330545c4de6cdb8b40ca0dde
@@ -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 = {})
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Datebox
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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")
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Borkowski