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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:10:47+00:00 2026-05-23T15:10:47+00:00

I have an edit view for an Event model with name , start_time ,

  • 0

I have an edit view for an Event model with name, start_time, and end_time fields. My view is a form that looks roughly like this:

# ...
# form with:
#  - event name
#  - datetime_select for event start_time (in business's local time zone)
#  - datetime_select for event end_time (in business's local time zone)

Now, here’s the problem: the start_time and end_time has a time zone attached to it, but that time is lost when we render the view, because the datetime_select doesn’t include a field for time zone. The result is that we have a “UTC time” which is actually the local time stripped of its timezone.

To recap, the situation looks like this when we render the form in the view, then immediately submit it without making any changes:

db time:                 2011-05-15 @ 1100 UTC
converted to local time: 2011-05-15 @ 0600 CDT
time stored in view:     2011-05-15 @ 0600 UTC (time zone info lost)
time posted back to db:  2011-05-15 @ 0600 UTC

Notice that the time that was stored was 1100 UTC originally but is now 0600 UTC, even though we didn’t make any changes. That’s a serious error.

There’s a number of approaches we could take here. What’s the smartest way to avoid losing the time zones when posting to the view? (Note that the model might get updated in ways other than posting the form — e.g., through an API.)

  • 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-23T15:10:47+00:00Added an answer on May 23, 2026 at 3:10 pm

    It never feels very satisfactory but i usually deal with this by making a couple of new methods for a virtual attribute called local_time, or time_formatted or something like that, which convert back and forth from the UTC time that is stored in the db.

    In this example the db field is “deadline” and the virtual attribute is “deadline_formatted”:

    def deadline_formatted
      self.deadline
    end
    
    def deadline_formatted= s
      self.deadline = s
    end
    

    Then, in the form,

    <%= f.label :deadline_formatted, "Deadline" %>
    <%= f.text_field :deadline_formatted %>
    

    Via some rails magic, which i still don’t quite understand*, this is enough to do it – it looks like it shouldn’t work but it does. At least it did for me.

    *the part that i don’t understand is that setting the deadline field in the form will go on to call the deadline= method with the value from the text field. Instead, i call the deadline_formatted= method, which just passes the result to deadline=, so you’d think the result would be identical. But, somehow, the time is translated to and fro from UTC (database) to local time (form).

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

Sidebar

Related Questions

I have a data-structure (in plist) that looks something like this: What i have
I have a edit View - Product/Edit/1 1 being the Id of the Product.How
I have an Edit action and an Edit view to allow users to update
so i have a Parents controller with list and edit view for it (to
I have two view controllers in a tabbar which can both edit data. Therefore,
I have a view and it's composed of two tables. I want to edit
How to implement CEditListCtrl?. List control with edit capabality (Report/Grid view). I have a
I have 3 (Edit) mutually exclusive IEnumerables that I want to iterate over. I
I have a Django app with custom form fields, some of which have slow
I'm noticing some behavior that I don't like, and I'm wondering if this is

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.