Skip to content

Commit 5c280fa

Browse files
committedJul 19, 2018
[refactor] get rid of date/format's Bag internal - use Hash
like MRI does internally (in C), this is also a noticeable performance improvement
1 parent a943b01 commit 5c280fa

File tree

1 file changed

+172
-197
lines changed

1 file changed

+172
-197
lines changed
 

Diff for: ‎lib/ruby/stdlib/date/format.rb

+172-197
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,6 @@ module Format # :nodoc:
105105
'yakutsk' => 32400
106106
}.freeze
107107

108-
class Bag # :nodoc:
109-
110-
def initialize
111-
@elem = {}
112-
end
113-
114-
def method_missing(t, *args, &block)
115-
t = t.to_s
116-
set = t.chomp!('=')
117-
t = t.intern
118-
if set
119-
@elem[t] = args[0]
120-
else
121-
@elem[t]
122-
end
123-
end
124-
125-
def to_hash
126-
@elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
127-
end
128-
129-
end
130-
131108
end
132109

133110
def asctime() strftime('%c') end
@@ -202,14 +179,14 @@ def self.s3e(e, y, m, d, bc=false)
202179
c = false if match[1] || match[2].size > 2
203180
end
204181
y = match&.[](0).to_i
205-
e.year = bc ? -y + 1 : y
182+
e[:year] = bc ? -y + 1 : y
206183
end
207184

208-
e.mon = m.match(/\d+/)&.[](0).to_i if m
185+
e[:mon] = m.match(/\d+/)&.[](0).to_i if m
209186

210-
e.mday = d.match(/\d+/)&.[](0).to_i if d
187+
e[:mday] = d.match(/\d+/)&.[](0).to_i if d
211188

212-
e._comp = c if c != nil
189+
e[:_comp] = c if c != nil
213190

214191
end
215192
private_class_method :s3e
@@ -220,19 +197,19 @@ def self.s3e(e, y, m, d, bc=false)
220197
ABBR_DAYS_KEYS = Format::ABBR_DAYS.keys.join('|').freeze
221198
private_constant :ABBR_DAYS_KEYS
222199

223-
def self._parse_day(str, e) # :nodoc:
200+
def self._parse_day(str, hash) # :nodoc:
224201
if str.sub!(/\b(#{ABBR_DAYS_KEYS})[^-\d\s]*/io, ' ')
225-
e.wday = Format::ABBR_DAYS[$1.downcase]
202+
hash[:wday] = Format::ABBR_DAYS[$1.downcase]
226203
true
227204
=begin
228205
elsif str.sub!(/\b(?!\dth)(su|mo|tu|we|th|fr|sa)\b/i, ' ')
229-
e.wday = %w(su mo tu we th fr sa).index($1.downcase)
206+
hash[:wday] = %w(su mo tu we th fr sa).index($1.downcase)
230207
true
231208
=end
232209
end
233210
end
234211

235-
def self._parse_time(str, e) # :nodoc:
212+
def self._parse_time(str, hash) # :nodoc:
236213
if str.sub!(
237214
/(
238215
(?:
@@ -264,7 +241,7 @@ def self._parse_time(str, e) # :nodoc:
264241
' ')
265242

266243
t = $1
267-
e.zone = $2 if $2
244+
hash[:zone] = $2 if $2
268245

269246
match = t.match /\A(\d+)h?
270247
(?:\s*:?\s*(\d+)m?
@@ -275,23 +252,23 @@ def self._parse_time(str, e) # :nodoc:
275252
(?:\s*([ap])(?:m\b|\.m\.))?/ix
276253

277254
if match
278-
e.hour = match[1].to_i
279-
e.min = match[2]&.to_i
280-
e.sec = match[3]&.to_i
281-
e.sec_fraction = Rational(match[4].to_i, 10**match[4].size) if match[4]
255+
hash[:hour] = match[1].to_i
256+
hash[:min] = match[2]&.to_i
257+
hash[:sec] = match[3]&.to_i
258+
hash[:sec_fraction] = Rational(match[4].to_i, 10**match[4].size) if match[4]
282259
if match[5]
283-
e.hour %= 12
284-
e.hour += 12 if match[5].eql?('p') || match[5].eql?('P')
260+
hash[:hour] %= 12
261+
hash[:hour] += 12 if match[5].eql?('p') || match[5].eql?('P')
285262
end
286263
else
287-
e.hour = 0
264+
hash[:hour] = 0
288265
end
289266

290267
true
291268
end
292269
end
293270

294-
def self._parse_eu(str, e) # :nodoc:
271+
def self._parse_eu(str, hash) # :nodoc:
295272
if str.sub!(
296273
/'?(\d+)[^-\d\s]*
297274
\s*
@@ -304,12 +281,12 @@ def self._parse_eu(str, e) # :nodoc:
304281
)?
305282
/iox,
306283
' ') # '
307-
s3e(e, $4, Format::ABBR_MONTHS[$2.downcase].to_s, $1, $3 && $3[0,1].downcase == 'b')
284+
s3e(hash, $4, Format::ABBR_MONTHS[$2.downcase].to_s, $1, $3 && $3[0,1].downcase == 'b')
308285
true
309286
end
310287
end
311288

312-
def self._parse_us(str, e) # :nodoc:
289+
def self._parse_us(str, hash) # :nodoc:
313290
if str.sub!(
314291
/\b(#{ABBR_MONTHS_KEYS})[^-\d\s']*
315292
\s*
@@ -322,101 +299,101 @@ def self._parse_us(str, e) # :nodoc:
322299
)?
323300
/iox,
324301
' ') # '
325-
s3e(e, $4, Format::ABBR_MONTHS[$1.downcase].to_s, $2, $3 && $3[0,1].downcase == 'b')
302+
s3e(hash, $4, Format::ABBR_MONTHS[$1.downcase].to_s, $2, $3 && $3[0,1].downcase == 'b')
326303
true
327304
end
328305
end
329306

330-
def self._parse_iso(str, e) # :nodoc:
307+
def self._parse_iso(str, hash) # :nodoc:
331308
if str.sub!(/('?[-+]?\d+)-(\d+)-('?-?\d+)/, ' ')
332-
s3e(e, $1, $2, $3)
309+
s3e(hash, $1, $2, $3)
333310
true
334311
end
335312
end
336313

337-
def self._parse_iso2(str, e) # :nodoc:
314+
def self._parse_iso2(str, hash) # :nodoc:
338315
if str.sub!(/\b(\d{2}|\d{4})?-?w(\d{2})(?:-?(\d))?\b/i, ' ')
339-
e.cwyear = $1.to_i if $1
340-
e.cweek = $2.to_i
341-
e.cwday = $3.to_i if $3
316+
hash[:cwyear] = $1.to_i if $1
317+
hash[:cweek] = $2.to_i
318+
hash[:cwday] = $3.to_i if $3
342319
true
343320
elsif str.sub!(/-w-(\d)\b/i, ' ')
344-
e.cwday = $1.to_i
321+
hash[:cwday] = $1.to_i
345322
true
346323
elsif str.sub!(/--(\d{2})?-(\d{2})\b/, ' ')
347-
e.mon = $1.to_i if $1
348-
e.mday = $2.to_i
324+
hash[:mon] = $1.to_i if $1
325+
hash[:mday] = $2.to_i
349326
true
350327
elsif str.sub!(/--(\d{2})(\d{2})?\b/, ' ')
351-
e.mon = $1.to_i
352-
e.mday = $2.to_i if $2
328+
hash[:mon] = $1.to_i
329+
hash[:mday] = $2.to_i if $2
353330
true
354331
elsif /[,.](\d{2}|\d{4})-\d{3}\b/ !~ str && str.sub!(/\b(\d{2}|\d{4})-(\d{3})\b/, ' ')
355-
e.year = $1.to_i
356-
e.yday = $2.to_i
332+
hash[:year] = $1.to_i
333+
hash[:yday] = $2.to_i
357334
true
358335
elsif /\d-\d{3}\b/ !~ str && str.sub!(/\b-(\d{3})\b/, ' ')
359-
e.yday = $1.to_i
336+
hash[:yday] = $1.to_i
360337
true
361338
end
362339
end
363340

364-
def self._parse_jis(str, e) # :nodoc:
341+
def self._parse_jis(str, hash) # :nodoc:
365342
if str.sub!(/\b([mtsh])(\d+)\.(\d+)\.(\d+)/i, ' ')
366343
era = { 'm'=>1867, 't'=>1911, 's'=>1925, 'h'=>1988 }[$1.downcase]
367-
e.year = $2.to_i + era
368-
e.mon = $3.to_i
369-
e.mday = $4.to_i
344+
hash[:year] = $2.to_i + era
345+
hash[:mon] = $3.to_i
346+
hash[:mday] = $4.to_i
370347
true
371348
end
372349
end
373350

374-
def self._parse_vms(str, e) # :nodoc:
351+
def self._parse_vms(str, hash) # :nodoc:
375352
if str.sub!(/('?-?\d+)-(#{ABBR_MONTHS_KEYS})[^-\/.]*-('?-?\d+)/iox, ' ')
376-
s3e(e, $3, Format::ABBR_MONTHS[$2.downcase].to_s, $1)
353+
s3e(hash, $3, Format::ABBR_MONTHS[$2.downcase].to_s, $1)
377354
true
378355
elsif str.sub!(/\b(#{ABBR_MONTHS_KEYS})[^-\/.]*-('?-?\d+)(?:-('?-?\d+))?/iox, ' ')
379-
s3e(e, $3, Format::ABBR_MONTHS[$1.downcase].to_s, $2)
356+
s3e(hash, $3, Format::ABBR_MONTHS[$1.downcase].to_s, $2)
380357
true
381358
end
382359
end
383360

384-
def self._parse_sla(str, e) # :nodoc:
361+
def self._parse_sla(str, hash) # :nodoc:
385362
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|, ' ') # '
386-
s3e(e, $1, $2, $3)
363+
s3e(hash, $1, $2, $3)
387364
true
388365
end
389366
end
390367

391-
def self._parse_dot(str, e) # :nodoc:
368+
def self._parse_dot(str, hash) # :nodoc:
392369
if str.sub!(%r|('?-?\d+)\.\s*('?\d+)\.\s*('?-?\d+)|, ' ') # '
393-
s3e(e, $1, $2, $3)
370+
s3e(hash, $1, $2, $3)
394371
true
395372
end
396373
end
397374

398-
def self._parse_year(str, e) # :nodoc:
375+
def self._parse_year(str, hash) # :nodoc:
399376
if str.sub!(/'(\d+)\b/, ' ')
400-
e.year = $1.to_i
377+
hash[:year] = $1.to_i
401378
true
402379
end
403380
end
404381

405-
def self._parse_mon(str, e) # :nodoc:
382+
def self._parse_mon(str, hash) # :nodoc:
406383
if str.sub!(/\b(#{ABBR_MONTHS_KEYS})\S*/io, ' ')
407-
e.mon = Format::ABBR_MONTHS[$1.downcase]
384+
hash[:mon] = Format::ABBR_MONTHS[$1.downcase]
408385
true
409386
end
410387
end
411388

412-
def self._parse_mday(str, e) # :nodoc:
389+
def self._parse_mday(str, hash) # :nodoc:
413390
if str.sub!(/(\d+)(st|nd|rd|th)\b/i, ' ')
414-
e.mday = $1.to_i
391+
hash[:mday] = $1.to_i
415392
true
416393
end
417394
end
418395

419-
def self._parse_ddd(str, e) # :nodoc:
396+
def self._parse_ddd(str, hash) # :nodoc:
420397
if str.sub!(
421398
/([-+]?)(\d{2,14})
422399
(?:
@@ -440,109 +417,109 @@ def self._parse_ddd(str, e) # :nodoc:
440417
case $2.size
441418
when 2
442419
if $3.nil? && $4
443-
e.sec = $2[-2, 2].to_i
420+
hash[:sec] = $2[-2, 2].to_i
444421
else
445-
e.mday = $2[ 0, 2].to_i
422+
hash[:mday] = $2[ 0, 2].to_i
446423
end
447424
when 4
448425
if $3.nil? && $4
449-
e.sec = $2[-2, 2].to_i
450-
e.min = $2[-4, 2].to_i
426+
hash[:sec] = $2[-2, 2].to_i
427+
hash[:min] = $2[-4, 2].to_i
451428
else
452-
e.mon = $2[ 0, 2].to_i
453-
e.mday = $2[ 2, 2].to_i
429+
hash[:mon] = $2[ 0, 2].to_i
430+
hash[:mday] = $2[ 2, 2].to_i
454431
end
455432
when 6
456433
if $3.nil? && $4
457-
e.sec = $2[-2, 2].to_i
458-
e.min = $2[-4, 2].to_i
459-
e.hour = $2[-6, 2].to_i
434+
hash[:sec] = $2[-2, 2].to_i
435+
hash[:min] = $2[-4, 2].to_i
436+
hash[:hour] = $2[-6, 2].to_i
460437
else
461-
e.year = ($1 + $2[ 0, 2]).to_i
462-
e.mon = $2[ 2, 2].to_i
463-
e.mday = $2[ 4, 2].to_i
438+
hash[:year] = ($1 + $2[ 0, 2]).to_i
439+
hash[:mon] = $2[ 2, 2].to_i
440+
hash[:mday] = $2[ 4, 2].to_i
464441
end
465442
when 8, 10, 12, 14
466443
if $3.nil? && $4
467-
e.sec = $2[-2, 2].to_i
468-
e.min = $2[-4, 2].to_i
469-
e.hour = $2[-6, 2].to_i
470-
e.mday = $2[-8, 2].to_i
444+
hash[:sec] = $2[-2, 2].to_i
445+
hash[:min] = $2[-4, 2].to_i
446+
hash[:hour] = $2[-6, 2].to_i
447+
hash[:mday] = $2[-8, 2].to_i
471448
if $2.size >= 10
472-
e.mon = $2[-10, 2].to_i
449+
hash[:mon] = $2[-10, 2].to_i
473450
end
474451
if $2.size == 12
475-
e.year = ($1 + $2[-12, 2]).to_i
452+
hash[:year] = ($1 + $2[-12, 2]).to_i
476453
end
477454
if $2.size == 14
478-
e.year = ($1 + $2[-14, 4]).to_i
479-
e._comp = false
455+
hash[:year] = ($1 + $2[-14, 4]).to_i
456+
hash[:_comp] = false
480457
end
481458
else
482-
e.year = ($1 + $2[ 0, 4]).to_i
483-
e.mon = $2[ 4, 2].to_i
484-
e.mday = $2[ 6, 2].to_i
485-
e.hour = $2[ 8, 2].to_i if $2.size >= 10
486-
e.min = $2[10, 2].to_i if $2.size >= 12
487-
e.sec = $2[12, 2].to_i if $2.size >= 14
488-
e._comp = false
459+
hash[:year] = ($1 + $2[ 0, 4]).to_i
460+
hash[:mon] = $2[ 4, 2].to_i
461+
hash[:mday] = $2[ 6, 2].to_i
462+
hash[:hour] = $2[ 8, 2].to_i if $2.size >= 10
463+
hash[:min] = $2[10, 2].to_i if $2.size >= 12
464+
hash[:sec] = $2[12, 2].to_i if $2.size >= 14
465+
hash[:_comp] = false
489466
end
490467
when 3
491468
if $3.nil? && $4
492-
e.sec = $2[-2, 2].to_i
493-
e.min = $2[-3, 1].to_i
469+
hash[:sec] = $2[-2, 2].to_i
470+
hash[:min] = $2[-3, 1].to_i
494471
else
495-
e.yday = $2[ 0, 3].to_i
472+
hash[:yday] = $2[ 0, 3].to_i
496473
end
497474
when 5
498475
if $3.nil? && $4
499-
e.sec = $2[-2, 2].to_i
500-
e.min = $2[-4, 2].to_i
501-
e.hour = $2[-5, 1].to_i
476+
hash[:sec] = $2[-2, 2].to_i
477+
hash[:min] = $2[-4, 2].to_i
478+
hash[:hour] = $2[-5, 1].to_i
502479
else
503-
e.year = ($1 + $2[ 0, 2]).to_i
504-
e.yday = $2[ 2, 3].to_i
480+
hash[:year] = ($1 + $2[ 0, 2]).to_i
481+
hash[:yday] = $2[ 2, 3].to_i
505482
end
506483
when 7
507484
if $3.nil? && $4
508-
e.sec = $2[-2, 2].to_i
509-
e.min = $2[-4, 2].to_i
510-
e.hour = $2[-6, 2].to_i
511-
e.mday = $2[-7, 1].to_i
485+
hash[:sec] = $2[-2, 2].to_i
486+
hash[:min] = $2[-4, 2].to_i
487+
hash[:hour] = $2[-6, 2].to_i
488+
hash[:mday] = $2[-7, 1].to_i
512489
else
513-
e.year = ($1 + $2[ 0, 4]).to_i
514-
e.yday = $2[ 4, 3].to_i
490+
hash[:year] = ($1 + $2[ 0, 4]).to_i
491+
hash[:yday] = $2[ 4, 3].to_i
515492
end
516493
end
517494
if $3
518495
if $4
519496
case $3.size
520497
when 2, 4, 6
521-
e.sec = $3[-2, 2].to_i
522-
e.min = $3[-4, 2].to_i if $3.size >= 4
523-
e.hour = $3[-6, 2].to_i if $3.size >= 6
498+
hash[:sec] = $3[-2, 2].to_i
499+
hash[:min] = $3[-4, 2].to_i if $3.size >= 4
500+
hash[:hour] = $3[-6, 2].to_i if $3.size >= 6
524501
end
525502
else
526503
case $3.size
527504
when 2, 4, 6
528-
e.hour = $3[ 0, 2].to_i
529-
e.min = $3[ 2, 2].to_i if $3.size >= 4
530-
e.sec = $3[ 4, 2].to_i if $3.size >= 6
505+
hash[:hour] = $3[ 0, 2].to_i
506+
hash[:min] = $3[ 2, 2].to_i if $3.size >= 4
507+
hash[:sec] = $3[ 4, 2].to_i if $3.size >= 6
531508
end
532509
end
533510
end
534511
if $4
535-
e.sec_fraction = Rational($4.to_i, 10**$4.size)
512+
hash[:sec_fraction] = Rational($4.to_i, 10**$4.size)
536513
end
537514
if $5
538-
e.zone = $5
539-
if e.zone[0] == '['
540-
o, n, = e.zone[1..-2].split(':')
541-
e.zone = n || o
515+
hash[:zone] = zone = $5
516+
if zone[0] == '['
517+
o, n, = zone[1..-2].split(':')
518+
hash[:zone] = n || o
542519
if /\A\d/ =~ o
543520
o = format('+%s', o)
544521
end
545-
e.offset = zone_to_diff(o)
522+
hash[:offset] = zone_to_diff(o)
546523
end
547524
end
548525
true
@@ -566,66 +543,64 @@ def self._parse(str, comp=true)
566543
end
567544
# we do not str = str.dup since we do a gsub (instead of gsub!)
568545

569-
e = Format::Bag.new
570-
e._comp = comp
571-
572546
str = str.gsub(/[^-+',.\/:@[:alnum:]\[\]]+/, ' ')
573547

574-
_parse_time(str, e) # || _parse_beat(str, e)
575-
_parse_day(str, e)
576-
577-
_parse_eu(str, e) ||
578-
_parse_us(str, e) ||
579-
_parse_iso(str, e) ||
580-
_parse_jis(str, e) ||
581-
_parse_vms(str, e) ||
582-
_parse_sla(str, e) ||
583-
_parse_dot(str, e) ||
584-
_parse_iso2(str, e) ||
585-
_parse_year(str, e) ||
586-
_parse_mon(str, e) ||
587-
_parse_mday(str, e) ||
588-
_parse_ddd(str, e)
548+
hash = { :_comp => comp }
549+
550+
_parse_time(str, hash) # || _parse_beat(str, hash)
551+
_parse_day(str, hash)
552+
553+
_parse_eu(str, hash) ||
554+
_parse_us(str, hash) ||
555+
_parse_iso(str, hash) ||
556+
_parse_jis(str, hash) ||
557+
_parse_vms(str, hash) ||
558+
_parse_sla(str, hash) ||
559+
_parse_dot(str, hash) ||
560+
_parse_iso2(str, hash) ||
561+
_parse_year(str, hash) ||
562+
_parse_mon(str, hash) ||
563+
_parse_mday(str, hash) ||
564+
_parse_ddd(str, hash)
589565

590566
if str.sub!(/\b(bc\b|bce\b|b\.c\.|b\.c\.e\.)/i, ' ')
591-
if e.year
592-
e.year = -e.year + 1
567+
if year = hash[:year]
568+
hash[:year] = -year + 1
593569
end
594570
end
595571

596572
if str.sub!(/\A\s*(\d{1,2})\s*\z/, ' ')
597-
if e.hour && !e.mday
573+
if hash[:hour] && !hash[:mday]
598574
v = $1.to_i
599-
if (1..31) === v
600-
e.mday = v
575+
if 1 <= v && v <= 31
576+
hash[:mday] = v
601577
end
602578
end
603-
if e.mday && !e.hour
579+
if hash[:mday] && !hash[:hour]
604580
v = $1.to_i
605-
if (0..24) === v
606-
e.hour = v
581+
if 0 <= v && v <= 24
582+
hash[:hour] = v
607583
end
608584
end
609585
end
610586

611-
if e._comp
612-
if e.cwyear
613-
if e.cwyear >= 0 && e.cwyear <= 99
614-
e.cwyear += if e.cwyear >= 69
615-
then 1900 else 2000 end
587+
if hash[:_comp]
588+
if cwyear = hash[:cwyear]
589+
if cwyear >= 0 && cwyear <= 99
590+
hash[:cwyear] += cwyear >= 69 ? 1900 : 2000
616591
end
617592
end
618-
if e.year
619-
if e.year >= 0 && e.year <= 99
620-
e.year += if e.year >= 69
621-
then 1900 else 2000 end
593+
if year = hash[:year]
594+
if year >= 0 && year <= 99
595+
hash[:year] += year >= 69 ? 1900 : 2000
622596
end
623597
end
624598
end
625599

626-
e.offset ||= zone_to_diff(e.zone) if e.zone
600+
hash[:offset] ||= zone_to_diff(hash[:zone]) if hash[:zone]
627601

628-
e.to_hash
602+
hash.reject! { |k, v| v.nil? || k[0].eql?('_') }
603+
hash
629604
end
630605

631606
def self._iso8601(str) # :nodoc:
@@ -757,42 +732,42 @@ def self._xmlschema(str) # :nodoc:
757732
(?:t
758733
(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?
759734
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
760-
e = Format::Bag.new
761-
e.year = $1.to_i
762-
e.mon = $2.to_i if $2
763-
e.mday = $3.to_i if $3
764-
e.hour = $4.to_i if $4
765-
e.min = $5.to_i if $5
766-
e.sec = $6.to_i if $6
767-
e.sec_fraction = Rational($7.to_i, 10**$7.size) if $7
735+
hash = Hash.new
736+
hash[:year] = $1.to_i
737+
hash[:mon] = $2.to_i if $2
738+
hash[:mday] = $3.to_i if $3
739+
hash[:hour] = $4.to_i if $4
740+
hash[:min] = $5.to_i if $5
741+
hash[:sec] = $6.to_i if $6
742+
hash[:sec_fraction] = Rational($7.to_i, 10**$7.size) if $7
768743
if $8
769-
e.zone = $8
770-
e.offset = zone_to_diff($8)
744+
hash[:zone] = $8
745+
hash[:offset] = zone_to_diff($8)
771746
end
772-
e.to_hash
747+
hash
773748
elsif /\A\s*(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?
774749
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
775-
e = Format::Bag.new
776-
e.hour = $1.to_i if $1
777-
e.min = $2.to_i if $2
778-
e.sec = $3.to_i if $3
779-
e.sec_fraction = Rational($4.to_i, 10**$4.size) if $4
750+
hash = Hash.new
751+
hash[:hour] = $1.to_i if $1
752+
hash[:min] = $2.to_i if $2
753+
hash[:sec] = $3.to_i if $3
754+
hash[:sec_fraction] = Rational($4.to_i, 10**$4.size) if $4
780755
if $5
781-
e.zone = $5
782-
e.offset = zone_to_diff($5)
756+
hash[:zone] = $5
757+
hash[:offset] = zone_to_diff($5)
783758
end
784-
e.to_hash
759+
hash
785760
elsif /\A\s*(?:--(\d{2})(?:-(\d{2}))?|---(\d{2}))
786761
(z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str
787-
e = Format::Bag.new
788-
e.mon = $1.to_i if $1
789-
e.mday = $2.to_i if $2
790-
e.mday = $3.to_i if $3
762+
hash = Hash.new
763+
hash[:mon] = $1.to_i if $1
764+
hash[:mday] = $2.to_i if $2
765+
hash[:mday] = $3.to_i if $3
791766
if $4
792-
e.zone = $4
793-
e.offset = zone_to_diff($4)
767+
hash[:zone] = $4
768+
hash[:offset] = zone_to_diff($4)
794769
end
795-
e.to_hash
770+
hash
796771
else
797772
{}
798773
end
@@ -805,15 +780,15 @@ def self._rfc2822(str) # :nodoc:
805780
-?(\d{2,})\s+ # allow minus, anyway
806781
\d{2}:\d{2}(:\d{2})?\s*
807782
(?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/iox =~ str
808-
e = _parse(str, false)
783+
hash = _parse(str, false)
809784
if $1.size < 4
810-
if e[:year] < 50
811-
e[:year] += 2000
812-
elsif e[:year] < 1000
813-
e[:year] += 1900
785+
if hash[:year] < 50
786+
hash[:year] += 2000
787+
elsif hash[:year] < 1000
788+
hash[:year] += 1900
814789
end
815790
end
816-
e
791+
hash
817792
else
818793
{}
819794
end

0 commit comments

Comments
 (0)
Please sign in to comment.