[DRE-commits] [SCM] ruby-tzinfo.git branch, master, updated. debian/0.3.33-2-3-g43f58ef

Hleb Valoshka 375GNU at Gmail.COM
Sun Jul 8 09:34:25 UTC 2012


The following commit has been merged in the master branch:
commit 713998b62e1c597d1fbadfb79764676f1d0d9e0a
Author: Hleb Valoshka <375GNU at Gmail.COM>
Date:   Sun Jul 8 12:10:51 2012 +0300

    use system tz data

diff --git a/debian/patches/0002-use-system-tz-data.patch b/debian/patches/0002-use-system-tz-data.patch
new file mode 100644
index 0000000..4777f86
--- /dev/null
+++ b/debian/patches/0002-use-system-tz-data.patch
@@ -0,0 +1,226 @@
+From e9f3e0764c532ddbf19228e0dd822fdeba7b739f Mon Sep 17 00:00:00 2001
+From: Hleb Valoshka <375GNU at Gmail.COM>
+Date: Sun, 8 Jul 2012 12:09:43 +0300
+Subject: [PATCH] use system tz data
+
+ apply patch from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=503591#64
+ fix tests for UTC
+---
+ lib/tzinfo.rb                        |    2 +
+ lib/tzinfo/timezone.rb               |   30 +-------
+ lib/tzinfo/zoneinfo_timezone_info.rb |  129 ++++++++++++++++++++++++++++++++++
+ test/tc_timezone.rb                  |    4 +-
+ 4 files changed, 135 insertions(+), 30 deletions(-)
+ create mode 100644 lib/tzinfo/zoneinfo_timezone_info.rb
+
+diff --git a/lib/tzinfo.rb b/lib/tzinfo.rb
+index e5d042e..5bcd1cb 100644
+--- a/lib/tzinfo.rb
++++ b/lib/tzinfo.rb
+@@ -53,3 +53,5 @@ require 'tzinfo/country_info'
+ 
+ require 'tzinfo/country'
+ require 'tzinfo/country_timezone'
++
++require 'tzinfo/zoneinfo_timezone_info'
+diff --git a/lib/tzinfo/timezone.rb b/lib/tzinfo/timezone.rb
+index b4a8b0e..b2d4e24 100644
+--- a/lib/tzinfo/timezone.rb
++++ b/lib/tzinfo/timezone.rb
+@@ -96,34 +96,8 @@ module TZInfo
+       instance = @@loaded_zones[identifier]
+       unless instance  
+         raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-Za-z0-9\+\-_]+(\/[A-Za-z0-9\+\-_]+)*$/
+-        identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__')
+-        begin
+-          # Use a temporary variable to avoid an rdoc warning
+-          file = "tzinfo/definitions/#{identifier}".untaint
+-          require file
+-          
+-          m = Definitions
+-          identifier.split(/\//).each {|part|
+-            m = m.const_get(part)
+-          }
+-          
+-          info = m.get
+-          
+-          # Could make Timezone subclasses register an interest in an info
+-          # type. Since there are currently only two however, there isn't
+-          # much point.
+-          if info.kind_of?(DataTimezoneInfo)
+-            instance = DataTimezone.new(info)
+-          elsif info.kind_of?(LinkedTimezoneInfo)
+-            instance = LinkedTimezone.new(info)
+-          else
+-            raise InvalidTimezoneIdentifier, "No handler for info type #{info.class}"
+-          end
+-          
+-          @@loaded_zones[instance.identifier] = instance         
+-        rescue LoadError, NameError => e
+-          raise InvalidTimezoneIdentifier, e.message
+-        end
++        instance = DataTimezone.new(ZoneinfoTimezoneInfo.new(identifier))
++        @@loaded_zones[instance.identifier] = instance
+       end
+       
+       instance
+diff --git a/lib/tzinfo/zoneinfo_timezone_info.rb b/lib/tzinfo/zoneinfo_timezone_info.rb
+new file mode 100644
+index 0000000..b73a553
+--- /dev/null
++++ b/lib/tzinfo/zoneinfo_timezone_info.rb
+@@ -0,0 +1,129 @@
++#--
++# Copyright (c) 2008 Philip Ross
++#
++# Permission is hereby granted, free of charge, to any person obtaining a copy
++# of this software and associated documentation files (the "Software"), to deal
++# in the Software without restriction, including without limitation the rights
++# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++# copies of the Software, and to permit persons to whom the Software is
++# furnished to do so, subject to the following conditions:
++#
++# The above copyright notice and this permission notice shall be included in all
++# copies or substantial portions of the Software.
++#
++# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
++# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
++# THE SOFTWARE.
++#++
++
++require 'tzinfo/data_timezone_info'
++require 'tzinfo/timezone'
++
++module TZInfo
++  class ZoneinfoTimezoneInfo < DataTimezoneInfo #:nodoc:
++
++    @@zoneinfo_dir = nil
++
++    class << self
++      def zoneinfo_dir
++        @@zoneinfo_dir ||= find_zoneinfo_dir
++      end
++
++      def zoneinfo_dir=(dir)
++        @@zoneinfo_dir = dir
++      end
++
++      private
++        def find_zoneinfo_dir
++          dir = ['/usr/share/zoneinfo', '/usr/share/lib/zoneinfo', '/etc/zoneinfo'].detect do |dir|
++            File.directory?(dir)
++          end
++
++          raise InvalidTimezoneIdentifier, 'Zoneinfo directory not found, use TZInfo::ZoneinfoTimezoneInfo.zoneinfo_dir= to set' unless dir
++          dir
++        end
++    end
++
++    def initialize(identifier)
++      super(identifier)
++
++      begin
++        File.open(File.join(self.class.zoneinfo_dir, identifier)) do |f|
++          parse(f)
++        end
++      rescue Errno::ENOENT => e
++        raise InvalidTimezoneIdentifier, e.message
++      end
++    end
++
++    private
++      def make_signed(long)
++        long -= 0x100000000 if long >= 0x80000000
++        long
++      end
++
++      def parse(input)
++        magic, ttisgmtcnt, ttisstdcnt, leapcnt, timecnt, typecnt, charcnt =
++          input.read(44).unpack('a5 x15 NNNNNN')
++
++        raise InvalidTimezoneIdentifier, "Invalid magic: #{magic}" unless magic =~ /^TZif2?/
++
++        transitions = []
++
++        (0...timecnt).each do |i|
++          transition_time = make_signed(input.read(4).unpack('N')[0])
++          transitions << {:time => Time.at(transition_time).utc}
++        end
++
++        (0...timecnt).each do |i|
++          localtime_type = input.read(1).unpack('C')[0]
++          transitions[i][:offset] = localtime_type
++        end
++
++        offsets = []
++
++        (0...typecnt).each do |i|
++          gmtoff, isdst, abbrind = input.read(6).unpack('NCC')
++          gmtoff = make_signed(gmtoff)
++          isdst = isdst == 1
++
++          # The setting of offsets is a hack at the moment.
++          # TZInfo wants the base UTC offset and daylight savings offset separately.
++          # For now just assume all dst offsets are 1 hour.
++          std_offset = isdst ? 3600 : 0
++
++          offsets << {:utc_offset => gmtoff - std_offset, :std_offset => std_offset, :is_dst => isdst, :abbr_index => abbrind}
++        end
++
++        abbrev = input.read(charcnt)
++
++        offsets.each do |o|
++          o[:abbr] = abbrev[o[:abbr_index]...abbrev.index("\0", o[:abbr_index])]
++        end
++
++        first = nil
++        offsets.each_with_index do |o, i|
++          if !o[:is_dst]
++            first = i
++            break
++          end
++        end
++
++        if first
++          offset first, offsets[first][:utc_offset], offsets[first][:std_offset], offsets[first][:abbr].to_sym
++        end
++
++        offsets.each_with_index do |o, i|
++          offset i, o[:utc_offset], o[:std_offset], o[:abbr].to_sym unless i == first
++        end
++
++        transitions.each do |t|
++          transition t[:time].year, t[:time].mon, t[:offset], t[:time].to_i
++        end
++      end
++  end
++end
+diff --git a/test/tc_timezone.rb b/test/tc_timezone.rb
+index f49a4d8..51c5508 100644
+--- a/test/tc_timezone.rb
++++ b/test/tc_timezone.rb
+@@ -75,7 +75,7 @@ class TCTimezone < Test::Unit::TestCase
+   def test_get_valid_2
+     tz = Timezone.get('UTC')
+     
+-    assert_kind_of(LinkedTimezone, tz)    
++    assert_kind_of(DataTimezone, tz)
+     assert_equal('UTC', tz.identifier)
+   end
+   
+@@ -934,7 +934,7 @@ class TCTimezone < Test::Unit::TestCase
+   
+   def test_marshal_linked
+     tz = Timezone.get('UTC')
+-    assert_kind_of(LinkedTimezone, tz)
++    assert_kind_of(DataTimezone, tz)
+     assert_same(tz, Marshal.load(Marshal.dump(tz)))    
+   end
+   
+-- 
+1.7.10.4
+
diff --git a/debian/patches/series b/debian/patches/series
index 50ee78d..fcebb86 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-disable-tainted-load-test.patch
+0002-use-system-tz-data.patch

-- 
ruby-tzinfo.git



More information about the Pkg-ruby-extras-commits mailing list