Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute time zones on all platforms with tzinfo gem #7551

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ group :jekyll_optional_dependencies do
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
end
end
Expand Down
24 changes: 19 additions & 5 deletions features/permalinks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,29 @@ Feature: Fancy permalinks
And the _site directory should exist
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 UTC time
Given I have a configuration file with:
| key | value |
| key | value |
| permalink | "/:year:month:day:hour:minute:second.html" |
| timezone | UTC |
| timezone | UTC |
And I have a _posts directory
And I have the following post:
| title | category | date | content |
| Custom Permalink Schema | stuff | 2009-03-27 22:31:07 | Totally custom. |
| title | category | date | content |
| Custom Permalink Schema | stuff | 2009-03-27 19:31:07 -0500 | Totally custom. |
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Totally custom." in "_site/20090328003107.html"

Scenario: Use custom permalink schema with date and New York time zone
Given I have a configuration file with:
| key | value |
| permalink | "/:year:month:day:hour:minute:second.html" |
| timezone | America/New_York |
And I have a _posts directory
And I have the following post:
| title | category | date | content |
| Custom Permalink Schema | stuff | 2009-03-27 22:31:07 -0500 | Totally custom. |
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
Expand Down
11 changes: 11 additions & 0 deletions features/post_data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ Feature: Post data
And the _site directory should exist
And I should see "Post date: 27 Mar 2009" in "_site/2009/03/27/star-wars.html"

Scenario: Use post.date variable with valid date and timezone
Given I have a _posts directory
And I have a configuration file with "timezone" set to "America/New_York"
And I have the following post:
| title | date | content |
| Star Wars | 2009-03-27 23:23:39 -05:00 | Luke, I am your father. |
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Luke, I am your father." in "_site/2009/03/27/star-wars.html"

Scenario: Use post.date variable with invalid
Given I have a _posts directory
And I have a "_posts/2016-01-01-test.md" page with date "tuesday" that contains "I have a bad date."
Expand Down
6 changes: 2 additions & 4 deletions features/site_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ Feature: Site configuration
And I should see "Page Layout: 2" in "_site/index.html"
And I should see "Post Layout: <p>content for entry1.</p>\n built at" in "_site/2013/04/09/entry1.html"
And I should see "Post Layout: <p>content for entry2.</p>\n built at" in "_site/2013/04/10/entry2.html"
And I should see date "2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html" unless Windows
And I should see date "2013-04-09T22:22:00-05:00" in "_site/2013/04/09/entry1.html" if on Windows
And I should see date "2013-04-10T03:14:00-04:00" in "_site/2013/04/10/entry2.html" unless Windows
And I should see date "2013-04-10T02:14:00-05:00" in "_site/2013/04/10/entry2.html" if on Windows
And I should see "2013-04-09T22:22:00-05:00" in "_site/2013/04/09/entry1.html"
And I should see "2013-04-10T02:14:00-05:00" in "_site/2013/04/10/entry2.html"

Scenario: Generate proper dates with explicitly set timezone (different than posts' time)
Given I have a _layouts directory
Expand Down
4 changes: 0 additions & 4 deletions features/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
FileUtils.rm_rf(Paths.test_dir) if Paths.test_dir.exist?
FileUtils.mkdir_p(Paths.test_dir) unless Paths.test_dir.directory?
Dir.chdir(Paths.test_dir)
@timezone_before_scenario = ENV["TZ"]
end

#
Expand All @@ -14,7 +13,6 @@
Paths.output_file.delete if Paths.output_file.exist?
Paths.status_file.delete if Paths.status_file.exist?
Dir.chdir(Paths.test_dir.parent)
ENV["TZ"] = @timezone_before_scenario
end

#
Expand Down Expand Up @@ -87,7 +85,6 @@

if status == "post"
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}"
end

Expand Down Expand Up @@ -153,7 +150,6 @@
{}
end
config[key] = YAML.load(value)
Jekyll.set_timezone(value) if key == "timezone"
File.write("_config.yml", YAML.dump(config))
end

Expand Down
1 change: 1 addition & 0 deletions jekyll.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("pathutil", "~> 0.9")
s.add_runtime_dependency("rouge", "~> 3.0")
s.add_runtime_dependency("safe_yaml", "~> 1.0")
s.add_runtime_dependency("tzinfo", "~> 1.2")

s.post_install_message = <<~MSG
----------------------------------------------------------------------------------
Expand Down
6 changes: 1 addition & 5 deletions lib/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ def configuration(override = {})
# Returns nothing
# rubocop:disable Naming/AccessorMethodName
def set_timezone(timezone)
ENV["TZ"] = if Utils::Platforms.really_windows?
Utils::WinTZ.calculate(timezone)
else
timezone
end
ENV["TZ"] = Utils::TimeZone.calculate(timezone)
end
# rubocop:enable Naming/AccessorMethodName

Expand Down
2 changes: 0 additions & 2 deletions lib/jekyll/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def gemfile_contents
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Utils
autoload :Internet, "jekyll/utils/internet"
autoload :Platforms, "jekyll/utils/platforms"
autoload :ThreadEvent, "jekyll/utils/thread_event"
autoload :WinTZ, "jekyll/utils/win_tz"
autoload :TimeZone, "jekyll/utils/time_zone"

# Constants for use in #slugify
SLUGIFY_MODES = %w(raw default pretty ascii latin).freeze
Expand Down
7 changes: 3 additions & 4 deletions lib/jekyll/utils/win_tz.rb → lib/jekyll/utils/time_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

module Jekyll
module Utils
module WinTZ
module TimeZone
extend self

# Public: Calculate the Timezone for Windows when the config file has a defined
# 'timezone' key.
# Public: Calculate the Time Zone when the config file has a defined 'timezone' key.
#
# timezone - the IANA Time Zone specified in "_config.yml"
#
# Returns a string that ultimately re-defines ENV["TZ"] in Windows
# Returns a string that ultimately re-defines ENV["TZ"]
def calculate(timezone)
External.require_with_graceful_fail("tzinfo") unless defined?(TZInfo)
tz = TZInfo::Timezone.get(timezone)
Expand Down