@@ -105,29 +105,6 @@ module Format # :nodoc:
105
105
'yakutsk' => 32400
106
106
} . freeze
107
107
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
-
131
108
end
132
109
133
110
def asctime ( ) strftime ( '%c' ) end
@@ -202,14 +179,14 @@ def self.s3e(e, y, m, d, bc=false)
202
179
c = false if match [ 1 ] || match [ 2 ] . size > 2
203
180
end
204
181
y = match &.[]( 0 ) . to_i
205
- e . year = bc ? -y + 1 : y
182
+ e [ : year] = bc ? -y + 1 : y
206
183
end
207
184
208
- e . mon = m . match ( /\d +/ ) &.[]( 0 ) . to_i if m
185
+ e [ : mon] = m . match ( /\d +/ ) &.[]( 0 ) . to_i if m
209
186
210
- e . mday = d . match ( /\d +/ ) &.[]( 0 ) . to_i if d
187
+ e [ : mday] = d . match ( /\d +/ ) &.[]( 0 ) . to_i if d
211
188
212
- e . _comp = c if c != nil
189
+ e [ : _comp] = c if c != nil
213
190
214
191
end
215
192
private_class_method :s3e
@@ -220,19 +197,19 @@ def self.s3e(e, y, m, d, bc=false)
220
197
ABBR_DAYS_KEYS = Format ::ABBR_DAYS . keys . join ( '|' ) . freeze
221
198
private_constant :ABBR_DAYS_KEYS
222
199
223
- def self . _parse_day ( str , e ) # :nodoc:
200
+ def self . _parse_day ( str , hash ) # :nodoc:
224
201
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 ]
226
203
true
227
204
=begin
228
205
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)
230
207
true
231
208
=end
232
209
end
233
210
end
234
211
235
- def self . _parse_time ( str , e ) # :nodoc:
212
+ def self . _parse_time ( str , hash ) # :nodoc:
236
213
if str . sub! (
237
214
/(
238
215
(?:
@@ -264,7 +241,7 @@ def self._parse_time(str, e) # :nodoc:
264
241
' ' )
265
242
266
243
t = $1
267
- e . zone = $2 if $2
244
+ hash [ : zone] = $2 if $2
268
245
269
246
match = t . match /\A (\d +)h?
270
247
(?:\s *:?\s *(\d +)m?
@@ -275,23 +252,23 @@ def self._parse_time(str, e) # :nodoc:
275
252
(?:\s *([ap])(?:m\b |\. m\. ))?/ix
276
253
277
254
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 ]
282
259
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' )
285
262
end
286
263
else
287
- e . hour = 0
264
+ hash [ : hour] = 0
288
265
end
289
266
290
267
true
291
268
end
292
269
end
293
270
294
- def self . _parse_eu ( str , e ) # :nodoc:
271
+ def self . _parse_eu ( str , hash ) # :nodoc:
295
272
if str . sub! (
296
273
/'?(\d +)[^-\d \s ]*
297
274
\s *
@@ -304,12 +281,12 @@ def self._parse_eu(str, e) # :nodoc:
304
281
)?
305
282
/iox ,
306
283
' ' ) # '
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' )
308
285
true
309
286
end
310
287
end
311
288
312
- def self . _parse_us ( str , e ) # :nodoc:
289
+ def self . _parse_us ( str , hash ) # :nodoc:
313
290
if str . sub! (
314
291
/\b (#{ ABBR_MONTHS_KEYS } )[^-\d \s ']*
315
292
\s *
@@ -322,101 +299,101 @@ def self._parse_us(str, e) # :nodoc:
322
299
)?
323
300
/iox ,
324
301
' ' ) # '
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' )
326
303
true
327
304
end
328
305
end
329
306
330
- def self . _parse_iso ( str , e ) # :nodoc:
307
+ def self . _parse_iso ( str , hash ) # :nodoc:
331
308
if str . sub! ( /('?[-+]?\d +)-(\d +)-('?-?\d +)/ , ' ' )
332
- s3e ( e , $1, $2, $3)
309
+ s3e ( hash , $1, $2, $3)
333
310
true
334
311
end
335
312
end
336
313
337
- def self . _parse_iso2 ( str , e ) # :nodoc:
314
+ def self . _parse_iso2 ( str , hash ) # :nodoc:
338
315
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
342
319
true
343
320
elsif str . sub! ( /-w-(\d )\b /i , ' ' )
344
- e . cwday = $1. to_i
321
+ hash [ : cwday] = $1. to_i
345
322
true
346
323
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
349
326
true
350
327
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
353
330
true
354
331
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
357
334
true
358
335
elsif /\d -\d {3}\b / !~ str && str . sub! ( /\b -(\d {3})\b / , ' ' )
359
- e . yday = $1. to_i
336
+ hash [ : yday] = $1. to_i
360
337
true
361
338
end
362
339
end
363
340
364
- def self . _parse_jis ( str , e ) # :nodoc:
341
+ def self . _parse_jis ( str , hash ) # :nodoc:
365
342
if str . sub! ( /\b ([mtsh])(\d +)\. (\d +)\. (\d +)/i , ' ' )
366
343
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
370
347
true
371
348
end
372
349
end
373
350
374
- def self . _parse_vms ( str , e ) # :nodoc:
351
+ def self . _parse_vms ( str , hash ) # :nodoc:
375
352
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)
377
354
true
378
355
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)
380
357
true
381
358
end
382
359
end
383
360
384
- def self . _parse_sla ( str , e ) # :nodoc:
361
+ def self . _parse_sla ( str , hash ) # :nodoc:
385
362
if str . sub! ( %r|('?-?\d +)/\s *('?\d +)(?:\D \s *('?-?\d +))?| , ' ' ) # '
386
- s3e ( e , $1, $2, $3)
363
+ s3e ( hash , $1, $2, $3)
387
364
true
388
365
end
389
366
end
390
367
391
- def self . _parse_dot ( str , e ) # :nodoc:
368
+ def self . _parse_dot ( str , hash ) # :nodoc:
392
369
if str . sub! ( %r|('?-?\d +)\. \s *('?\d +)\. \s *('?-?\d +)| , ' ' ) # '
393
- s3e ( e , $1, $2, $3)
370
+ s3e ( hash , $1, $2, $3)
394
371
true
395
372
end
396
373
end
397
374
398
- def self . _parse_year ( str , e ) # :nodoc:
375
+ def self . _parse_year ( str , hash ) # :nodoc:
399
376
if str . sub! ( /'(\d +)\b / , ' ' )
400
- e . year = $1. to_i
377
+ hash [ : year] = $1. to_i
401
378
true
402
379
end
403
380
end
404
381
405
- def self . _parse_mon ( str , e ) # :nodoc:
382
+ def self . _parse_mon ( str , hash ) # :nodoc:
406
383
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 ]
408
385
true
409
386
end
410
387
end
411
388
412
- def self . _parse_mday ( str , e ) # :nodoc:
389
+ def self . _parse_mday ( str , hash ) # :nodoc:
413
390
if str . sub! ( /(\d +)(st|nd|rd|th)\b /i , ' ' )
414
- e . mday = $1. to_i
391
+ hash [ : mday] = $1. to_i
415
392
true
416
393
end
417
394
end
418
395
419
- def self . _parse_ddd ( str , e ) # :nodoc:
396
+ def self . _parse_ddd ( str , hash ) # :nodoc:
420
397
if str . sub! (
421
398
/([-+]?)(\d {2,14})
422
399
(?:
@@ -440,109 +417,109 @@ def self._parse_ddd(str, e) # :nodoc:
440
417
case $2. size
441
418
when 2
442
419
if $3. nil? && $4
443
- e . sec = $2[ -2 , 2 ] . to_i
420
+ hash [ : sec] = $2[ -2 , 2 ] . to_i
444
421
else
445
- e . mday = $2[ 0 , 2 ] . to_i
422
+ hash [ : mday] = $2[ 0 , 2 ] . to_i
446
423
end
447
424
when 4
448
425
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
451
428
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
454
431
end
455
432
when 6
456
433
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
460
437
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
464
441
end
465
442
when 8 , 10 , 12 , 14
466
443
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
471
448
if $2. size >= 10
472
- e . mon = $2[ -10 , 2 ] . to_i
449
+ hash [ : mon] = $2[ -10 , 2 ] . to_i
473
450
end
474
451
if $2. size == 12
475
- e . year = ( $1 + $2[ -12 , 2 ] ) . to_i
452
+ hash [ : year] = ( $1 + $2[ -12 , 2 ] ) . to_i
476
453
end
477
454
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
480
457
end
481
458
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
489
466
end
490
467
when 3
491
468
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
494
471
else
495
- e . yday = $2[ 0 , 3 ] . to_i
472
+ hash [ : yday] = $2[ 0 , 3 ] . to_i
496
473
end
497
474
when 5
498
475
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
502
479
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
505
482
end
506
483
when 7
507
484
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
512
489
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
515
492
end
516
493
end
517
494
if $3
518
495
if $4
519
496
case $3. size
520
497
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
524
501
end
525
502
else
526
503
case $3. size
527
504
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
531
508
end
532
509
end
533
510
end
534
511
if $4
535
- e . sec_fraction = Rational ( $4. to_i , 10 **$4. size )
512
+ hash [ : sec_fraction] = Rational ( $4. to_i , 10 **$4. size )
536
513
end
537
514
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
542
519
if /\A \d / =~ o
543
520
o = format ( '+%s' , o )
544
521
end
545
- e . offset = zone_to_diff ( o )
522
+ hash [ : offset] = zone_to_diff ( o )
546
523
end
547
524
end
548
525
true
@@ -566,66 +543,64 @@ def self._parse(str, comp=true)
566
543
end
567
544
# we do not str = str.dup since we do a gsub (instead of gsub!)
568
545
569
- e = Format ::Bag . new
570
- e . _comp = comp
571
-
572
546
str = str . gsub ( /[^-+',.\/ :@[:alnum:]\[ \] ]+/ , ' ' )
573
547
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 )
589
565
590
566
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
593
569
end
594
570
end
595
571
596
572
if str . sub! ( /\A \s *(\d {1,2})\s *\z / , ' ' )
597
- if e . hour && !e . mday
573
+ if hash [ : hour] && !hash [ : mday]
598
574
v = $1. to_i
599
- if ( 1 .. 31 ) === v
600
- e . mday = v
575
+ if 1 <= v && v <= 31
576
+ hash [ : mday] = v
601
577
end
602
578
end
603
- if e . mday && !e . hour
579
+ if hash [ : mday] && !hash [ : hour]
604
580
v = $1. to_i
605
- if ( 0 .. 24 ) === v
606
- e . hour = v
581
+ if 0 <= v && v <= 24
582
+ hash [ : hour] = v
607
583
end
608
584
end
609
585
end
610
586
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
616
591
end
617
592
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
622
596
end
623
597
end
624
598
end
625
599
626
- e . offset ||= zone_to_diff ( e . zone ) if e . zone
600
+ hash [ : offset] ||= zone_to_diff ( hash [ : zone] ) if hash [ : zone]
627
601
628
- e . to_hash
602
+ hash . reject! { |k , v | v . nil? || k [ 0 ] . eql? ( '_' ) }
603
+ hash
629
604
end
630
605
631
606
def self . _iso8601 ( str ) # :nodoc:
@@ -757,42 +732,42 @@ def self._xmlschema(str) # :nodoc:
757
732
(?:t
758
733
(\d {2}):(\d {2}):(\d {2})(?:\. (\d +))?)?
759
734
(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
768
743
if $8
769
- e . zone = $8
770
- e . offset = zone_to_diff ( $8)
744
+ hash [ : zone] = $8
745
+ hash [ : offset] = zone_to_diff ( $8)
771
746
end
772
- e . to_hash
747
+ hash
773
748
elsif /\A \s *(\d {2}):(\d {2}):(\d {2})(?:\. (\d +))?
774
749
(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
780
755
if $5
781
- e . zone = $5
782
- e . offset = zone_to_diff ( $5)
756
+ hash [ : zone] = $5
757
+ hash [ : offset] = zone_to_diff ( $5)
783
758
end
784
- e . to_hash
759
+ hash
785
760
elsif /\A \s *(?:--(\d {2})(?:-(\d {2}))?|---(\d {2}))
786
761
(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
791
766
if $4
792
- e . zone = $4
793
- e . offset = zone_to_diff ( $4)
767
+ hash [ : zone] = $4
768
+ hash [ : offset] = zone_to_diff ( $4)
794
769
end
795
- e . to_hash
770
+ hash
796
771
else
797
772
{ }
798
773
end
@@ -805,15 +780,15 @@ def self._rfc2822(str) # :nodoc:
805
780
-?(\d {2,})\s + # allow minus, anyway
806
781
\d {2}:\d {2}(:\d {2})?\s *
807
782
(?:[-+]\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 )
809
784
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
814
789
end
815
790
end
816
- e
791
+ hash
817
792
else
818
793
{ }
819
794
end
0 commit comments