twitter_cldr 6.8.0 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb3f9e357d9106f3b87744f5a8203eda30efd0dac40a24dacfbfaca6122431bc
4
- data.tar.gz: a39e1373d65e2665124caedba55b039d62214950ced3db2e79636e38aef9e9e6
3
+ metadata.gz: c8aceda15c987295a62672bd4f7a78546b34eed2a83eb9178b58bd5a5efa49be
4
+ data.tar.gz: b179d63e855785bdd871b12dda0f7c0ecd67b91106510972d89f74ab93b8ec5d
5
5
  SHA512:
6
- metadata.gz: 0e810877761c6898a5e5efb187c2f16a91536bf5e2bf784d802eb99ef9fe482140c79490f20e2c3748622147f340be3905cdc2cebc1c046e7eff9c5929130c8d
7
- data.tar.gz: 2e9d84af9731ba6ada0cd0fc63224a54fbdb4f7de6b3de1d0f4748d20f71c6f17b65b490b5d32b56e269273c5c05dc94fa704da8fe89af077a62e50aad562023
6
+ metadata.gz: 92f18ec12c13f8ed66b23a9453c9b932e502738266957b326a62493ef1062878ae29932d16f4963658f0b30591528de8415293f1e1c90e394a3e2b4fba2b1244
7
+ data.tar.gz: b34f99bbb5e5e37d3c95d63ce56d47c097d2aac14730ed56d72fc2f5e3c5a0db26b1ff0d20ea599a200d4e75bb3c38cd22ecf5321ece0a606967f0f49290738d
@@ -21,18 +21,18 @@ module TwitterCldr
21
21
  Territories = TwitterCldr::Shared::Territories
22
22
  Utils = TwitterCldr::Utils
23
23
 
24
- def display_name_for(date, fmt = :generic_location)
24
+ def display_name_for(date, fmt = :generic_location, dst = TZInfo::Timezone.default_dst, &block)
25
25
  case fmt
26
26
  when :generic_location
27
27
  generic_location_display_name
28
28
  when :generic_short
29
- generic_short_display_name(date) || generic_location_display_name
29
+ generic_short_display_name(date, dst, &block) || generic_location_display_name
30
30
  when :generic_long
31
- generic_long_display_name(date) || generic_location_display_name
31
+ generic_long_display_name(date, dst, &block) || generic_location_display_name
32
32
  when :specific_short
33
- specific_short_display_name(date)
33
+ specific_short_display_name(date, dst, &block)
34
34
  when :specific_long
35
- specific_long_display_name(date)
35
+ specific_long_display_name(date, dst, &block)
36
36
  when :exemplar_location
37
37
  exemplar_city
38
38
  else
@@ -58,20 +58,20 @@ module TwitterCldr
58
58
  end
59
59
  end
60
60
 
61
- def generic_short_display_name(date)
62
- format_display_name(date, :generic, :short)
61
+ def generic_short_display_name(date, dst = TZInfo::Timezone.default_dst, &block)
62
+ format_display_name(date, :generic, :short, dst, &block)
63
63
  end
64
64
 
65
- def generic_long_display_name(date)
66
- format_display_name(date, :generic, :long)
65
+ def generic_long_display_name(date, dst = TZInfo::Timezone.default_dst, &block)
66
+ format_display_name(date, :generic, :long, dst, &block)
67
67
  end
68
68
 
69
- def specific_short_display_name(date)
70
- format_display_name(date, :specific, :short)
69
+ def specific_short_display_name(date, dst = TZInfo::Timezone.default_dst, &block)
70
+ format_display_name(date, :specific, :short, dst, &block)
71
71
  end
72
72
 
73
- def specific_long_display_name(date)
74
- format_display_name(date, :specific, :long)
73
+ def specific_long_display_name(date, dst = TZInfo::Timezone.default_dst, &block)
74
+ format_display_name(date, :specific, :long, dst, &block)
75
75
  end
76
76
 
77
77
  # From ICU source, TimeZoneGenericNames.java, formatGenericNonLocationName():
@@ -86,9 +86,9 @@ module TwitterCldr
86
86
  # 4. If a generic non-location string is not available, use generic location
87
87
  # string.
88
88
  #
89
- def format_display_name(date, type, fmt)
89
+ def format_display_name(date, type, fmt, dst = TZInfo::Timezone.default_dst, &block)
90
90
  date_int = date.strftime('%s').to_i
91
- period = tz.period_for_local(date)
91
+ period = tz.period_for_local(date, dst, &block)
92
92
 
93
93
  flavor = if type == :generic
94
94
  :generic
@@ -10,8 +10,8 @@ module TwitterCldr
10
10
  DEFAULT_FORMAT = :long_gmt
11
11
  DEFAULT_GMT_ZERO_FORMAT = 'GMT'.freeze
12
12
 
13
- def display_name_for(date, format = DEFAULT_FORMAT)
14
- offset = tz.period_for_local(date).offset
13
+ def display_name_for(date, format = DEFAULT_FORMAT, dst = TZInfo::Timezone.default_dst, &block)
14
+ offset = tz.period_for_local(date, dst, &block).offset
15
15
  offset_secs = offset.utc_offset + offset.std_offset
16
16
  return gmt_zero_format if offset_secs == 0
17
17
 
@@ -27,8 +27,8 @@ module TwitterCldr
27
27
  :iso_extended_local_full
28
28
  ].freeze
29
29
 
30
- def display_name_for(date, fmt)
31
- offset = tz.period_for_local(date).offset
30
+ def display_name_for(date, fmt, dst = TZInfo::Timezone.default_dst, &block)
31
+ offset = tz.period_for_local(date, dst, &block).offset
32
32
  offset_secs = offset.utc_offset + offset.std_offset
33
33
 
34
34
  case fmt
@@ -47,17 +47,17 @@ module TwitterCldr
47
47
  @locale = locale
48
48
  end
49
49
 
50
- def display_name_for(date, format = :generic_location)
50
+ def display_name_for(date, format = :generic_location, dst = TZInfo::Timezone.default_dst, &block)
51
51
  case format
52
52
  when *GenericLocation::FORMATS
53
- generic_location.display_name_for(date, format) ||
54
- gmt_location.display_name_for(date, GENERIC_TO_GMT_MAP[format])
53
+ generic_location.display_name_for(date, format, dst, &block) ||
54
+ gmt_location.display_name_for(date, GENERIC_TO_GMT_MAP[format], dst, &block)
55
55
 
56
56
  when *GmtLocation::FORMATS
57
- gmt_location.display_name_for(date, format)
57
+ gmt_location.display_name_for(date, format, dst, &block)
58
58
 
59
59
  when *Iso8601Location::FORMATS
60
- iso_location.display_name_for(date, format)
60
+ iso_location.display_name_for(date, format, dst, &block)
61
61
 
62
62
  when :zone_id
63
63
  identifier
@@ -75,8 +75,12 @@ module TwitterCldr
75
75
  tz.identifier
76
76
  end
77
77
 
78
- def period_for_local(date)
79
- tz.period_for_local(date)
78
+ def period_for_local(*args, &block)
79
+ tz.period_for_local(*args, &block)
80
+ end
81
+
82
+ def period_for_utc(time)
83
+ tz.period_for_utc(time)
80
84
  end
81
85
 
82
86
  def transitions_up_to(date)
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = '6.8.0'
7
+ VERSION = '6.9.0'
8
8
  end
@@ -266,4 +266,45 @@ describe 'Timezones' do
266
266
  end
267
267
  end
268
268
  end
269
+
270
+ describe '#display_name_for' do
271
+ let(:tz) { TwitterCldr::Timezones::Timezone.instance('America/New_York', :en) }
272
+
273
+ it 'accepts a dst argument', :aggregate_failures do
274
+ zoned_date = Time.new(2021, 11, 7, 1, 1, 23, -4 * 3600)
275
+ dst_date = Time.new(2021, 11, 7, 1, 1, 23, 0)
276
+ non_dst_date = Time.new(2021, 11, 7, 12, 1, 23, 0)
277
+
278
+ expect(tz.display_name_for(zoned_date, :specific_long, true)).to eq 'Eastern Daylight Time'
279
+ expect(tz.display_name_for(dst_date, :specific_long, true)).to eq 'Eastern Daylight Time'
280
+ expect(tz.display_name_for(non_dst_date, :specific_long, false)).to eq 'Eastern Standard Time'
281
+ expect(tz.display_name_for(zoned_date, :iso_extended_local_full, true)).to eq '-04:00'
282
+ expect(tz.display_name_for(dst_date, :iso_extended_local_full, true)).to eq '-04:00'
283
+ expect(tz.display_name_for(non_dst_date, :iso_extended_local_full, false)).to eq '-05:00'
284
+ end
285
+
286
+ it 'accepts a block to handle ambiguous times' do
287
+ # Known ambiguous time
288
+ time = Time.new(2021, 11, 7, 1, 1, 23, 0)
289
+
290
+ expect { tz.display_name_for(time, :generic_short) }.to raise_error(TZInfo::AmbiguousTime)
291
+ expect { tz.display_name_for(time, :generic_short, &:first) }.to_not raise_error
292
+ end
293
+ end
294
+
295
+ describe '#period_for_local' do
296
+ let(:tz) { TwitterCldr::Timezones::Timezone.instance('America/New_York', :en) }
297
+ # Known ambiguous time
298
+ let(:time) { Time.new(2021, 11, 7, 1, 1, 23, 0) }
299
+
300
+ it 'accepts a block to handle ambiguous times' do
301
+ expect { tz.period_for_local(time) }.to raise_error(TZInfo::AmbiguousTime)
302
+ expect { tz.period_for_local(time, &:first) }.to_not raise_error
303
+ end
304
+
305
+ it 'accepts a dst argument', :aggregate_failures do
306
+ expect(tz.period_for_local(time, false).dst?).to be false
307
+ expect(tz.period_for_local(time, true).dst?).to be true
308
+ end
309
+ end
269
310
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_cldr
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.8.0
4
+ version: 6.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-11 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: camertron-eprun