Skip to content

Commit

Permalink
Explore Time.parse vs PST in Ruby 1.9 to 2.7, gh-30
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Feb 20, 2021
1 parent a9f8d35 commit c1c948b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c1c948b

Please sign in to comment.