-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from interagent/add-zulu-time-helpers
Add Pliny::Helpers::ZuluTime to Serializers::Base
- Loading branch information
Showing
5 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Pliny::Helpers | ||
module ZuluTime | ||
def zulu_time(time) | ||
time ? time.getutc.strftime("%Y-%m-%dT%H:%M:%SZ") : nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module Serializers | ||
class Base | ||
extend Pliny::Helpers::ZuluTime | ||
|
||
@@structures = {} | ||
|
||
def self.structure(type, &blk) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "spec_helper" | ||
require "active_support/core_ext/numeric/time" | ||
|
||
describe Pliny::Helpers::ZuluTime do | ||
context "zulu_time" do | ||
class ZuluTimeTest | ||
extend Pliny::Helpers::ZuluTime | ||
end | ||
|
||
it "it formats Time instances" do | ||
formatted = ZuluTimeTest.zulu_time(Time.parse("2017-11-28T21:49:52.123+00:00")) | ||
assert_equal "2017-11-28T21:49:52Z", formatted | ||
end | ||
|
||
it "it formats DateTime instances" do | ||
formatted = ZuluTimeTest.zulu_time(DateTime.parse("2017-11-28T21:49:52.123+00:00")) | ||
assert_equal "2017-11-28T21:49:52Z", formatted | ||
end | ||
|
||
it "when called with nil" do | ||
assert_nil ZuluTimeTest.zulu_time(nil) | ||
end | ||
end | ||
end |