Skip to content

Commit

Permalink
Removed some redundant Time#change time options from beginning_of_ me…
Browse files Browse the repository at this point in the history
…thods in Date and Time
  • Loading branch information
farski committed Mar 14, 2011
1 parent dfa9e28 commit 377bd69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def next_week(day = :monday)


# Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00) # Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)
def beginning_of_month def beginning_of_month
self.acts_like?(:time) ? change(:day => 1,:hour => 0, :min => 0, :sec => 0) : change(:day => 1) self.acts_like?(:time) ? change(:day => 1, :hour => 0) : change(:day => 1)
end end
alias :at_beginning_of_month :beginning_of_month alias :at_beginning_of_month :beginning_of_month


Expand All @@ -231,13 +231,13 @@ def end_of_quarter


# Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00) # Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00)
def beginning_of_year def beginning_of_year
self.acts_like?(:time) ? change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0) : change(:month => 1, :day => 1) self.acts_like?(:time) ? change(:month => 1, :day => 1, :hour => 0) : change(:month => 1, :day => 1)
end end
alias :at_beginning_of_year :beginning_of_year alias :at_beginning_of_year :beginning_of_year


# Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59) # Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59)
def end_of_year def end_of_year
self.acts_like?(:time) ? change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59) : change(:month => 12, :day => 31) self.acts_like?(:time) ? change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59) : change(:month => 12, :day => 31)
end end
alias :at_end_of_year :end_of_year alias :at_end_of_year :end_of_year


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def next_week(day = :monday)
# Returns a new Time representing the start of the day (0:00) # Returns a new Time representing the start of the day (0:00)
def beginning_of_day def beginning_of_day
#(self - seconds_since_midnight).change(:usec => 0) #(self - seconds_since_midnight).change(:usec => 0)
change(:hour => 0, :min => 0, :sec => 0, :usec => 0) change(:hour => 0)
end end
alias :midnight :beginning_of_day alias :midnight :beginning_of_day
alias :at_midnight :beginning_of_day alias :at_midnight :beginning_of_day
Expand All @@ -201,7 +201,7 @@ def end_of_day
# Returns a new Time representing the start of the month (1st of the month, 0:00) # Returns a new Time representing the start of the month (1st of the month, 0:00)
def beginning_of_month def beginning_of_month
#self - ((self.mday-1).days + self.seconds_since_midnight) #self - ((self.mday-1).days + self.seconds_since_midnight)
change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0) change(:day => 1, :hour => 0)
end end
alias :at_beginning_of_month :beginning_of_month alias :at_beginning_of_month :beginning_of_month


Expand All @@ -227,7 +227,7 @@ def end_of_quarter


# Returns a new Time representing the start of the year (1st of january, 0:00) # Returns a new Time representing the start of the year (1st of january, 0:00)
def beginning_of_year def beginning_of_year
change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0, :usec => 0) change(:month => 1, :day => 1, :hour => 0)
end end
alias :at_beginning_of_year :beginning_of_year alias :at_beginning_of_year :beginning_of_year


Expand Down

0 comments on commit 377bd69

Please sign in to comment.