edtf 3.3.0 → 4.0.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 +4 -4
- data/README.md +143 -117
- data/lib/edtf/date.rb +39 -2
- data/lib/edtf/epoch.rb +3 -1
- data/lib/edtf/interval.rb +40 -15
- data/lib/edtf/parser.rb +33 -33
- data/lib/edtf/parser.y +32 -32
- data/lib/edtf/season.rb +10 -2
- data/lib/edtf/set.rb +15 -1
- data/lib/edtf/uncertainty.rb +7 -8
- data/lib/edtf/version.rb +1 -1
- metadata +26 -57
- data/.github/workflows/ci.yml +0 -44
- data/.gitignore +0 -8
- data/.rspec +0 -3
- data/.simplecov +0 -19
- data/Gemfile +0 -20
- data/Rakefile +0 -41
- data/cucumber.yml +0 -1
- data/edtf.gemspec +0 -29
- data/features/parser/date_times.feature +0 -41
- data/features/parser/dates.feature +0 -89
- data/features/parser/intervals.feature +0 -18
- data/features/parser/precision.feature +0 -14
- data/features/parser/uncertain_or_approximate.feature +0 -129
- data/features/parser/unspecified.feature +0 -34
- data/features/print/level_0_edtf.feature +0 -79
- data/features/print/level_1_edtf.feature +0 -137
- data/features/print/level_2_edtf.feature +0 -39
- data/features/print/uncertain_or_approximate.feature +0 -131
- data/features/step_definitions/edtf_steps.rb +0 -150
- data/features/support/env.rb +0 -13
- data/spec/edtf/date_spec.rb +0 -245
- data/spec/edtf/epoch_spec.rb +0 -88
- data/spec/edtf/interval_spec.rb +0 -308
- data/spec/edtf/parser_spec.rb +0 -427
- data/spec/edtf/season_spec.rb +0 -111
- data/spec/edtf/set_spec.rb +0 -107
- data/spec/edtf/uncertainty_spec.rb +0 -296
- data/spec/spec_helper.rb +0 -15
data/lib/edtf/parser.rb
CHANGED
|
@@ -871,7 +871,7 @@ Racc_token_to_s_table = [
|
|
|
871
871
|
"d01_30" ]
|
|
872
872
|
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
|
|
873
873
|
|
|
874
|
-
Racc_debug_parser =
|
|
874
|
+
Racc_debug_parser = true
|
|
875
875
|
|
|
876
876
|
##### State transition tables end #####
|
|
877
877
|
|
|
@@ -889,21 +889,21 @@ Racc_debug_parser = false
|
|
|
889
889
|
|
|
890
890
|
module_eval(<<'.,.,', 'parser.y', 23)
|
|
891
891
|
def _reduce_6(val, _values, result)
|
|
892
|
-
result = Date.
|
|
892
|
+
result = Date.gregorian(val[0]).year_precision!
|
|
893
893
|
result
|
|
894
894
|
end
|
|
895
895
|
.,.,
|
|
896
896
|
|
|
897
897
|
module_eval(<<'.,.,', 'parser.y', 24)
|
|
898
898
|
def _reduce_7(val, _values, result)
|
|
899
|
-
result = Date.
|
|
899
|
+
result = Date.gregorian(*val.flatten).month_precision!
|
|
900
900
|
result
|
|
901
901
|
end
|
|
902
902
|
.,.,
|
|
903
903
|
|
|
904
904
|
module_eval(<<'.,.,', 'parser.y', 25)
|
|
905
905
|
def _reduce_8(val, _values, result)
|
|
906
|
-
result = Date.
|
|
906
|
+
result = Date.gregorian(*val.flatten).day_precision!
|
|
907
907
|
result
|
|
908
908
|
end
|
|
909
909
|
.,.,
|
|
@@ -1057,7 +1057,7 @@ module_eval(<<'.,.,', 'parser.y', 93)
|
|
|
1057
1057
|
|
|
1058
1058
|
module_eval(<<'.,.,', 'parser.y', 99)
|
|
1059
1059
|
def _reduce_39(val, _values, result)
|
|
1060
|
-
result = Date.
|
|
1060
|
+
result = Date.gregorian(val[0][0]).year_precision!
|
|
1061
1061
|
result.unspecified.year[2,2] = val[0][1]
|
|
1062
1062
|
|
|
1063
1063
|
result
|
|
@@ -1099,7 +1099,7 @@ module_eval(<<'.,.,', 'parser.y', 121)
|
|
|
1099
1099
|
|
|
1100
1100
|
module_eval(<<'.,.,', 'parser.y', 125)
|
|
1101
1101
|
def _reduce_47(val, _values, result)
|
|
1102
|
-
result = Date.
|
|
1102
|
+
result = Date.gregorian(val[0]).unspecified!(:month)
|
|
1103
1103
|
result.precision = :month
|
|
1104
1104
|
|
|
1105
1105
|
result
|
|
@@ -1108,7 +1108,7 @@ module_eval(<<'.,.,', 'parser.y', 125)
|
|
|
1108
1108
|
|
|
1109
1109
|
module_eval(<<'.,.,', 'parser.y', 130)
|
|
1110
1110
|
def _reduce_48(val, _values, result)
|
|
1111
|
-
result = Date.
|
|
1111
|
+
result = Date.gregorian(*val[0]).unspecified!(:day)
|
|
1112
1112
|
|
|
1113
1113
|
result
|
|
1114
1114
|
end
|
|
@@ -1116,7 +1116,7 @@ module_eval(<<'.,.,', 'parser.y', 130)
|
|
|
1116
1116
|
|
|
1117
1117
|
module_eval(<<'.,.,', 'parser.y', 134)
|
|
1118
1118
|
def _reduce_49(val, _values, result)
|
|
1119
|
-
result = Date.
|
|
1119
|
+
result = Date.gregorian(val[0]).unspecified!([:day,:month])
|
|
1120
1120
|
|
|
1121
1121
|
result
|
|
1122
1122
|
end
|
|
@@ -1212,7 +1212,7 @@ module_eval(<<'.,.,', 'parser.y', 170)
|
|
|
1212
1212
|
|
|
1213
1213
|
module_eval(<<'.,.,', 'parser.y', 181)
|
|
1214
1214
|
def _reduce_73(val, _values, result)
|
|
1215
|
-
result = Date.
|
|
1215
|
+
result = Date.gregorian(val[1])
|
|
1216
1216
|
result.precision = :year
|
|
1217
1217
|
|
|
1218
1218
|
result
|
|
@@ -1221,7 +1221,7 @@ module_eval(<<'.,.,', 'parser.y', 181)
|
|
|
1221
1221
|
|
|
1222
1222
|
module_eval(<<'.,.,', 'parser.y', 186)
|
|
1223
1223
|
def _reduce_74(val, _values, result)
|
|
1224
|
-
result = Date.
|
|
1224
|
+
result = Date.gregorian(-1 * val[2])
|
|
1225
1225
|
result.precision = :year
|
|
1226
1226
|
|
|
1227
1227
|
result
|
|
@@ -1305,7 +1305,7 @@ module_eval(<<'.,.,', 'parser.y', 225)
|
|
|
1305
1305
|
|
|
1306
1306
|
module_eval(<<'.,.,', 'parser.y', 231)
|
|
1307
1307
|
def _reduce_91(val, _values, result)
|
|
1308
|
-
result = Date.
|
|
1308
|
+
result = Date.gregorian(val[0].year * 10 ** val[2]).year_precision!
|
|
1309
1309
|
|
|
1310
1310
|
result
|
|
1311
1311
|
end
|
|
@@ -1313,7 +1313,7 @@ module_eval(<<'.,.,', 'parser.y', 231)
|
|
|
1313
1313
|
|
|
1314
1314
|
module_eval(<<'.,.,', 'parser.y', 235)
|
|
1315
1315
|
def _reduce_92(val, _values, result)
|
|
1316
|
-
result = Date.
|
|
1316
|
+
result = Date.gregorian(val[1] * 10 ** val[3]).year_precision!
|
|
1317
1317
|
|
|
1318
1318
|
result
|
|
1319
1319
|
end
|
|
@@ -1321,7 +1321,7 @@ module_eval(<<'.,.,', 'parser.y', 235)
|
|
|
1321
1321
|
|
|
1322
1322
|
module_eval(<<'.,.,', 'parser.y', 239)
|
|
1323
1323
|
def _reduce_93(val, _values, result)
|
|
1324
|
-
result = Date.
|
|
1324
|
+
result = Date.gregorian(-1 * val[2] * 10 ** val[4]).year_precision!
|
|
1325
1325
|
|
|
1326
1326
|
result
|
|
1327
1327
|
end
|
|
@@ -1448,49 +1448,49 @@ module_eval(<<'.,.,', 'parser.y', 287)
|
|
|
1448
1448
|
|
|
1449
1449
|
module_eval(<<'.,.,', 'parser.y', 289)
|
|
1450
1450
|
def _reduce_114(val, _values, result)
|
|
1451
|
-
result = Date.
|
|
1451
|
+
result = Date.gregorian(*val[0]).day_precision!
|
|
1452
1452
|
result
|
|
1453
1453
|
end
|
|
1454
1454
|
.,.,
|
|
1455
1455
|
|
|
1456
1456
|
module_eval(<<'.,.,', 'parser.y', 290)
|
|
1457
1457
|
def _reduce_115(val, _values, result)
|
|
1458
|
-
result = Date.
|
|
1458
|
+
result = Date.gregorian(*val[0]).month_precision!
|
|
1459
1459
|
result
|
|
1460
1460
|
end
|
|
1461
1461
|
.,.,
|
|
1462
1462
|
|
|
1463
1463
|
module_eval(<<'.,.,', 'parser.y', 291)
|
|
1464
1464
|
def _reduce_116(val, _values, result)
|
|
1465
|
-
result = Date.
|
|
1465
|
+
result = Date.gregorian(val[0]).year_precision!
|
|
1466
1466
|
result
|
|
1467
1467
|
end
|
|
1468
1468
|
.,.,
|
|
1469
1469
|
|
|
1470
1470
|
module_eval(<<'.,.,', 'parser.y', 294)
|
|
1471
1471
|
def _reduce_117(val, _values, result)
|
|
1472
|
-
result = (Date.
|
|
1472
|
+
result = (Date.gregorian(*val[0]).day_precision! .. Date.gregorian(*val[2]).day_precision!)
|
|
1473
1473
|
result
|
|
1474
1474
|
end
|
|
1475
1475
|
.,.,
|
|
1476
1476
|
|
|
1477
1477
|
module_eval(<<'.,.,', 'parser.y', 295)
|
|
1478
1478
|
def _reduce_118(val, _values, result)
|
|
1479
|
-
result = (Date.
|
|
1479
|
+
result = (Date.gregorian(*val[0]).month_precision! .. Date.gregorian(*val[2]).month_precision!)
|
|
1480
1480
|
result
|
|
1481
1481
|
end
|
|
1482
1482
|
.,.,
|
|
1483
1483
|
|
|
1484
1484
|
module_eval(<<'.,.,', 'parser.y', 296)
|
|
1485
1485
|
def _reduce_119(val, _values, result)
|
|
1486
|
-
result = (Date.
|
|
1486
|
+
result = (Date.gregorian(val[0]).year_precision! .. Date.gregorian(val[2]).year_precision!)
|
|
1487
1487
|
result
|
|
1488
1488
|
end
|
|
1489
1489
|
.,.,
|
|
1490
1490
|
|
|
1491
1491
|
module_eval(<<'.,.,', 'parser.y', 302)
|
|
1492
1492
|
def _reduce_120(val, _values, result)
|
|
1493
|
-
result = Date.
|
|
1493
|
+
result = Date.gregorian(val[0][0], val[2], val[4])
|
|
1494
1494
|
result.unspecified.year[2,2] = val[0][1]
|
|
1495
1495
|
|
|
1496
1496
|
result
|
|
@@ -1499,7 +1499,7 @@ module_eval(<<'.,.,', 'parser.y', 302)
|
|
|
1499
1499
|
|
|
1500
1500
|
module_eval(<<'.,.,', 'parser.y', 307)
|
|
1501
1501
|
def _reduce_121(val, _values, result)
|
|
1502
|
-
result = Date.
|
|
1502
|
+
result = Date.gregorian(val[0][0], val[2], 1)
|
|
1503
1503
|
result.month_precision!
|
|
1504
1504
|
result.unspecified.year[2,2] = val[0][1]
|
|
1505
1505
|
|
|
@@ -1509,7 +1509,7 @@ module_eval(<<'.,.,', 'parser.y', 307)
|
|
|
1509
1509
|
|
|
1510
1510
|
module_eval(<<'.,.,', 'parser.y', 313)
|
|
1511
1511
|
def _reduce_122(val, _values, result)
|
|
1512
|
-
result = Date.
|
|
1512
|
+
result = Date.gregorian(val[0][0], 1, val[5])
|
|
1513
1513
|
result.unspecified.year[2,2] = val[0][1]
|
|
1514
1514
|
result.unspecified!(:month)
|
|
1515
1515
|
|
|
@@ -1519,7 +1519,7 @@ module_eval(<<'.,.,', 'parser.y', 313)
|
|
|
1519
1519
|
|
|
1520
1520
|
module_eval(<<'.,.,', 'parser.y', 319)
|
|
1521
1521
|
def _reduce_123(val, _values, result)
|
|
1522
|
-
result = Date.
|
|
1522
|
+
result = Date.gregorian(val[0][0], 1, 1)
|
|
1523
1523
|
result.unspecified.year[2,2] = val[0][1]
|
|
1524
1524
|
result.unspecified!([:month, :day])
|
|
1525
1525
|
|
|
@@ -1529,7 +1529,7 @@ module_eval(<<'.,.,', 'parser.y', 319)
|
|
|
1529
1529
|
|
|
1530
1530
|
module_eval(<<'.,.,', 'parser.y', 325)
|
|
1531
1531
|
def _reduce_124(val, _values, result)
|
|
1532
|
-
result = Date.
|
|
1532
|
+
result = Date.gregorian(val[0][0], val[2], 1)
|
|
1533
1533
|
result.unspecified.year[2,2] = val[0][1]
|
|
1534
1534
|
result.unspecified!(:day)
|
|
1535
1535
|
|
|
@@ -1539,7 +1539,7 @@ module_eval(<<'.,.,', 'parser.y', 325)
|
|
|
1539
1539
|
|
|
1540
1540
|
module_eval(<<'.,.,', 'parser.y', 331)
|
|
1541
1541
|
def _reduce_125(val, _values, result)
|
|
1542
|
-
result = Date.
|
|
1542
|
+
result = Date.gregorian(val[0], 1, val[5])
|
|
1543
1543
|
result.unspecified!(:month)
|
|
1544
1544
|
|
|
1545
1545
|
result
|
|
@@ -1578,7 +1578,7 @@ module_eval(<<'.,.,', 'parser.y', 342)
|
|
|
1578
1578
|
|
|
1579
1579
|
module_eval(<<'.,.,', 'parser.y', 344)
|
|
1580
1580
|
def _reduce_131(val, _values, result)
|
|
1581
|
-
result = uoa(Date.
|
|
1581
|
+
result = uoa(Date.gregorian(val[0]), val[1], :year)
|
|
1582
1582
|
result
|
|
1583
1583
|
end
|
|
1584
1584
|
.,.,
|
|
@@ -1593,7 +1593,7 @@ module_eval(<<'.,.,', 'parser.y', 348)
|
|
|
1593
1593
|
|
|
1594
1594
|
module_eval(<<'.,.,', 'parser.y', 351)
|
|
1595
1595
|
def _reduce_133(val, _values, result)
|
|
1596
|
-
result = [uoa(Date.
|
|
1596
|
+
result = [uoa(Date.gregorian(val[0], val[2]), val[3], [:year, :month])]
|
|
1597
1597
|
|
|
1598
1598
|
result
|
|
1599
1599
|
end
|
|
@@ -1601,7 +1601,7 @@ module_eval(<<'.,.,', 'parser.y', 351)
|
|
|
1601
1601
|
|
|
1602
1602
|
module_eval(<<'.,.,', 'parser.y', 354)
|
|
1603
1603
|
def _reduce_134(val, _values, result)
|
|
1604
|
-
result = [uoa(Date.
|
|
1604
|
+
result = [uoa(Date.gregorian(val[0], val[2]), val[4], [:month]), true]
|
|
1605
1605
|
|
|
1606
1606
|
result
|
|
1607
1607
|
end
|
|
@@ -1633,7 +1633,7 @@ module_eval(<<'.,.,', 'parser.y', 366)
|
|
|
1633
1633
|
|
|
1634
1634
|
module_eval(<<'.,.,', 'parser.y', 369)
|
|
1635
1635
|
def _reduce_138(val, _values, result)
|
|
1636
|
-
result = uoa(uoa(Date.
|
|
1636
|
+
result = uoa(uoa(Date.gregorian(val[0], val[2], val[5]), val[4], :month), val[6], :day)
|
|
1637
1637
|
|
|
1638
1638
|
result
|
|
1639
1639
|
end
|
|
@@ -1641,7 +1641,7 @@ module_eval(<<'.,.,', 'parser.y', 369)
|
|
|
1641
1641
|
|
|
1642
1642
|
module_eval(<<'.,.,', 'parser.y', 372)
|
|
1643
1643
|
def _reduce_139(val, _values, result)
|
|
1644
|
-
result = uoa(Date.
|
|
1644
|
+
result = uoa(Date.gregorian(val[0][0], val[0][1], val[2]), val[3])
|
|
1645
1645
|
|
|
1646
1646
|
result
|
|
1647
1647
|
end
|
|
@@ -1649,7 +1649,7 @@ module_eval(<<'.,.,', 'parser.y', 372)
|
|
|
1649
1649
|
|
|
1650
1650
|
module_eval(<<'.,.,', 'parser.y', 375)
|
|
1651
1651
|
def _reduce_140(val, _values, result)
|
|
1652
|
-
result = uoa(Date.
|
|
1652
|
+
result = uoa(Date.gregorian(val[0][0], val[0][1], val[2]), val[4], [:day])
|
|
1653
1653
|
|
|
1654
1654
|
result
|
|
1655
1655
|
end
|
|
@@ -1657,7 +1657,7 @@ module_eval(<<'.,.,', 'parser.y', 375)
|
|
|
1657
1657
|
|
|
1658
1658
|
module_eval(<<'.,.,', 'parser.y', 378)
|
|
1659
1659
|
def _reduce_141(val, _values, result)
|
|
1660
|
-
result = uoa(Date.
|
|
1660
|
+
result = uoa(Date.gregorian(val[0], val[2], val[4]), val[6], [:month, :day])
|
|
1661
1661
|
|
|
1662
1662
|
result
|
|
1663
1663
|
end
|
|
@@ -1665,7 +1665,7 @@ module_eval(<<'.,.,', 'parser.y', 378)
|
|
|
1665
1665
|
|
|
1666
1666
|
module_eval(<<'.,.,', 'parser.y', 381)
|
|
1667
1667
|
def _reduce_142(val, _values, result)
|
|
1668
|
-
result = Date.
|
|
1668
|
+
result = Date.gregorian(val[0], val[2], val[4])
|
|
1669
1669
|
result = uoa(result, val[6], [:day])
|
|
1670
1670
|
result = uoa(result, val[8], [:month, :day])
|
|
1671
1671
|
|
data/lib/edtf/parser.y
CHANGED
|
@@ -21,9 +21,9 @@ rule
|
|
|
21
21
|
;
|
|
22
22
|
|
|
23
23
|
date :
|
|
24
|
-
year { result = Date.
|
|
25
|
-
| year_month { result = Date.
|
|
26
|
-
| year_month_day { result = Date.
|
|
24
|
+
year { result = Date.gregorian(val[0]).year_precision! }
|
|
25
|
+
| year_month { result = Date.gregorian(*val.flatten).month_precision! }
|
|
26
|
+
| year_month_day { result = Date.gregorian(*val.flatten).day_precision! }
|
|
27
27
|
;
|
|
28
28
|
|
|
29
29
|
|
|
@@ -97,7 +97,7 @@ rule
|
|
|
97
97
|
|
|
98
98
|
unspecified : unspecified_year
|
|
99
99
|
{
|
|
100
|
-
result = Date.
|
|
100
|
+
result = Date.gregorian(val[0][0]).year_precision!
|
|
101
101
|
result.unspecified.year[2,2] = val[0][1]
|
|
102
102
|
}
|
|
103
103
|
| unspecified_month
|
|
@@ -123,16 +123,16 @@ rule
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
unspecified_month : year '-' U U {
|
|
126
|
-
result = Date.
|
|
126
|
+
result = Date.gregorian(val[0]).unspecified!(:month)
|
|
127
127
|
result.precision = :month
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
unspecified_day : year_month '-' U U {
|
|
131
|
-
result = Date.
|
|
131
|
+
result = Date.gregorian(*val[0]).unspecified!(:day)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
unspecified_day_and_month : year '-' U U '-' U U {
|
|
135
|
-
result = Date.
|
|
135
|
+
result = Date.gregorian(val[0]).unspecified!([:day,:month])
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
level_1_interval : level_1_interval_closed | level_1_interval_open | level_1_interval_unknown
|
|
@@ -179,12 +179,12 @@ rule
|
|
|
179
179
|
long_year_simple :
|
|
180
180
|
LONGYEAR long_year
|
|
181
181
|
{
|
|
182
|
-
result = Date.
|
|
182
|
+
result = Date.gregorian(val[1])
|
|
183
183
|
result.precision = :year
|
|
184
184
|
}
|
|
185
185
|
| LONGYEAR '-' long_year
|
|
186
186
|
{
|
|
187
|
-
result = Date.
|
|
187
|
+
result = Date.gregorian(-1 * val[2])
|
|
188
188
|
result.precision = :year
|
|
189
189
|
}
|
|
190
190
|
;
|
|
@@ -229,15 +229,15 @@ rule
|
|
|
229
229
|
long_year_scientific :
|
|
230
230
|
long_year_simple E integer
|
|
231
231
|
{
|
|
232
|
-
result = Date.
|
|
232
|
+
result = Date.gregorian(val[0].year * 10 ** val[2]).year_precision!
|
|
233
233
|
}
|
|
234
234
|
| LONGYEAR int1_4 E integer
|
|
235
235
|
{
|
|
236
|
-
result = Date.
|
|
236
|
+
result = Date.gregorian(val[1] * 10 ** val[3]).year_precision!
|
|
237
237
|
}
|
|
238
238
|
| LONGYEAR '-' int1_4 E integer
|
|
239
239
|
{
|
|
240
|
-
result = Date.
|
|
240
|
+
result = Date.gregorian(-1 * val[2] * 10 ** val[4]).year_precision!
|
|
241
241
|
}
|
|
242
242
|
;
|
|
243
243
|
|
|
@@ -287,49 +287,49 @@ rule
|
|
|
287
287
|
|
|
288
288
|
earlier : DOTS date { result = val[1] }
|
|
289
289
|
|
|
290
|
-
later : year_month_day DOTS { result = Date.
|
|
291
|
-
| year_month DOTS { result = Date.
|
|
292
|
-
| year DOTS { result = Date.
|
|
290
|
+
later : year_month_day DOTS { result = Date.gregorian(*val[0]).day_precision! }
|
|
291
|
+
| year_month DOTS { result = Date.gregorian(*val[0]).month_precision! }
|
|
292
|
+
| year DOTS { result = Date.gregorian(val[0]).year_precision! }
|
|
293
293
|
;
|
|
294
294
|
|
|
295
|
-
consecutives : year_month_day DOTS year_month_day { result = (Date.
|
|
296
|
-
| year_month DOTS year_month { result = (Date.
|
|
297
|
-
| year DOTS year { result = (Date.
|
|
295
|
+
consecutives : year_month_day DOTS year_month_day { result = (Date.gregorian(*val[0]).day_precision! .. Date.gregorian(*val[2]).day_precision!) }
|
|
296
|
+
| year_month DOTS year_month { result = (Date.gregorian(*val[0]).month_precision! .. Date.gregorian(*val[2]).month_precision!) }
|
|
297
|
+
| year DOTS year { result = (Date.gregorian(val[0]).year_precision! .. Date.gregorian(val[2]).year_precision!) }
|
|
298
298
|
;
|
|
299
299
|
|
|
300
300
|
partial_unspecified :
|
|
301
301
|
unspecified_year '-' month '-' day
|
|
302
302
|
{
|
|
303
|
-
result = Date.
|
|
303
|
+
result = Date.gregorian(val[0][0], val[2], val[4])
|
|
304
304
|
result.unspecified.year[2,2] = val[0][1]
|
|
305
305
|
}
|
|
306
306
|
| unspecified_year '-' month
|
|
307
307
|
{
|
|
308
|
-
result = Date.
|
|
308
|
+
result = Date.gregorian(val[0][0], val[2], 1)
|
|
309
309
|
result.month_precision!
|
|
310
310
|
result.unspecified.year[2,2] = val[0][1]
|
|
311
311
|
}
|
|
312
312
|
| unspecified_year '-' U U '-' day
|
|
313
313
|
{
|
|
314
|
-
result = Date.
|
|
314
|
+
result = Date.gregorian(val[0][0], 1, val[5])
|
|
315
315
|
result.unspecified.year[2,2] = val[0][1]
|
|
316
316
|
result.unspecified!(:month)
|
|
317
317
|
}
|
|
318
318
|
| unspecified_year '-' U U '-' U U
|
|
319
319
|
{
|
|
320
|
-
result = Date.
|
|
320
|
+
result = Date.gregorian(val[0][0], 1, 1)
|
|
321
321
|
result.unspecified.year[2,2] = val[0][1]
|
|
322
322
|
result.unspecified!([:month, :day])
|
|
323
323
|
}
|
|
324
324
|
| unspecified_year '-' month '-' U U
|
|
325
325
|
{
|
|
326
|
-
result = Date.
|
|
326
|
+
result = Date.gregorian(val[0][0], val[2], 1)
|
|
327
327
|
result.unspecified.year[2,2] = val[0][1]
|
|
328
328
|
result.unspecified!(:day)
|
|
329
329
|
}
|
|
330
330
|
| year '-' U U '-' day
|
|
331
331
|
{
|
|
332
|
-
result = Date.
|
|
332
|
+
result = Date.gregorian(val[0], 1, val[5])
|
|
333
333
|
result.unspecified!(:month)
|
|
334
334
|
}
|
|
335
335
|
;
|
|
@@ -342,17 +342,17 @@ rule
|
|
|
342
342
|
| pua_year_month { result = val[0][0].month_precision! }
|
|
343
343
|
| pua_year_month_day { result = val[0].day_precision! }
|
|
344
344
|
|
|
345
|
-
pua_year : year UA { result = uoa(Date.
|
|
345
|
+
pua_year : year UA { result = uoa(Date.gregorian(val[0]), val[1], :year) }
|
|
346
346
|
|
|
347
347
|
pua_year_month :
|
|
348
348
|
pua_year '-' month ua {
|
|
349
349
|
result = [uoa(val[0].change(:month => val[2]), val[3], [:month, :year])]
|
|
350
350
|
}
|
|
351
351
|
| year '-' month UA {
|
|
352
|
-
result = [uoa(Date.
|
|
352
|
+
result = [uoa(Date.gregorian(val[0], val[2]), val[3], [:year, :month])]
|
|
353
353
|
}
|
|
354
354
|
| year '-(' month ')' UA {
|
|
355
|
-
result = [uoa(Date.
|
|
355
|
+
result = [uoa(Date.gregorian(val[0], val[2]), val[4], [:month]), true]
|
|
356
356
|
}
|
|
357
357
|
| pua_year '-(' month ')' UA {
|
|
358
358
|
result = [uoa(val[0].change(:month => val[2]), val[4], [:month]), true]
|
|
@@ -367,19 +367,19 @@ rule
|
|
|
367
367
|
result = uoa(val[0][0].change(:day => val[2]), val[4], [:day])
|
|
368
368
|
}
|
|
369
369
|
| year '-(' month ')' UA day ua {
|
|
370
|
-
result = uoa(uoa(Date.
|
|
370
|
+
result = uoa(uoa(Date.gregorian(val[0], val[2], val[5]), val[4], :month), val[6], :day)
|
|
371
371
|
}
|
|
372
372
|
| year_month '-' day UA {
|
|
373
|
-
result = uoa(Date.
|
|
373
|
+
result = uoa(Date.gregorian(val[0][0], val[0][1], val[2]), val[3])
|
|
374
374
|
}
|
|
375
375
|
| year_month '-(' day ')' UA {
|
|
376
|
-
result = uoa(Date.
|
|
376
|
+
result = uoa(Date.gregorian(val[0][0], val[0][1], val[2]), val[4], [:day])
|
|
377
377
|
}
|
|
378
378
|
| year '-(' month '-' day ')' UA {
|
|
379
|
-
result = uoa(Date.
|
|
379
|
+
result = uoa(Date.gregorian(val[0], val[2], val[4]), val[6], [:month, :day])
|
|
380
380
|
}
|
|
381
381
|
| year '-(' month '-(' day ')' UA ')' UA {
|
|
382
|
-
result = Date.
|
|
382
|
+
result = Date.gregorian(val[0], val[2], val[4])
|
|
383
383
|
result = uoa(result, val[6], [:day])
|
|
384
384
|
result = uoa(result, val[8], [:month, :day])
|
|
385
385
|
}
|
data/lib/edtf/season.rb
CHANGED
|
@@ -130,7 +130,13 @@ module EDTF
|
|
|
130
130
|
def qualified?; !!@qualifier; end
|
|
131
131
|
|
|
132
132
|
def edtf
|
|
133
|
-
'%04d-%2d%s' % [
|
|
133
|
+
'%04d-%2d%s%s%s' % [
|
|
134
|
+
year,
|
|
135
|
+
CODES[season],
|
|
136
|
+
uncertain? ? '?' : '',
|
|
137
|
+
approximate? ? '~' : '',
|
|
138
|
+
qualified? ? "^#{qualifier}" : ''
|
|
139
|
+
]
|
|
134
140
|
end
|
|
135
141
|
|
|
136
142
|
alias to_s edtf
|
|
@@ -140,7 +146,9 @@ module EDTF
|
|
|
140
146
|
case other
|
|
141
147
|
when Date
|
|
142
148
|
cover?(other) ? 0 : to_date <=> other
|
|
143
|
-
when Interval
|
|
149
|
+
when Interval
|
|
150
|
+
(c = other <=> self) && -c
|
|
151
|
+
when Epoch
|
|
144
152
|
[min, max] <=> [other.min, other.max]
|
|
145
153
|
when Season
|
|
146
154
|
[year, month, qualifier] <=> [other.year, other.month, other.qualifier]
|
data/lib/edtf/set.rb
CHANGED
|
@@ -7,7 +7,6 @@ module EDTF
|
|
|
7
7
|
include Comparable
|
|
8
8
|
|
|
9
9
|
def_delegators :@dates, :size, :length, :empty?
|
|
10
|
-
def_delegators :to_a, :include?
|
|
11
10
|
|
|
12
11
|
attr_accessor :choice, :later, :earlier
|
|
13
12
|
|
|
@@ -29,6 +28,21 @@ module EDTF
|
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
|
|
31
|
+
def include?(v)
|
|
32
|
+
return false unless v.is_a?(Date)
|
|
33
|
+
return false if empty?
|
|
34
|
+
|
|
35
|
+
dates_array = to_a
|
|
36
|
+
if earlier?
|
|
37
|
+
(min = dates_array.first) >= v && min.precision == v.precision
|
|
38
|
+
elsif later?
|
|
39
|
+
(max = dates_array.last) <= v && max.precision == v.precision
|
|
40
|
+
else
|
|
41
|
+
dates_array.member?(v)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
alias member? include?
|
|
45
|
+
|
|
32
46
|
def <<(date)
|
|
33
47
|
dates << date
|
|
34
48
|
self
|
data/lib/edtf/uncertainty.rb
CHANGED
|
@@ -12,7 +12,6 @@ module EDTF
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def hash_base=(base)
|
|
15
|
-
@hash_map = false
|
|
16
15
|
@hash_base = base
|
|
17
16
|
end
|
|
18
17
|
|
|
@@ -37,13 +36,7 @@ module EDTF
|
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def hash
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
def hash_map
|
|
46
|
-
@hash_map ||= (0...length).map { |i| hash_base << i }
|
|
39
|
+
(year ? hash_base : 0) + (month ? hash_base << 1 : 0) + (day ? hash_base << 2 : 0)
|
|
47
40
|
end
|
|
48
41
|
|
|
49
42
|
end
|
|
@@ -79,6 +72,12 @@ module EDTF
|
|
|
79
72
|
alias specific! specified!
|
|
80
73
|
alias unspecific! unspecified!
|
|
81
74
|
|
|
75
|
+
def hash
|
|
76
|
+
y, m, d = year, month, day
|
|
77
|
+
(y[0] ? 1 : 0) | (y[1] ? 2 : 0) | (y[2] ? 4 : 0) | (y[3] ? 8 : 0) |
|
|
78
|
+
(m[0] ? 16 : 0) | (m[1] ? 32 : 0) | (d[0] ? 64 : 0) | (d[1] ? 128 : 0)
|
|
79
|
+
end
|
|
80
|
+
|
|
82
81
|
private :year=, :month=, :day=
|
|
83
82
|
|
|
84
83
|
def to_s
|
data/lib/edtf/version.rb
CHANGED