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

  • SEARCH
  • Home
  • 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 8371021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:03:40+00:00 2026-06-09T14:03:40+00:00

I create multiple scheduled objects with different scheduled_on attributes. For example, each object would

  • 0

I create multiple scheduled objects with different scheduled_on attributes. For example, each object would have a date to land on 4:00pm the first of every month.

Once one of those objects hits a timezone change. The app intelligently configures it an hour ahead or behind so that its relative to its parent’s timezone.

The problem is that the app will save an object as 4:00PM (in Pacific Standard) for times that will eventually be displayed as (PDT or an hour ahead or 5:00pm). This would mean that I need it to save an hour off in UTC so that when the time comes about, it will display as 4PM regardless of what timezone we are in.

Whats the best technique for ensuring this in Rails?

  • 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-09T14:03:41+00:00Added an answer on June 9, 2026 at 2:03 pm

    I’m going to answer this question by pointing out some good things to know about adding time in Rails in relation to timezone.

    When you add time, time is allocated in UTC to stay the same time despite timezone changes :

    t = Time.now
    -> 2012-08-10 13:17:01 +0200
    t + 90.days
    -> 2012-11-08 13:17:01 +0100
    

    A DateTime will not do this. A DateTime will go up an hour or down an hour in the same TimeZone it began in :

     dt = DateTime.now
     => Fri, 10 Aug 2012 13:16:54 +0200 
     dt + 90.days
     => Thu, 08 Nov 2012 13:16:54 +0200
    

    But a DateTime is the only way to get the number of days between two dates which you can do by subtracting two DateTimes. This, you can’t do with a Time, because when substracting a time, it will not divide by a perfect 24 hours, you’ll get an irrational number because of the timezone switch.

    This is specific to my issue. But I solved my problem by converting my Time to DateTimes to find the number of days in distance, and then reconverted back to time to find a later time in UTC relative to a TimeZone change :

    original_job.to_time + ( new_date.to_datetime - original_job.to_datetime ).to_i.days
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do i create multiple checkbox for jquery to identify it? example i have
I would like to create multiple objects/instances in a loop. how to do this?
I'm trying to create multiple form instances. For example, i have a form1 and
How Create multiple array from an array and concatenate each elments? I have an
I create multiple Frame programmatically and navigate each Frame to different page, But all
I need to create multiple tar files in a tar-by-environment package. Every different environment
I need to create multiple divs like below based on how many objects are
Can we create multiple test methods in JUnit against single method? I have explored
Is it possible to create multiple instances of an object in javascript such that
I'm trying to create a work schedule creator with multiple stores and each store

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.