Skip to content

Commit

Permalink
Refine EtOrbi.zone_abbreviation(zone_name, time)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Mar 31, 2024
1 parent 599fbc9 commit ac15d51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 5 additions & 6 deletions lib/et-orbi/zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ def zone_abbreviation(zone_name, time)

tz = ::TZInfo::Timezone.get(zone_name)

a = [
tz.period_for_local(time, false).abbreviation.to_s,
tz.period_for_local(time, true).abbreviation.to_s
].uniq
a.reverse! if time.month < 6
ts = tz.period_for_local(time, true) rescue -1
tw = tz.period_for_local(time, false) rescue -2

a.first
return ts.abbreviation.to_s if ts == tw

tz.period_for_local(time + 2 * 3600).abbreviation.to_s
end

def tweak_zone_name(name)
Expand Down
8 changes: 7 additions & 1 deletion spec/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -962,13 +962,19 @@ class << t; def zone; 'ECT'; end; end
{ [ 'Europe/Tallinn', '2012-07-28' ] => 'EEST',
[ 'Europe/Tallinn', '2012-10-28' ] => 'EEST',
[ 'Europe/Tallinn', '2012-12-28' ] => 'EET',

[ 'Europe/Tallinn', '2012-03-25 02:00' ] => 'EET',
[ 'Europe/Tallinn', '2012-03-25 03:00' ] => 'EEST',
[ 'Europe/Tallinn', '2012-03-25 04:00' ] => 'EEST',
[ 'Europe/Tallinn', '2012-03-25 05:00' ] => 'EEST',

[ 'Europe/Tallinn', '2012-10-28 00:00' ] => 'EEST',
[ 'Europe/Tallinn', '2012-10-28 02:59' ] => 'EEST',
[ 'Europe/Tallinn', '2012-10-28 03:00' ] => 'EET',
[ 'Europe/Tallinn', '2012-10-28 03:30' ] => 'EET',
[ 'Europe/Tallinn', '2012-10-28 04:30' ] => 'EET',

# note, it favours non-DST...
# in case of ambiguity, .zone_abbreviation goes 2 hours forward...

}.each do |(zone, time), v|

Expand Down

0 comments on commit ac15d51

Please sign in to comment.