timetastic 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/timetastic.rb +15 -1
  2. metadata +2 -2
data/lib/timetastic.rb CHANGED
@@ -21,6 +21,14 @@ module Timetastic
21
21
  Traveller.new(1, 0)
22
22
  end
23
23
 
24
+ def days_between(b, e)
25
+ (e.to_i - b.to_i) / 60 / 60 / 24
26
+ end
27
+ def days_and_months_between(b, e)
28
+ t = Time.at(e.to_i - b.to_i)
29
+ [ t.day, t.month ]
30
+ end
31
+
24
32
  alias_method :coming, :next
25
33
 
26
34
  # Fixes the relative time by which all of Timetastic operations
@@ -65,7 +73,7 @@ module Timetastic
65
73
 
66
74
  def initialize(direction, distance, relative_to = nil)
67
75
  @distance = distance.to_i
68
- @relative_to = relative_to
76
+ @relative_to = relative_to || Timetastic.now
69
77
  @direction = case direction
70
78
  when -1; :ago
71
79
  when 1; :hence
@@ -80,6 +88,12 @@ module Timetastic
80
88
  protected
81
89
 
82
90
  def relative_anchored_time(domain)
91
+ if domain == :months
92
+ if @relative_to.day < 3
93
+ @relative_to = Time.new(@relative_to.year, @relative_to.month, @relative_to.day + 3)
94
+ end
95
+ end
96
+
83
97
  t = @distance.send(domain).send(@direction, @relative_to)
84
98
 
85
99
  case domain
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.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-12-28 00:00:00.000000000 Z
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec