From c1c948b149e88c72fc475ff4b5f01f50666cfd17 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Sat, 20 Feb 2021 16:15:28 +0900 Subject: [PATCH] Explore Time.parse vs PST in Ruby 1.9 to 2.7, gh-30 --- .github/workflows/test.yaml | 2 +- spec/module_spec.rb | 31 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 +---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f94ef40..d75bee5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - ruby: [ '2.3', '2.5', '2.6', '2.7', jruby-9.2 ] + ruby: [ '1.9', '2.1', '2.3', '2.5', '2.6', '2.7', jruby-9.2 ] experimental: [ false ] tz: [ '', 'UTC', 'Asia/Tokyo', 'America/Chicago' ] fail-fast: false diff --git a/spec/module_spec.rb b/spec/module_spec.rb index 6dde06d..164e331 100644 --- a/spec/module_spec.rb +++ b/spec/module_spec.rb @@ -236,6 +236,37 @@ expect(t.to_zs).to eq('2019-01-01 12:10:00 Asia/Shanghai') end + # https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations + # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + + [ # IN | Time.parse | EtOrbi.parse | in timezone) + + '2015/03/08 01:59:59 | 20150308 015959 +0300 | 20150308 015959 +0300 | Europe/Moscow', + #'2021-01-01 7AM PST | 20210101 070000 -0800 | 20210101 070000 +0000', + + ].each do |l| + + ss = l.split(/\s*\|\s*/) + l0 = ss.join(' | ') + + h = OpenStruct.new(s: ss[0], ts: ss[1], eots: ss[2], inzone: ss[3]) + + f = '%Y%m%d %H%M%S %z' + title = "parses #{h.s.inspect}" + title = "#{title} in #{h.inzone}" if h.inzone + + it(title) do + + t, ot = in_zone(h.inzone) { [ Time.parse(h.s), EtOrbi.parse(h.s) ] } + + l1 = [ h.s, t.strftime(f), ot.strftime(f), h.inzone ] + .compact + .join(' | ') + + expect(l1).to eq(l0) + end + end + context 'when Chronic is defined' do before :each do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c16a975..cfbc356 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,12 +8,9 @@ ENV['_TZ'] = ENV['TZ'] # preserve original TZ if any require 'pp' +require 'ostruct' require 'chronic' - # -p defined?(Chronic) -p defined?(::Chronic) - # ::Khronic = ::Chronic Object.send(:remove_const, :Chronic)