2007-12-21 08:48:59 +01:00
|
|
|
class Time
|
2009-08-04 17:16:03 +02:00
|
|
|
# Coerces the time to a string for JSON encoding.
|
|
|
|
#
|
|
|
|
# ISO 8601 format is used if ActiveSupport::JSON::Encoding.use_standard_json_time_format is set.
|
2008-05-18 06:22:34 +02:00
|
|
|
#
|
2009-02-04 21:26:08 +01:00
|
|
|
# ==== Examples
|
2008-10-27 07:47:01 +01:00
|
|
|
#
|
2009-08-04 17:16:03 +02:00
|
|
|
# # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
|
2008-10-27 07:47:01 +01:00
|
|
|
# Time.utc(2005,2,1,15,15,10).to_json
|
|
|
|
# # => "2005-02-01T15:15:10Z"
|
|
|
|
#
|
2009-08-04 17:16:03 +02:00
|
|
|
# # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
|
2008-05-18 06:22:34 +02:00
|
|
|
# Time.utc(2005,2,1,15,15,10).to_json
|
2008-10-27 07:47:01 +01:00
|
|
|
# # => "2005/02/01 15:15:10 +0000"
|
2009-08-04 17:16:03 +02:00
|
|
|
def as_json(options = nil)
|
|
|
|
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
|
|
|
xmlschema
|
2008-05-18 06:22:34 +02:00
|
|
|
else
|
2009-08-04 17:16:03 +02:00
|
|
|
%(#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
|
2008-05-18 06:22:34 +02:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
end
|