~ubuntu-branches/ubuntu/wily/tdiary/wily

« back to all changes in this revision

Viewing changes to vendor/json_pure-1.7.7/lib/json/add/date.rb

  • Committer: Package Import Robot
  • Author(s): Hideki Yamane
  • Date: 2013-05-19 16:14:01 UTC
  • mfrom: (12.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130519161401-hf5oyr8g8a94fsew
Tags: 3.2.2-2
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
 
2
  require 'json'
 
3
end
 
4
require 'date'
 
5
 
 
6
# Date serialization/deserialization
 
7
class Date
 
8
 
 
9
  # Deserializes JSON string by converting Julian year <tt>y</tt>, month
 
10
  # <tt>m</tt>, day <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> to Date.
 
11
  def self.json_create(object)
 
12
    civil(*object.values_at('y', 'm', 'd', 'sg'))
 
13
  end
 
14
 
 
15
  alias start sg unless method_defined?(:start)
 
16
 
 
17
  # Returns a hash, that will be turned into a JSON object and represent this
 
18
  # object.
 
19
  def as_json(*)
 
20
    {
 
21
      JSON.create_id => self.class.name,
 
22
      'y' => year,
 
23
      'm' => month,
 
24
      'd' => day,
 
25
      'sg' => start,
 
26
    }
 
27
  end
 
28
 
 
29
  # Stores class name (Date) with Julian year <tt>y</tt>, month <tt>m</tt>, day
 
30
  # <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
 
31
  def to_json(*args)
 
32
    as_json.to_json(*args)
 
33
  end
 
34
end