Skip to content

Instantly share code, notes, and snippets.

@bjhess
Created December 9, 2008 18:49
Show Gist options
  • Save bjhess/34028 to your computer and use it in GitHub Desktop.
Save bjhess/34028 to your computer and use it in GitHub Desktop.
# When I want to get beginning of day in the time zone set for
# the request, not the local machine's time zone.
class ::Date
def beginning_of_day_in_zone
Time.zone.parse(self.to_s)
end
alias_method :at_beginning_of_day_in_zone, :beginning_of_day_in_zone
alias_method :midnight_in_zone, :beginning_of_day_in_zone
alias_method :at_midnight_in_zone, :beginning_of_day_in_zone
def end_of_day_in_zone
Time.zone.parse((self+1).to_s) - 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment