fortnight 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,30 +18,6 @@ Add in the models that we want to use
18
18
 
19
19
  include Fortnight
20
20
 
21
- ## Usage
22
-
23
- It's very simple, the syntax is the next:
24
-
25
- Model.in_fortnight(year, month, options)
26
-
27
- 'options' for now are only :field and :half
28
- :field ALWAYS HAVE TO BE A TIME FIELD
29
- :half is to get the first (by default) or the second (as symbol)
30
-
31
- ## Examples
32
-
33
- Customer.in_fortnight(2012, 04)
34
- We'll get the customers created_at between 2012-04-01 00:00 AND 2012-04-15 23:59:59
35
-
36
- Customer.in_fortnight(2012, 04, half: :second)
37
- We'll get the customers created_at between 2012-04-15 23:59:59 AND 2012-04-30 23:59:59
38
-
39
- Customer.in_fortnight(2012, 05, half: :second)
40
- We'll get the customers created_at between 2012-05-15 23:59:59 AND 2012-05-31 23:59:59
41
-
42
- Customer.in_fortnight(2012, 04, field: 'updated_at')
43
- We'll get the customers updated_at between 2012-04-01 00:00 AND 2012-04-15 23:59
44
-
45
- Customer.in_fortnight(2012, 04, half: :second, field: 'updated_at')
46
- We'll get the customers updated_at between 2012-04-15 23:59:59 AND 2012-04-30 23:59:59
21
+ ## Methods Wiki
22
+ See the wiki page for the methods details
47
23
 
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require "bundler/gem_tasks"
@@ -5,24 +5,53 @@ module Fortnight
5
5
  def self.included(base)
6
6
  base.extend ClassMethods
7
7
  end
8
-
8
+
9
9
  module ClassMethods
10
10
  def in_fortnight(year, month, options={})
11
11
 
12
12
  begin_of_month = Time.new(year, month)
13
- half_of_month = begin_of_month.advance(days: 14).end_of_day
13
+ half_month = begin_of_month.advance(days: 14).end_of_day
14
14
  final_of_month = begin_of_month.end_of_month.end_of_day
15
15
 
16
- start = options[:half] == :second ? half_of_month : begin_of_month
17
- finish = options[:half] == :second ? final_of_month : half_of_month
16
+ start = options[:half] == :second ? half_month : begin_of_month
17
+ finish = options[:half] == :second ? final_of_month : half_month
18
18
 
19
19
  field = options[:field] || 'created_at'
20
20
 
21
21
  scope = where("#{field} >= :s AND #{field} <= :f", s: start, f: finish)
22
22
  scope = scope.order(options[:order]) if options[:order]
23
+
23
24
  scope
24
25
  end
26
+
27
+ def last_fortnight
28
+ today = Date.today
29
+ date = today - 15.days
30
+
31
+ if today.day >= 1 && today.day <= 15
32
+ self.in_fortnight(date.year, date.month, half: :second)
33
+ else
34
+ self.in_fortnight(date.year, date.month)
35
+ end
36
+ end
37
+ end
38
+
39
+ def fortnight_in_words
40
+ date = self.created_at.to_date
41
+ month_begin = date.beginning_of_month
42
+ half_month = month_begin.advance(days: 14)
43
+
44
+ if date.day >= 1 && date.day <=15
45
+ output = I18n.l(month_begin, format: :long)
46
+ output << ' - '
47
+ output << I18n.l(half_month.to_date, format: :long)
48
+ else
49
+ output = I18n.l((half_month + 1.day).to_date, format: :long)
50
+ output << ' - '
51
+ output << I18n.l(date.end_of_month, format: :long)
52
+ end
53
+
54
+ output
25
55
  end
26
56
  end
27
57
 
28
-
@@ -1,3 +1,3 @@
1
1
  module Fortnight
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortnight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails