Fix timezone incosistencies between different ruby version (#6697)
Merge pull request 6697
This commit is contained in:
parent
c9d2da8722
commit
cf5c689d94
|
@ -71,14 +71,14 @@ Feature: Fancy permalinks
|
||||||
And I should see "Totally custom." in "_site/03-27-2009/custom-permalink-schema.html"
|
And I should see "Totally custom." in "_site/03-27-2009/custom-permalink-schema.html"
|
||||||
|
|
||||||
Scenario: Use custom permalink schema with date and time
|
Scenario: Use custom permalink schema with date and time
|
||||||
Given I have a _posts directory
|
Given I have a configuration file with:
|
||||||
|
| key | value |
|
||||||
|
| permalink | "/:year:month:day:hour:minute:second.html" |
|
||||||
|
| timezone | UTC |
|
||||||
|
And I have a _posts directory
|
||||||
And I have the following post:
|
And I have the following post:
|
||||||
| title | category | date | content |
|
| title | category | date | content |
|
||||||
| Custom Permalink Schema | stuff | 2009-03-27 22:31:07 | Totally custom. |
|
| Custom Permalink Schema | stuff | 2009-03-27 22:31:07 | Totally custom. |
|
||||||
And I have a configuration file with:
|
|
||||||
| key | value |
|
|
||||||
| permalink | "/:year:month:day:hour:minute:second.html" |
|
|
||||||
| timezone | UTC |
|
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then I should get a zero exit status
|
Then I should get a zero exit status
|
||||||
And the _site directory should exist
|
And the _site directory should exist
|
||||||
|
|
|
@ -4,6 +4,7 @@ Before do
|
||||||
FileUtils.rm_rf(Paths.test_dir) if Paths.test_dir.exist?
|
FileUtils.rm_rf(Paths.test_dir) if Paths.test_dir.exist?
|
||||||
FileUtils.mkdir_p(Paths.test_dir) unless Paths.test_dir.directory?
|
FileUtils.mkdir_p(Paths.test_dir) unless Paths.test_dir.directory?
|
||||||
Dir.chdir(Paths.test_dir)
|
Dir.chdir(Paths.test_dir)
|
||||||
|
@timezone_before_scenario = ENV["TZ"]
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -13,6 +14,7 @@ After do
|
||||||
Paths.output_file.delete if Paths.output_file.exist?
|
Paths.output_file.delete if Paths.output_file.exist?
|
||||||
Paths.status_file.delete if Paths.status_file.exist?
|
Paths.status_file.delete if Paths.status_file.exist?
|
||||||
Dir.chdir(Paths.test_dir.parent)
|
Dir.chdir(Paths.test_dir.parent)
|
||||||
|
ENV["TZ"] = @timezone_before_scenario
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -85,6 +87,7 @@ Given(%r!^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$!)
|
||||||
|
|
||||||
if status == "post"
|
if status == "post"
|
||||||
parsed_date = Time.xmlschema(input_hash["date"]) rescue Time.parse(input_hash["date"])
|
parsed_date = Time.xmlschema(input_hash["date"]) rescue Time.parse(input_hash["date"])
|
||||||
|
input_hash["date"] = parsed_date
|
||||||
filename = "#{parsed_date.strftime("%Y-%m-%d")}-#{title}.#{ext}"
|
filename = "#{parsed_date.strftime("%Y-%m-%d")}-#{title}.#{ext}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@ Given(%r!^I have a configuration file with "(.*)" set to "(.*)"$!) do |key, valu
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
config[key] = YAML.load(value)
|
config[key] = YAML.load(value)
|
||||||
|
Jekyll.set_timezone(value) if key == "timezone"
|
||||||
File.write("_config.yml", YAML.dump(config))
|
File.write("_config.yml", YAML.dump(config))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -426,7 +426,7 @@ module Jekyll
|
||||||
|
|
||||||
private
|
private
|
||||||
def merge_date!(source)
|
def merge_date!(source)
|
||||||
if data.key?("date") && !data["date"].is_a?(Time)
|
if data.key?("date")
|
||||||
data["date"] = Utils.parse_date(
|
data["date"] = Utils.parse_date(
|
||||||
data["date"].to_s,
|
data["date"].to_s,
|
||||||
"Document '#{relative_path}' does not have a valid date in the #{source}."
|
"Document '#{relative_path}' does not have a valid date in the #{source}."
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
date: 2015-10-01
|
||||||
|
---
|
||||||
|
Here is the content.
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
date: 2015-10-01 01:00:00 +0800
|
||||||
|
---
|
||||||
|
Here is the content.
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
date: 2015-10-01 01:00:00
|
||||||
|
---
|
||||||
|
Here is the content.
|
|
@ -16,6 +16,19 @@ class TestDocument < JekyllUnitTest
|
||||||
}).tap(&:read)
|
}).tap(&:read)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_document_with_dates(filename)
|
||||||
|
site = fixture_site("collections" => ["dates"])
|
||||||
|
site.process
|
||||||
|
docs = nil
|
||||||
|
with_env("TZ", "UTC") do
|
||||||
|
docs = Document.new(site.in_source_dir(File.join("_dates", filename)), {
|
||||||
|
:site => site,
|
||||||
|
:collection => site.collections["dates"],
|
||||||
|
}).tap(&:read)
|
||||||
|
end
|
||||||
|
docs
|
||||||
|
end
|
||||||
|
|
||||||
context "a document in a collection" do
|
context "a document in a collection" do
|
||||||
setup do
|
setup do
|
||||||
@site = fixture_site({
|
@site = fixture_site({
|
||||||
|
@ -558,4 +571,34 @@ class TestDocument < JekyllUnitTest
|
||||||
Jekyll::Renderer.new(@document.site, @document).render_document
|
Jekyll::Renderer.new(@document.site, @document).render_document
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "a document with a date with timezone" do
|
||||||
|
setup do
|
||||||
|
@document = setup_document_with_dates "time_with_timezone.md"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the expected date" do
|
||||||
|
assert_equal "2015/09/30", @document.data["date"].strftime("%Y/%m/%d")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a document with a date with time but without timezone" do
|
||||||
|
setup do
|
||||||
|
@document = setup_document_with_dates "time_without_timezone.md"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the expected date" do
|
||||||
|
assert_equal "2015/10/01", @document.data["date"].strftime("%Y/%m/%d")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a document with a date without time" do
|
||||||
|
setup do
|
||||||
|
@document = setup_document_with_dates "date_without_time.md"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have the expected date" do
|
||||||
|
assert_equal "2015/10/01", @document.data["date"].strftime("%Y/%m/%d")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue