Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Figured it out. Special thanks to @MarkLakata for pointing out the differences between PDT and PST. Turns out we can't rely on these to play with dates. In my app, I do know the geographic location of my Property though. For now, it's "Pacific Time (US &amp; Canada)", but later I may have properties from many other locations. I want to schedule cleanings in the future. In the real world, people don't usually reschedule around DST. So if I say I'm doing something at 4:15pm, I mean it whether it's DST or not, and I need my app to behave the same way.</p> <pre><code>property.timezone =&gt; "Pacific Time (US &amp; Canada)" Time.zone = property.timezone =&gt; "Pacific Time (US &amp; Canada)" time = Time.zone.parse("2013-12-08 04:15pm").utc =&gt; 2013-12-09 00:15:00 UTC time = Time.zone.parse("2013-10-08 04:15pm").utc #DST =&gt; 2013-10-08 23:15:00 UTC </code></pre> <p>I store my cleaning_date attribute in a PostgreSQL DateTime field on Heroku. I know the timezone from the property, so I can save it after I parse it from the front end.</p> <pre><code>property.update(:cleaning_time =&gt; time) </code></pre> <p>To get it back from the database, I just do this:</p> <pre><code>def cleaning_date_string self.cleaning_time.in_time_zone("Pacific Time (US &amp; Canada)").strftime("%m/%d/%Y") end def cleaning_time_string self.cleaning_time.in_time_zone("Pacific Time (US &amp; Canada)").strftime("%l:%M%P") end </code></pre> <p>Unfortunately, this is the only way I found to save a precise time in the database and retrieve it the exact same way. This seems to work locally and on Heroku.</p> <p>addition:<br> This seems to be thread safe according to: <a href="https://stackoverflow.com/questions/15451637/setting-time-zone-during-a-request-thread-safe">Setting Time.zone during a request: Thread Safe?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload