diff --git a/Gemfile b/Gemfile index 6c1fb650..88d57beb 100644 --- a/Gemfile +++ b/Gemfile @@ -80,8 +80,12 @@ group :jekyll_optional_dependencies do gem "yajl-ruby", "~> 1.4" end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem - gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw, :jruby] + # 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", "~> 2.0" + gem "tzinfo-data" + end end # diff --git a/docs/_docs/upgrading/3-to-4.md b/docs/_docs/upgrading/3-to-4.md index de4418f9..cf4b7a16 100644 --- a/docs/_docs/upgrading/3-to-4.md +++ b/docs/_docs/upgrading/3-to-4.md @@ -46,6 +46,21 @@ you can invoke *`Liquid::Template`* directly: + template = Liquid::Template.parse(content) ``` + +### Timezone in Windows + +Timezone handling for Jekyll on Windows now requires `tzinfo-2.0` and above. +Simply add / update the gem listing in your `Gemfile`: + +```ruby +# Gemfile + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +# and associated library. +gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem "tzinfo", "~> 2.0" +``` + --- ### Exclusion changes diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index c6832d7b..acf5c99d 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -88,8 +88,14 @@ module Jekyll group :jekyll_plugins do gem "jekyll-feed", "~> 0.6" end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem - gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] + + # 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", "~> 2.0" + gem "tzinfo-data" + end + # Performance-booster for watching directories on Windows gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform? diff --git a/lib/jekyll/utils/win_tz.rb b/lib/jekyll/utils/win_tz.rb index 965cbc95..235b69b5 100644 --- a/lib/jekyll/utils/win_tz.rb +++ b/lib/jekyll/utils/win_tz.rb @@ -13,16 +13,20 @@ module Jekyll # Returns a string that ultimately re-defines ENV["TZ"] in Windows def calculate(timezone) External.require_with_graceful_fail("tzinfo") unless defined?(TZInfo) - tz = TZInfo::Timezone.get(timezone) - difference = Time.now.to_i - tz.now.to_i + difference = TZInfo::Timezone.get(timezone).now.utc_offset # # POSIX style definition reverses the offset sign. # e.g. Eastern Standard Time (EST) that is 5Hrs. to the 'west' of Prime Meridian # is denoted as: # EST+5 (or) EST+05:00 # Reference: http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html - sign = difference.negative? ? "-" : "+" - offset = sign == "-" ? "+" : "-" unless difference.zero? + if difference.negative? + offset = "-" + sign = "+" + else + offset = "+" + sign = "-" + end # # convert the difference (in seconds) to hours, as a rational number, and perform # a modulo operation on it.