lib/timespan.rb in timespan-0.5.1 vs lib/timespan.rb in timespan-0.5.2
- old
+ new
@@ -41,13 +41,13 @@
attr_reader :start_time, :end_time
alias_method :start_date, :start_time
alias_method :end_date, :end_time
- START_KEYS = [:start, :from, :start_date]
- END_KEYS = [:to, :end, :end_date]
- DURATION_KEYS = [:duration, :lasting]
+ START_KEYS = [:start, :from, :start_date, :start_time, :start_from, :starting]
+ END_KEYS = [:to, :end, :end_date, :end_at, :ending]
+ DURATION_KEYS = [:duration, :lasting, :"for"]
ALL_KEYS = START_KEYS + END_KEYS + DURATION_KEYS
def initialize options = {}
@is_new = true
@@ -64,10 +64,18 @@
configure! options
@is_new = false
end
+ def asap!
+ @asap = true
+ end
+
+ def asap= value
+ @asap = !!value
+ end
+
class << self
def max_date
@max_date ||= Time.now + 10.years
end
@@ -86,12 +94,14 @@
def asap options = {}
self.new options.merge(asap: true)
end
def from start, duration, options = {}
+ asap = false
start = case start.to_sym
when :now, :asap
+ asap = true
Time.now
when :today
Date.today
when :tomorrow
Date.today + 1.day
@@ -103,11 +113,11 @@
options[:start] ? date.at_beginning_of_month.next_month : date
else
start
end
- self.new start_date: start, duration: duration
+ self.new start_date: start, duration: duration, asap: asap
end
def untill ending
ending = case ending.to_sym
when :tomorrow
@@ -156,14 +166,14 @@
end
end
alias_method :end_date=, :end_time=
def asap?
- @asap
+ !!@asap
end
def min
- asap ? Time.now : start_time
+ asap? ? Time.now : start_time
end
def max
end_time
end
\ No newline at end of file