【问题标题】:Time on Rails baseball schedule app off by 5 hours on productionTime on Rails 棒球时间表应用程序在生产时减少了 5 小时
【发布时间】:2014-04-11 14:35:30
【问题描述】:

我有一个应用程序:http://arethebaronsplaying.com/,它在美国中部时间每天晚上 7 点在生产时中断,但在本地正常运行。该网站由 Ninefold 托管。

简而言之,我有一个包含一堆游戏对象的种子.rb 文件,游戏的一个属性是日期,它设置为 m/d 格式,例如。 4/09。

每天晚上 7 点,应用程序会通过显示一个大大的 NO 和文字说明下一场比赛何时开始,下一场比赛是当天的比赛。然后在它下面,它会显示一个YES!与当天的比赛。

所以它显示的是 YES 和 NO,这让我认为 Date.today 计算时间的方式可能与 Time.now 不同,并且由于我同时使用它们,因此错误的将显示 NO。

无论如何,这是我的逻辑:

<% i = 0 %>
<% games.each do |game| %>
<% if game.date.strftime("%_m/%d")[1..-1] == Time.now.strftime("%_m/%d")[1..-1] && game.away == false %>
<h1 class="main-text answer yesanswer" id="responsive_headline"><%=link_to "YES!", "http://www.milb.com/tickets/singlegame.jsp?sid=t247", target: "_blank" %></h1>
<% i = 1 %>
<br>
<h2 class="main-text2 gamewrap" id="responsive_headline2">
    <% if game.away == false %>
        <span class="next-venue">vs.</span>
        <span class="next-opponent"><%= game.opponent %></span> |
        <span class="next-time"><%= game.time %></span>
    <% else %>
        <span class="next-venue">at</span>
        <span class="next-opponent"><%= game.opponent %></span> |
        <span class="next-time"><%= game.time %></span>
    <% end %>
</h2>
<% elsif game.date.strftime("%_m/%d")[1..-1] == Time.now.strftime("%_m/%d")[1..-1] && game.away == true %>
    <% unless i == 1 %>
    <a><h1 class="main-text answer" data-reveal-id="myModal" data-reveal id="responsive_headline">NO.</h1></a>
    <% i = 1 %>
    <h2 class="main-text2 gamewrap" id="responsive_headline2">
        <span class="next-venue">away game</span>
        <span class="next-opponent">@<%= game.opponent %></span>
    </h2>
    <% end %>
<% else %>
    <% unless i == 1 %>
    <a><h1 class="main-text answer" data-reveal-id="myModal" data-reveal id="responsive_headline">NO.</h1></a>
    <% i = 1 %>
    <h2 class="main-text2 gamewrap" id="responsive_headline2">
        <span class="next-venue">vs.</span>
        <span class="next-opponent">
            <% if next_home_game > 1 %>
            <%= game.opponent %>
            in <%= next_home_game %> days |
            <% else %>
            <%= game.opponent %>
            in <%= next_home_game %> day |
            <% end %>
        <span class="next-time"><%= game.time %></span>
    </h2>
    <% end %>
  <% end %>
<% end %>

我尝试将config.time_zone = 'Central Time (US &amp; Canada)' 添加到application.rbproduction.rb,但它破坏了部署。

Ninefold 的时间如下:https://help.ninefold.com/hc/en-us/articles/201320124-What-time-standard-does-Ninefold-use-

感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails ruby timezone


    【解决方案1】:

    日期和时间(跨时区)管理起来简直就是一场噩梦(我知道这没有多大帮助……但我去过那里,你有我的哀悼)。

    无论如何...尝试分别用Time.zone.nowTime.zone.today 替换所有Time.nowDate.today 调用。

    确保您的所有时间都以 UTC 格式存储在数据库中(无论您的当地时间或服务器时间如何),并查看一些提供其他建议的文章(如 http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-railshttp://danilenko.org/2012/7/6/rails_timezones/

    祝你好运!

    【讨论】:

    • 感谢您的建议。我一定会试试的。我没有任何时间存储在数据库中,只有日期 (4/11),我应该更改这些吗?
    猜你喜欢
    • 2011-01-20
    • 1970-01-01
    • 2015-11-12
    • 2010-12-21
    • 2011-05-12
    • 2013-03-06
    • 2013-06-28
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多