Skip to content

Commit 06d3707

Browse files
Document ActiveModel::Type::Time as time of day [ci-skip]
`ActiveModel::Type::Time` is meant to represent time of day (without a date or time zone). This commit fixes the code example to show that the date and time zone are normalized when parsing a time from a string.
1 parent ec4e340 commit 06d3707

File tree

1 file changed

+9
-13
lines changed
  • activemodel/lib/active_model/type

1 file changed

+9
-13
lines changed

activemodel/lib/active_model/type/time.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ActiveModel
44
module Type
5-
# Attribute type for time representation. It is registered under the
5+
# Attribute type for time of day representation. It is registered under the
66
# +:time+ key.
77
#
88
# class Event
@@ -11,23 +11,19 @@ module Type
1111
# attribute :start, :time
1212
# end
1313
#
14+
# String values are parsed using the ISO 8601 datetime format, but are
15+
# normalized to have a date of 2000-01-01 and be in the UTC time zone.
16+
#
1417
# event = Event.new
15-
# event.start = "2022-02-18T13:15:00-05:00"
18+
# event.start = "2004-10-25T01:23:45-06:00"
1619
#
1720
# event.start.class # => Time
18-
# event.start.year # => 2022
19-
# event.start.month # => 2
20-
# event.start.day # => 18
21-
# event.start.hour # => 13
22-
# event.start.min # => 15
23-
# event.start.sec # => 0
24-
# event.start.zone # => "EST"
21+
# event.start # => 2000-01-01 07:23:45 UTC
2522
#
26-
# String values are parsed using the ISO 8601 datetime format. Partial
27-
# time-only formats are also accepted.
23+
# Partial time-only formats are also accepted.
2824
#
29-
# event.start = "06:07:08+09:00"
30-
# event.start.utc # => 1999-12-31 21:07:08 UTC
25+
# event.start = "00:01:02+03:00"
26+
# event.start # => 1999-12-31 21:01:02 UTC
3127
#
3228
# The degree of sub-second precision can be customized when declaring an
3329
# attribute:

0 commit comments

Comments
 (0)