pigeon_hole 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pigeon_hole/json_date_time.rb +4 -17
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-46.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-47.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-58.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-02.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-08.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-09.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-10.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-35.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-36.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-37.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-38.rb +29 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-11.rb +41 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-41.rb +34 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-42.rb +34 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-11-26.rb +35 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-33.rb +39 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-46.rb +40 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-57.rb +37 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-03.rb +27 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-04.rb +27 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-05.rb +27 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-17-22.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-17-23.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-19-14.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-50.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-52.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-53.rb +28 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-26-57.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-26-58.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-27-58.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-27-59.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-40.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-41.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-42.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-53.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-07.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-08.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-09.rb +42 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-20.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-21.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-22.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-23.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-24.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-25.rb +44 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-26.rb +53 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-27.rb +53 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-28.rb +53 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-29.rb +53 -0
- data/lib/pigeon_hole/monster-vim-2016-07-26-10-39-14.rb +53 -0
- data/lib/pigeon_hole/typed_json.rb +13 -0
- data/spec/integration_spec.rb +18 -0
- data/spec/monster-vim-2016-07-26-10-29-02.rb +117 -0
- data/spec/monster-vim-2016-07-26-10-29-53.rb +118 -0
- metadata +55 -2
@@ -0,0 +1,41 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
|
8
|
+
of_a, of_b = object['of'].split('/')
|
9
|
+
if of_b and of_b != '0'
|
10
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
11
|
+
else
|
12
|
+
args << of_a
|
13
|
+
end
|
14
|
+
args << object['sg']
|
15
|
+
DateTime.civil(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
19
|
+
# object.
|
20
|
+
def as_json(*)
|
21
|
+
{
|
22
|
+
JSON.create_id => self.class.name,
|
23
|
+
'y' => (to_f * 1000).to,
|
24
|
+
'm' => month,
|
25
|
+
'd' => day,
|
26
|
+
'H' => hour,
|
27
|
+
'M' => min,
|
28
|
+
'S' => sec,
|
29
|
+
'of' => offset.to_s,
|
30
|
+
'sg' => start,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
35
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
36
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
37
|
+
def to_json(*args)
|
38
|
+
as_json.to_json(*args)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
args = object.valu
|
8
|
+
of_a, of_b = object['of'].split('/')
|
9
|
+
if of_b and of_b != '0'
|
10
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
11
|
+
else
|
12
|
+
args << of_a
|
13
|
+
end
|
14
|
+
args << object['sg']
|
15
|
+
DateTime.civil(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
19
|
+
# object.
|
20
|
+
def as_json(*)
|
21
|
+
{
|
22
|
+
JSON.create_id => self.class.name,
|
23
|
+
'ms' => (to_f * 1000).to_i,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
28
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
29
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
30
|
+
def to_json(*args)
|
31
|
+
as_json.to_json(*args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
args = object.
|
8
|
+
of_a, of_b = object['of'].split('/')
|
9
|
+
if of_b and of_b != '0'
|
10
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
11
|
+
else
|
12
|
+
args << of_a
|
13
|
+
end
|
14
|
+
args << object['sg']
|
15
|
+
DateTime.civil(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
19
|
+
# object.
|
20
|
+
def as_json(*)
|
21
|
+
{
|
22
|
+
JSON.create_id => self.class.name,
|
23
|
+
'ms' => (to_f * 1000).to_i,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
28
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
29
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
30
|
+
def to_json(*args)
|
31
|
+
as_json.to_json(*args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms']
|
8
|
+
|
9
|
+
of_a, of_b = object['of'].split('/')
|
10
|
+
if of_b and of_b != '0'
|
11
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
12
|
+
else
|
13
|
+
args << of_a
|
14
|
+
end
|
15
|
+
args << object['sg']
|
16
|
+
DateTime.civil(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
20
|
+
# object.
|
21
|
+
def as_json(*)
|
22
|
+
{
|
23
|
+
JSON.create_id => self.class.name,
|
24
|
+
'ms' => (to_f * 1000).to_i,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
29
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
30
|
+
# offset <tt>of</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
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms']
|
8
|
+
|
9
|
+
seconds, fragment = Int64.from_bson(buffer).divmod(1000)
|
10
|
+
at(seconds, fragment * 1000).utc
|
11
|
+
|
12
|
+
of_a, of_b = object['of'].split('/')
|
13
|
+
if of_b and of_b != '0'
|
14
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
15
|
+
else
|
16
|
+
args << of_a
|
17
|
+
end
|
18
|
+
args << object['sg']
|
19
|
+
|
20
|
+
DateTime.civil(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
24
|
+
# object.
|
25
|
+
def as_json(*)
|
26
|
+
{
|
27
|
+
JSON.create_id => self.class.name,
|
28
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
33
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
34
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
35
|
+
def to_json(*args)
|
36
|
+
as_json.to_json(*args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms']
|
8
|
+
|
9
|
+
seconds, fragment = Int64.from_bson(econds, fragment = Int64.from_bson(buffer).divmod(1000)
|
10
|
+
at(seconds, fragment * 1000).utc(1000)
|
11
|
+
at(seconds, fragment * 1000).utc
|
12
|
+
|
13
|
+
of_a, of_b = object['of'].split('/')
|
14
|
+
if of_b and of_b != '0'
|
15
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
16
|
+
else
|
17
|
+
args << of_a
|
18
|
+
end
|
19
|
+
args << object['sg']
|
20
|
+
|
21
|
+
DateTime.civil(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
25
|
+
# object.
|
26
|
+
def as_json(*)
|
27
|
+
{
|
28
|
+
JSON.create_id => self.class.name,
|
29
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
34
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
35
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
36
|
+
def to_json(*args)
|
37
|
+
as_json.to_json(*args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
seconds, fragment = Int64.from_bson(ms_since_epoc).divmod(1000)
|
8
|
+
Time.at(seconds, fragment * 1000).utc
|
9
|
+
|
10
|
+
of_a, of_b = object['of'].split('/')
|
11
|
+
if of_b and of_b != '0'
|
12
|
+
args << DateTime.send(:Rational, of_a.to_i, of_b.to_i)
|
13
|
+
else
|
14
|
+
args << of_a
|
15
|
+
end
|
16
|
+
args << object['sg']
|
17
|
+
|
18
|
+
DateTime.civil(*args)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
22
|
+
# object.
|
23
|
+
def as_json(*)
|
24
|
+
{
|
25
|
+
JSON.create_id => self.class.name,
|
26
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
31
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
32
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
33
|
+
def to_json(*args)
|
34
|
+
as_json.to_json(*args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
seconds, fragment = Int64.from_bson(ms_since_epoc).divmod(1000)
|
8
|
+
Time.at(seconds, fragment * 1000).utc.
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
12
|
+
# object.
|
13
|
+
def as_json(*)
|
14
|
+
{
|
15
|
+
JSON.create_id => self.class.name,
|
16
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
21
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
22
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
23
|
+
def to_json(*args)
|
24
|
+
as_json.to_json(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
seconds, fragment = Int64.from_bson(ms_since_epoc).divmod(1000)
|
8
|
+
Time.at(seconds, fragment * 1000).utc.to
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
12
|
+
# object.
|
13
|
+
def as_json(*)
|
14
|
+
{
|
15
|
+
JSON.create_id => self.class.name,
|
16
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
21
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
22
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
23
|
+
def to_json(*args)
|
24
|
+
as_json.to_json(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
seconds, fragment = Int64.from_bson(ms_since_epoc).divmod(1000)
|
8
|
+
Time.at(seconds, fragment * 1000).utc.to_datetime
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
12
|
+
# object.
|
13
|
+
def as_json(*)
|
14
|
+
{
|
15
|
+
JSON.create_id => self.class.name,
|
16
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
21
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
22
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
23
|
+
def to_json(*args)
|
24
|
+
as_json.to_json(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms'].
|
8
|
+
seconds, fragment = ms_since_epoc.divmod(1000)
|
9
|
+
Time.at(seconds, fragment * 1000).utc.to_datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
13
|
+
# object.
|
14
|
+
def as_json(*)
|
15
|
+
{
|
16
|
+
JSON.create_id => self.class.name,
|
17
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
22
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
23
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
24
|
+
def to_json(*args)
|
25
|
+
as_json.to_json(*args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms'].to
|
8
|
+
seconds, fragment = ms_since_epoc.divmod(1000)
|
9
|
+
Time.at(seconds, fragment * 1000).utc.to_datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
13
|
+
# object.
|
14
|
+
def as_json(*)
|
15
|
+
{
|
16
|
+
JSON.create_id => self.class.name,
|
17
|
+
'ms' => (to_i * 1000) + (usec / 1000),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
22
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
23
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
24
|
+
def to_json(*args)
|
25
|
+
as_json.to_json(*args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PigeonHole
|
2
|
+
class JSONDateTime < SimpleDelegator
|
3
|
+
# Deserializes JSON string by converting year <tt>y</tt>, month <tt>m</tt>,
|
4
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
5
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
6
|
+
def self.json_create(object)
|
7
|
+
ms_since_epoc = object['ms'].to_i
|
8
|
+
seconds, fragment = ms_since_epoc.divmod(1000)
|
9
|
+
Time.at(seconds, fragment * 1000).utc.to_datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
13
|
+
# object.
|
14
|
+
def as_json(*)
|
15
|
+
{
|
16
|
+
JSON.create_id => self.class.name,
|
17
|
+
'ms' => (to_i * 1000) + (to_time.usec / 1000),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
22
|
+
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
23
|
+
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> as JSON string
|
24
|
+
def to_json(*args)
|
25
|
+
as_json.to_json(*args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|