Ruby / Rails DateTime.utc.iso8601和Time.utc.iso8601格式不同

时间:2018-02-20 06:36:58

标签: ruby-on-rails ruby timezone timezone-offset

由于Rails monkeypat日期对象,我不清楚这是Rails特定行为还是Ruby特定行为。

if ( f1.get_numerator() != -4 ||
     f1.get_denominator() != 5 ||
     f2.get_numerator() != 2 ||
     f2.get_denominator() != 3)
{
   cout <<"The reduce function was wrong.\n";

   if ( f1.get_numerator() != -4 )
   {
      cout << "Expected value of f1.get_numerator(): " << -4 << "\n";
      cout << "Actual value of f1.get_numerator(): " << f1.get_numerator() << "\n";
   }
   else
   {
      cout << "Got the expected value of f1.get_numerator()\n";
   }

   if ( f1.get_denominator() != 5 )
   {
      cout << "Expected value of f1.get_denominator(): " << 5 << "\n";
      cout << "Actual value of f1.get_denominator(): " << f1.get_denominator() << "\n";
   }
   else
   {
      cout << "Got the expected value of f1.get_denominator()\n";
   }


   if ( f2.get_numerator() != 2 )
   {
      cout << "Expected value of f2.get_numerator(): " << 2 << "\n";
      cout << "Actual value of f2.get_numerator(): " << f2.get_numerator() << "\n";
   else
   {
      cout << "Got the expected value of f2.get_numerator()\n";
   }

   if ( f2.get_denominator() != 3 )
   {
      cout << "Expected value of f2.get_denominator(): " << 3 << "\n";
      cout << "Actual value of f2.get_denominator(): " << f2.get_denominator() << "\n";
   }
   else
   {
      cout << "Got the expected value of f2.get_denominator()\n";
   }

    result -= 0.5;
}

注意一个人如何拥有时区字符串“+00:00”而另一个字符串为“Z”。它们在iso8610标准中都是等价的,但是我试图在起始类类型的情况下生成相同的字符串。

The Ruby docs on Time甚至没有记录DateTime.now.utc.iso8601 => "2018-02-20T06:31:44+00:00" Time.now.utc.iso8601 => "2018-02-20T06:31:44Z" 方法,它们只是在不同的上下文中显示它,所以我不知道如何弄清楚发生了什么。

0 个答案:

没有答案