Class: Date

Inherits:
Object show all
Includes:
ActiveSupport::CoreExtensions::Date::Behavior, ActiveSupport::CoreExtensions::Date::Calculations, ActiveSupport::CoreExtensions::Date::Conversions
Defined in:
lib/active_support/core_ext/date.rb,
lib/active_support/json/encoders/date.rb

Overview

:nodoc:

Constant Summary

Constants included from ActiveSupport::CoreExtensions::Date::Conversions

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::Date::Conversions

included, #readable_inspect, #to_date, #to_datetime, #to_formatted_s, #to_time, #xmlschema

Methods included from ActiveSupport::CoreExtensions::Date::Calculations

#advance, #ago, #beginning_of_day, #beginning_of_month, #beginning_of_quarter, #beginning_of_week, #beginning_of_year, #change, #end_of_day, #end_of_month, #end_of_quarter, #end_of_week, #end_of_year, #future?, included, #last_month, #last_year, #minus_with_duration, #months_ago, #months_since, #next_month, #next_week, #next_year, #past?, #plus_with_duration, #prev_month, #prev_year, #since, #today?, #tomorrow, #years_ago, #years_since, #yesterday

Methods included from ActiveSupport::CoreExtensions::Date::Behavior

#acts_like_date?

Instance Method Details

#as_json(options = nil) ⇒ Object

Coerces the date to a string for JSON encoding.

ISO 8601 format is used if ActiveSupport::JSON::Encoding.use_standard_json_time_format is set.

Examples

# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
Date.new(2005,2,1).to_json
# => "2005-02-01"

# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
Date.new(2005,2,1).to_json
# => "2005/02/01"


15
16
17
18
19
20
21
# File 'lib/active_support/json/encoders/date.rb', line 15

def as_json(options = nil)
  if ActiveSupport::JSON::Encoding.use_standard_json_time_format
    strftime("%Y-%m-%d")
  else
    strftime("%Y/%m/%d")
  end
end