|
66 | 66 | ensure
|
67 | 67 | connection.close
|
68 | 68 | end
|
| 69 | + |
| 70 | + it "can get timestamps with microseconds and tz" do |
| 71 | + [{ |
| 72 | + # PG produces: "2022-11-11 12:38:59.123456+00" |
| 73 | + zone: 'UTC', |
| 74 | + time: '2022-11-11 23:38:59.123456+11', |
| 75 | + result: Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+11:00'), |
| 76 | + }, { |
| 77 | + # PG produces: "2022-11-11 12:38:59+00" |
| 78 | + zone: 'UTC', |
| 79 | + time: '2022-11-11 23:38:59+11', |
| 80 | + result: Time.new(2022, 11, 11, 23, 38, BigDecimal('59'), '+11:00'), |
| 81 | + }, { |
| 82 | + # PG produces: "2022-11-11 23:38:59.123456+00" |
| 83 | + zone: 'UTC', |
| 84 | + time: '2022-11-11 23:38:59.123456', |
| 85 | + result: Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+00:00'), |
| 86 | + }, { |
| 87 | + # PG produces: "2022-11-11 23:38:59+11" |
| 88 | + zone: 'Australia/Sydney', |
| 89 | + time: '2022-11-11 23:38:59', |
| 90 | + result: Time.new(2022, 11, 11, 23, 38, BigDecimal('59'), '+11:00'), |
| 91 | + }, { |
| 92 | + # PG produces: "2022-11-12 06:08:59.123456+11" |
| 93 | + zone: 'Australia/Sydney', |
| 94 | + time: '2022-11-11 23:38:59.123456+04:30', |
| 95 | + result: Time.new(2022, 11, 11, 23, 38, BigDecimal('59.123456'), '+04:30'), |
| 96 | + }, { |
| 97 | + # PG produces: "2000-01-01 05:30:00+05:30" |
| 98 | + zone: 'Asia/Kolkata', |
| 99 | + time: '2000-01-01 00:00:00+00', |
| 100 | + result: Time.new(2000, 1, 1, 5, 30, 0, '+05:30'), |
| 101 | + }].each do |spec| |
| 102 | + |
| 103 | + connection.send_query("SET TIME ZONE '#{spec[:zone]}'"); |
| 104 | + connection.send_query("SELECT '#{spec[:time]}'::TIMESTAMPTZ AS TS") |
| 105 | + |
| 106 | + result = connection.next_result |
| 107 | + row = result.to_a.first |
| 108 | + |
| 109 | + expect(row.first).to be == spec[:result] |
| 110 | + end |
| 111 | + ensure |
| 112 | + connection.close |
| 113 | + end |
69 | 114 |
|
70 | 115 | describe '#append_string' do
|
71 | 116 | it "should escape string" do
|
|
0 commit comments