Skip to content

Commit 0bdc6aa

Browse files
authored
Merge pull request #296 from jekyll/copilot/fix-date-formatting-compatibility
[WIP] Fix backwards compatibility in date formatting
2 parents e41276f + 546ee9d commit 0bdc6aa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/jekyll-github-metadata/value.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def render
3434

3535
def to_liquid
3636
case render
37-
when nil, true, false, Hash, String, Numeric, Array
37+
when nil, true, false, Hash, String, Numeric, Array, Time
3838
value
3939
else
4040
to_json

spec/value_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
let(:nil_value_without_key) { described_class.new(nil) }
1212
let(:nil_value_with_key) { described_class.new("my_key", nil) }
1313
let(:key_and_value) { described_class.new("my_key2", proc { "leonard told me" }) }
14+
let(:time_value) { described_class.new(Time.utc(2025, 1, 29, 12, 0, 0)) }
1415

1516
it "takes in a value and stores it" do
1617
v = described_class.new("some_value")
@@ -55,6 +56,16 @@
5556
expect(hash_value.render).to eql("hello" => "world")
5657
end
5758

59+
it "does not modify a time value" do
60+
expect(time_value.render).to be_a(Time)
61+
expect(time_value.render).to eql(Time.utc(2025, 1, 29, 12, 0, 0))
62+
end
63+
64+
it "returns Time objects directly from to_liquid for date filter compatibility" do
65+
expect(time_value.to_liquid).to be_a(Time)
66+
expect(time_value.to_liquid).to eql(Time.utc(2025, 1, 29, 12, 0, 0))
67+
end
68+
5869
it "accepts a nil value with no key" do
5970
expect(nil_value_without_key.key).to eql("{anonymous}")
6071
expect(nil_value_without_key.render).to be_nil

0 commit comments

Comments
 (0)