datetime_helper 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +7 -3
- data/lib/datetime_helper/active_model_serialiser.rb +1 -1
- data/lib/datetime_helper/serialisers/active_model_serialiser_helper.rb +19 -0
- data/lib/datetime_helper/version.rb +1 -1
- data/spec/serialisers/{zulu_time_active_model_serialiser_helper_spec.rb → active_model_serialiser_helper_spec.rb} +20 -6
- metadata +5 -5
- data/lib/datetime_helper/serialisers/zulu_time_active_model_serialiser_helper.rb +0 -13
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmZjYmI4OWEwZTBhYzk4ZDBiYTVmZTBmZDhhZGM3N2NiZDlkZTU0OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTJlOGNmYzUzNTU3NTQ4ZWUyNDg3MDMzY2QzZTRiNDU0MTQ3NGEwZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzFiY2VlODg2YzdhNzQ2NmZmNzY0ODRlMDIyODcyNWRlMjkyZmU0NjhiOWVk
|
10
|
+
NjNjNGFmMGU5MWYzZjdjNmU0Yzg1ZDQ3MmRlMmJlNzJhYjIxZjQwNDgwMjY0
|
11
|
+
NGYyMzZjNTVhNWI3ZDYzNWIxZWY4NWYzOTkwNTA1YTgzZTg5Y2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGQ1MWRhNjZlNjMyYzFiMTFiY2ViMTNiMWViZWNjZjA0YTI1Y2ZkZjE5Yzdi
|
14
|
+
NmIwMWRmOTY1YjhhNmE5ZTAzMzQyYjJhYmUxYTRiOTM4NGI5NWNlM2VmMGZk
|
15
|
+
MDMyZjRkNmZkNzdmYTkzYTg4ZDAzNmJjNjliMmJlNzkyMjQ5Y2U=
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A collection of useful utilities for projects that have to deal with dates, time
|
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
1. A base method called `is_zulu_time?`,
|
7
|
+
1. A base method called `is_zulu_time?`,
|
8
8
|
2. `rspec` matchers `be_zulu_time`, `be_an_iso_formatted_date`, and `be_an_iso_formatted_time`
|
9
9
|
3. An `ActiveModel` validator called `zulu_time`, and
|
10
10
|
4. An `ActiveModel::Serializer` helper method called `enforce_zulu_time`.
|
@@ -88,7 +88,7 @@ This will verify that a `Time` is supplied at `UTC+0`,
|
|
88
88
|
or that a `DateTime` has `.zone == "+00:00"`,
|
89
89
|
or that a `String` is in Zulu Time format.
|
90
90
|
|
91
|
-
### Enforcing `ActiveModel::Serializer` Zulu Time
|
91
|
+
### Enforcing `ActiveModel::Serializer` Zulu Time and iso8601 Date String Formats
|
92
92
|
|
93
93
|
First be sure you `require 'datetime_helper/active_model_serialiser'`
|
94
94
|
|
@@ -98,6 +98,7 @@ Then you can put this in your serialisers:
|
|
98
98
|
extend DatetimeHelper::Serialisers
|
99
99
|
|
100
100
|
enforce_zulu_time :updated_at
|
101
|
+
enforce_iso8601_date :enable_date
|
101
102
|
```
|
102
103
|
|
103
104
|
or if you have a bunch of 'em
|
@@ -106,9 +107,11 @@ or if you have a bunch of 'em
|
|
106
107
|
extend DatetimeHelper::Serialisers
|
107
108
|
|
108
109
|
%w(updated_at deleted_at).each { |attribute| enforce_zulu_time attribute }
|
110
|
+
%w(date enable_date).each { |attribute| enforce_iso8601_date attribute }
|
109
111
|
```
|
110
112
|
|
111
|
-
This will ensure that the serialised output is a proper Zulu
|
113
|
+
This will ensure that the serialised output is a proper Zulu time formatted
|
114
|
+
string and iso8601 formatted date string.
|
112
115
|
|
113
116
|
## To build
|
114
117
|
|
@@ -143,3 +146,4 @@ The `Datetime Helper` is © 2015 Westfield Labs and is available for use under t
|
|
143
146
|
|`0.0.3`| Added the `ActiveModel::Serializer` helper |
|
144
147
|
|`1.0.0`| Cleaned up for first official release |
|
145
148
|
|`1.0.1`| Enhanced matchers, and validator |
|
149
|
+
|`1.0.2`| Add iso8601 date format for serializers |
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DatetimeHelper
|
2
|
+
module Serialisers
|
3
|
+
|
4
|
+
# Enforces that a DateTime is serialised as zulu time format
|
5
|
+
def enforce_zulu_time(attribute)
|
6
|
+
define_method(attribute) do
|
7
|
+
object.send(attribute).utc.iso8601 unless object.send(attribute).nil?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Enforces that a Date is serialized as iso8601 format
|
12
|
+
def enforce_iso8601_date(attribute)
|
13
|
+
define_method(attribute) do
|
14
|
+
object.send(attribute).iso8601 unless object.send(attribute).nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -3,22 +3,25 @@ require "datetime_helper/active_model_serialiser"
|
|
3
3
|
|
4
4
|
class TestSerialiser < ActiveModel::Serializer
|
5
5
|
extend DatetimeHelper::Serialisers
|
6
|
-
attributes :updated_at
|
7
|
-
|
6
|
+
attributes :updated_at, :enabled_date
|
7
|
+
|
8
8
|
enforce_zulu_time :updated_at
|
9
|
+
enforce_iso8601_date :enabled_date
|
9
10
|
end
|
10
11
|
|
11
12
|
class TestItemNoTime
|
12
13
|
include ActiveModel::SerializerSupport
|
13
|
-
attr_reader :updated_at
|
14
|
+
attr_reader :updated_at, :enabled_date
|
14
15
|
def initialize(options = {})
|
15
16
|
@updated_at = nil
|
17
|
+
@enabled_date = nil
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
class TestItem < TestItemNoTime
|
20
22
|
def initialize(options = {})
|
21
23
|
@updated_at = options[:updated_at] || Time.now.utc
|
24
|
+
@enabled_date = options[:enabled_date] || Time.now.to_date
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -28,12 +31,12 @@ describe DatetimeHelper::Serialisers do
|
|
28
31
|
|
29
32
|
context 'with a UTC time' do
|
30
33
|
let(:item) { TestItem.new }
|
31
|
-
it { expect(subject[:updated_at]).to be_zulu_time}
|
34
|
+
it { expect(subject[:updated_at]).to be_zulu_time }
|
32
35
|
end
|
33
36
|
|
34
37
|
context 'with a local time' do
|
35
|
-
let(:item) { TestItem.new updated_at:
|
36
|
-
it { expect(subject[:updated_at]).to be_zulu_time}
|
38
|
+
let(:item) { TestItem.new updated_at: Time.now.getlocal }
|
39
|
+
it { expect(subject[:updated_at]).to be_zulu_time }
|
37
40
|
end
|
38
41
|
|
39
42
|
context 'with a nil time' do
|
@@ -41,4 +44,15 @@ describe DatetimeHelper::Serialisers do
|
|
41
44
|
it { expect(subject[:updated_at]).to be_nil}
|
42
45
|
end
|
43
46
|
|
47
|
+
context 'with a date' do
|
48
|
+
let(:item) { TestItem.new }
|
49
|
+
|
50
|
+
it { expect(subject[:enabled_date]).to be_an_iso_formatted_date }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with a nil date' do
|
54
|
+
let(:item) { TestItemNoTime.new }
|
55
|
+
it { expect(subject[:enabled_date]).to be_nil}
|
56
|
+
end
|
57
|
+
|
44
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datetime_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- davesag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -117,13 +117,13 @@ files:
|
|
117
117
|
- lib/datetime_helper/matchers/iso_date_and_time_rspec_matchers.rb
|
118
118
|
- lib/datetime_helper/matchers/zulu_time_rspec_matcher.rb
|
119
119
|
- lib/datetime_helper/rspec.rb
|
120
|
-
- lib/datetime_helper/serialisers/
|
120
|
+
- lib/datetime_helper/serialisers/active_model_serialiser_helper.rb
|
121
121
|
- lib/datetime_helper/validators/zulu_time_active_model_validator.rb
|
122
122
|
- lib/datetime_helper/version.rb
|
123
123
|
- spec/datetime_helper_spec.rb
|
124
124
|
- spec/matchers/iso_date_and_time_rspec_matcher_spec.rb
|
125
125
|
- spec/matchers/zulu_time_rspec_matcher_spec.rb
|
126
|
-
- spec/serialisers/
|
126
|
+
- spec/serialisers/active_model_serialiser_helper_spec.rb
|
127
127
|
- spec/spec_helper.rb
|
128
128
|
- spec/validators/zulu_time_active_model_validator_spec.rb
|
129
129
|
homepage: https://github.com/westfieldlabs/datetime_helper
|
@@ -155,6 +155,6 @@ test_files:
|
|
155
155
|
- spec/datetime_helper_spec.rb
|
156
156
|
- spec/matchers/iso_date_and_time_rspec_matcher_spec.rb
|
157
157
|
- spec/matchers/zulu_time_rspec_matcher_spec.rb
|
158
|
-
- spec/serialisers/
|
158
|
+
- spec/serialisers/active_model_serialiser_helper_spec.rb
|
159
159
|
- spec/spec_helper.rb
|
160
160
|
- spec/validators/zulu_time_active_model_validator_spec.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# Enforces that a DateTime is serialised as zulu time
|
2
|
-
|
3
|
-
module DatetimeHelper
|
4
|
-
module Serialisers
|
5
|
-
|
6
|
-
def enforce_zulu_time(attribute)
|
7
|
-
define_method(attribute) do
|
8
|
-
object.send(attribute).utc.iso8601 unless object.send(attribute).nil?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|