aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/type/time_test.rb
blob: aa114fc911b49198a80b2af64c14e8b2311a56a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true
require "cases/helper"
require "active_model/type"

module ActiveModel
  module Type
    class TimeTest < ActiveModel::TestCase
      def test_type_cast_time
        type = Type::Time.new
        assert_nil type.cast(nil)
        assert_nil type.cast("")
        assert_nil type.cast("ABC")

        time_string = ::Time.now.utc.strftime("%T")
        assert_equal time_string, type.cast(time_string).strftime("%T")

        assert_equal ::Time.utc(2000,  1,  1, 16, 45, 54), type.cast("2015-06-13T19:45:54+03:00")
        assert_equal ::Time.utc(1999, 12, 31, 21,  7,  8), type.cast("06:07:08+09:00")
      end
    end
  end
end