Class: Remistify

Inherits:
Object
  • Object
show all
Defined in:
lib/remistify.rb

Class Method Summary collapse

Class Method Details

.expiration(remiss, issues, cycle, from = nil, tz = nil) ⇒ DateTime

Calculates expiration based on remiss

Parameters:

  • remiss (integer)

    number of remaining issues to fulfill

  • issues (integer)

    issues per cycle

  • cycle (integer)

    integer value of time measurement for duration of subscription cycle (T_1_YEAR)

  • from (String) (defaults to: nil)

    specify a starting point in time

Returns:

  • (DateTime)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/remistify.rb', line 9

def self.expiration(remiss, issues, cycle, from=nil, tz=nil)
   seconds_per_cycle = cycle.to_i / issues.to_i
   expiration = nil
   if from
      expiration = DateTime.parse(from).to_time
   else
      expiration = Time.now
      if tz
         expiration = expiration.in_time_zone(tz)
      end #/if
   end #/if-else

   range = (1..remiss)
   if remiss <= 0
      range = (remiss..-1) # ignore 0
   end#/if

   range.each do |i|
      if remiss >= 1
         expiration = expiration + seconds_per_cycle
      else
         expiration = expiration - seconds_per_cycle
      end #/if-else
   end #/each
   
   return expiration
end