Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:49:48+00:00 2026-06-11T21:49:48+00:00

My date methods aren’t working correctly on Heroku. I created a user that goes

  • 0

My date methods aren’t working correctly on Heroku. I created a user that goes by the (GMT-05:00) Eastern Time (US & Canada) and is suppose to see products added based on the date attribute it has. So it suppose to say Added 1 Product Today but it’s as if it’s the methods themselves are recording by the day before. So today is actually yesterday and yesterday is actually the day after yesterday.

Here are my methods:

  def self.today
    where(:date => Date.today)
  end

  def self.yesterday
    where(:date => Date.yesterday)
  end

  def self.this_week
    where(:date => Date.today.beginning_of_week..Date.today.end_of_week)
  end

  def self.last_week
    where(:date => 1.week.ago.beginning_of_week..1.week.ago.end_of_week)
  end

  def self.this_month
    where(:date => Date.today.beginning_of_month..Date.today.end_of_month)
  end

  def self.last_month
    where(:date => 1.month.ago.beginning_of_month..1.month.ago.end_of_month).order('date desc')
  end

So I guess it’s always -1 day for every method on Heroku but not in development. Heroku’s Time zone and Time are:

Loading production environment (Rails 3.2.8)
irb(main):001:0> Time.now
Time.now
=> 2012-09-21 02:37:26 +0000
irb(main):002:0> Time.zone
Time.zone
=> (GMT+00:00) UTC

This is wrong for me since it’s 2012-09-20 in the US East.

I want to have the methods work for every Timezone, not just Eastern Timezone so what should I do about this? How can I get a user to see the products they’ve added based on their Timezone?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:49:50+00:00Added an answer on June 11, 2026 at 9:49 pm

    Well, if you wanted one time zone globally, the easiest way to do that is to heroku config:set TZ to some suitable value. That covers everything from libc on up.

    However, user-specific time zones means you need to change the time zone within the context of each request. “Each request” should immediately make you think “in the controller”.

    It turns out that Rails (specifically, ActionSupport) makes provisions for this with Time.zone=. It also just so happens that this is common enough that the zone= documentation includes sample code specifically for this scenario:

    class ApplicationController < ActionController::Base
      around_filter :set_time_zone
    
      def set_time_zone
        old_time_zone = Time.zone
        Time.zone = current_user.time_zone if logged_in?
        yield
      ensure
        Time.zone = old_time_zone
      end
    end
    

    Also, if you can’t get users to select their time zone from a list, you can guess based on the time zone offset detected in JavaScript. It’s better than nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, i'm coding some methods for returning solr docs that mach a interval date
I have noticed that numerous Date methods in Java have been deprecated, but rather
I have methods in all of my models that look like this: def formatted_start_date
The java.util.Date toString() method displays the date in the local time zone. There are
Given that Date has a method called after(Date) and Timestamp has a method the
I've got an ATL method that takes a DATE type, which is really a
Can anyone suggest an easy method to convert date and time to different timezones
I have created a new route like the following: routes.MapRoute( BlogYMD, blog/date/{year}/{month}/{day}, new {
Working on an ASP.NET 4.0 project, which uses user controls to dynamically generate a
We have some Materialized views in our Oracle 9i database that were created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.