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 340115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:35:10+00:00 2026-05-12T10:35:10+00:00

I have all the time zone information that is needed and it saves all

  • 0

I have all the time zone information that is needed and it saves all of the information correctly according to this railscast. Everything works great for all the normal purposes like displaying time’s in a table, however I am wondering how I can convert the following to the current_users saved time zone.

I have a finds the total number of calls hourly:

Calls.count(:group => DATE_PART('hour', start_time), 
            :conditions => ["start_time BETWEEN ? AND ?", start, finish]

This query pulls in all all the calls that were made in an hour between the start and finish time. The only thing is that it’s pulling back the time in the database which is stored as UTC. I wrote my own little conversion method with Time.now.utc_offset but realized that wouldn’t work. What would be a good way to compare the users saved time_zone with what is coming down from the database and add the utc_offset.

The time_zone is stored as a string in the database Eastern Time (US & Canada).

What is the best way of figuring this out, I can change to save the user’s offset in the database but before I go do that I would rather see if there is an easier way.

Edit
To be more clear, the query returns a hash of hours and the count. So for example:

                Hour                       Count
                "5"                          20
                "6"                          15
                "7"                          35
                ...                          ...

The hour is coming back as a UTC offset hour, I need to convert that digit to the users time zone, so for example, if it’s Eastern Time (US and Canada) you loop through the hash and add -4 to the hour.

Edit 2
Thanks to Andy I was able to figure this out pretty simply. The first thing you want to do is set the Time object to the current users Time zone. So:

Time.zone = @current_user.time_zone
=> "Eastern Time (US & Canada)

Then Add the current user’s offset to the “Hour” inside the hash

hour + Time.now.in_time_zone.utc_offset / 3600

Pretty self explanatory, but that gets the time of the zone you set earlier, and finds the UTC offset in seconds which is why we divide by 3600.

  • 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-05-12T10:35:10+00:00Added an answer on May 12, 2026 at 10:35 am

    Does this help?

    t = TimeZone["Eastern Time (US & Canada)"]
    t.utc_to_local(DateTime.now) #gives the local time
    

    Whoever posted before me deleted his answer (it was much better than my answer). If he brings his answer back I’ll take mine down again.

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

Sidebar

Related Questions

I have a client request that all times be displayed in Pacific Time Zone,
I have a query now that shows me all the calls between this time,
How do I validate that all 'signedWhen' xml attributes should not have time zone
I have a time interval that spans years and I want all the time
I have a variable that's being changed all the time in the course of
I have a spreadsheet I'm using to compile text that changes all the time.
it is very strange, because this error doesn't happen all the time... I have
I have been using attachment_fu on a project for a long time and all
In Excel, let's say I have 5 columns, but not all of the time
I have a jQuery autocomplete input box for time. It lists all available times

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.