Upgrade WinTZ utility to use TZInfo-2.0 (#7521)

Merge pull request 7521
This commit is contained in:
Ashwin Maroli 2019-02-21 02:23:13 +05:30 committed by jekyllbot
parent 4e24a460ae
commit 13cbef4221
4 changed files with 37 additions and 8 deletions

View File

@ -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
#

View File

@ -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

View File

@ -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?

View File

@ -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.