Skip to content

Commit 70de71c

Browse files
committed
Prefer Rational over BigDecimal.
1 parent 9a0d678 commit 70de71c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/db/postgres/native/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def parse(string)
9191
if match = string.match(/\A(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(?:\.\d+)?)([-+]\d\d(?::\d\d)?)?\z/)
9292
parts = match.captures
9393

94-
parts[5] = BigDecimal(parts[5])
94+
parts[5] = Rational(parts[5])
9595

9696
if parts[6].nil?
9797
parts[6] = '+00'

test/db/postgres/connection/date_time.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@
3232
let(:connection) {subject.new(**CREDENTIALS)}
3333

3434
# PG produces: "2022-11-11 12:38:59.123456+00"
35-
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59.123456+11', Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+11:00')
35+
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59.123456+11', Time.new(2022, 11, 11, 23, 38, Rational('59.123456'), '+11:00')
3636

3737
# PG produces: "2022-11-11 12:38:59+00"
38-
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59+11', Time.new(2022, 11, 11, 23, 38, BigDecimal('59'), '+11:00')
38+
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59+11', Time.new(2022, 11, 11, 23, 38, Rational('59'), '+11:00')
3939

4040
# PG produces: "2022-11-11 23:38:59.123456+00"
41-
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59.123456', Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+00:00')
41+
it_behaves_like ATimestamp, 'UTC', '2022-11-11 23:38:59.123456', Time.new(2022, 11, 11, 23, 38, Rational('59.123456'), '+00:00')
4242

4343
# PG produces: "2022-11-11 23:38:59+11"
44-
it_behaves_like ATimestamp, 'Australia/Sydney', '2022-11-11 23:38:59', Time.new(2022, 11, 11, 23, 38, BigDecimal('59'), '+11:00')
44+
it_behaves_like ATimestamp, 'Australia/Sydney', '2022-11-11 23:38:59', Time.new(2022, 11, 11, 23, 38, Rational('59'), '+11:00')
4545

4646
# PG produces: "2022-11-12 06:08:59.123456+11"
47-
it_behaves_like ATimestamp, 'Australia/Sydney', '2022-11-11 23:38:59.123456+04:30', Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+04:30')
47+
it_behaves_like ATimestamp, 'Australia/Sydney', '2022-11-11 23:38:59.123456+04:30', Time.new(2022, 11, 11, 23, 38, Rational('59.123456'), '+04:30')
4848

4949
# PG produces: "2000-01-01 05:30:00+05:30"
5050
it_behaves_like ATimestamp, 'Asia/Kolkata', '2000-01-01 00:00:00+00', Time.new(2000, 1, 1, 5, 30, 0, '+05:30')
5151

5252
# PG produces: "2022-11-11 23:38:59+01"
53-
it_behaves_like ATimestamp, 'Europe/Lisbon', '2022-11-11 23:38:59+01', Time.new(2022, 11, 11, 23, 38, BigDecimal('59'), '+01:00')
53+
it_behaves_like ATimestamp, 'Europe/Lisbon', '2022-11-11 23:38:59+01', Time.new(2022, 11, 11, 23, 38, Rational('59'), '+01:00')
5454

5555
# PG produces: "infinity"
5656
it_behaves_like ATimestamp, 'UTC', 'infinity', 'infinity'

0 commit comments

Comments
 (0)