我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用psycopg2.extras.DateTimeRange()。
def test_cast_timestamp(self): from psycopg2.extras import DateTimeRange cur = self.conn.cursor() ts1 = datetime(2000, 1, 1) ts2 = datetime(2000, 12, 31, 23, 59, 59, 999) cur.execute("select tsrange(%s, %s, '()')", (ts1, ts2)) r = cur.fetchone()[0] self.assertTrue(isinstance(r, DateTimeRange)) self.assertTrue(not r.isempty) self.assertEqual(r.lower, ts1) self.assertEqual(r.upper, ts2) self.assertTrue(not r.lower_inf) self.assertTrue(not r.upper_inf) self.assertTrue(not r.lower_inc) self.assertTrue(not r.upper_inc)
def test_adapt_date_range(self): from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange from psycopg2.tz import FixedOffsetTimezone cur = self.conn.cursor() d1 = date(2012, 0o1, 0o1) d2 = date(2012, 12, 31) r = DateRange(d1, d2) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateRange)) self.assertEqual(r1.lower, d1) self.assertEqual(r1.upper, d2) self.assertTrue(r1.lower_inc) self.assertTrue(not r1.upper_inc) r = DateTimeRange(empty=True) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateTimeRange)) self.assertTrue(r1.isempty) ts1 = datetime(2000, 1, 1, tzinfo=FixedOffsetTimezone(600)) ts2 = datetime(2000, 12, 31, 23, 59, 59, 999, tzinfo=FixedOffsetTimezone(600)) r = DateTimeTZRange(ts1, ts2, '(]') cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateTimeTZRange)) self.assertEqual(r1.lower, ts1) self.assertEqual(r1.upper, ts2) self.assertTrue(not r1.lower_inc) self.assertTrue(r1.upper_inc)
def test_cast_timestamp(self): from psycopg2.extras import DateTimeRange cur = self.conn.cursor() ts1 = datetime(2000, 1, 1) ts2 = datetime(2000, 12, 31, 23, 59, 59, 999) cur.execute("select tsrange(%s, %s, '()')", (ts1, ts2)) r = cur.fetchone()[0] self.assert_(isinstance(r, DateTimeRange)) self.assert_(not r.isempty) self.assertEqual(r.lower, ts1) self.assertEqual(r.upper, ts2) self.assert_(not r.lower_inf) self.assert_(not r.upper_inf) self.assert_(not r.lower_inc) self.assert_(not r.upper_inc)
def test_adapt_date_range(self): from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange from psycopg2.tz import FixedOffsetTimezone cur = self.conn.cursor() d1 = date(2012, 01, 01) d2 = date(2012, 12, 31) r = DateRange(d1, d2) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateRange)) self.assertEqual(r1.lower, d1) self.assertEqual(r1.upper, d2) self.assert_(r1.lower_inc) self.assert_(not r1.upper_inc) r = DateTimeRange(empty=True) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateTimeRange)) self.assert_(r1.isempty) ts1 = datetime(2000, 1, 1, tzinfo=FixedOffsetTimezone(600)) ts2 = datetime(2000, 12, 31, 23, 59, 59, 999, tzinfo=FixedOffsetTimezone(600)) r = DateTimeTZRange(ts1, ts2, '(]') cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateTimeTZRange)) self.assertEqual(r1.lower, ts1) self.assertEqual(r1.upper, ts2) self.assert_(not r1.lower_inc) self.assert_(r1.upper_inc)
def test_cast_timestamp(self): from psycopg2.extras import DateTimeRange cur = self.conn.cursor() ts1 = datetime(2000,1,1) ts2 = datetime(2000,12,31,23,59,59,999) cur.execute("select tsrange(%s, %s, '()')", (ts1, ts2)) r = cur.fetchone()[0] self.assert_(isinstance(r, DateTimeRange)) self.assert_(not r.isempty) self.assertEqual(r.lower, ts1) self.assertEqual(r.upper, ts2) self.assert_(not r.lower_inf) self.assert_(not r.upper_inf) self.assert_(not r.lower_inc) self.assert_(not r.upper_inc)
def test_adapt_date_range(self): from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange from psycopg2.tz import FixedOffsetTimezone cur = self.conn.cursor() d1 = date(2012, 01, 01) d2 = date(2012, 12, 31) r = DateRange(d1, d2) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateRange)) self.assertEqual(r1.lower, d1) self.assertEqual(r1.upper, d2) self.assert_(r1.lower_inc) self.assert_(not r1.upper_inc) r = DateTimeRange(empty=True) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateTimeRange)) self.assert_(r1.isempty) ts1 = datetime(2000,1,1, tzinfo=FixedOffsetTimezone(600)) ts2 = datetime(2000,12,31,23,59,59,999, tzinfo=FixedOffsetTimezone(600)) r = DateTimeTZRange(ts1, ts2, '(]') cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assert_(isinstance(r1, DateTimeTZRange)) self.assertEqual(r1.lower, ts1) self.assertEqual(r1.upper, ts2) self.assert_(not r1.lower_inc) self.assert_(r1.upper_inc)
def test_cast_timestamp(self): from psycopg2.extras import DateTimeRange cur = self.conn.cursor() ts1 = datetime(2000,1,1) ts2 = datetime(2000,12,31,23,59,59,999) cur.execute("select tsrange(%s, %s, '()')", (ts1, ts2)) r = cur.fetchone()[0] self.assertTrue(isinstance(r, DateTimeRange)) self.assertTrue(not r.isempty) self.assertEqual(r.lower, ts1) self.assertEqual(r.upper, ts2) self.assertTrue(not r.lower_inf) self.assertTrue(not r.upper_inf) self.assertTrue(not r.lower_inc) self.assertTrue(not r.upper_inc)
def test_adapt_date_range(self): from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange from psycopg2.tz import FixedOffsetTimezone cur = self.conn.cursor() d1 = date(2012, 0o1, 0o1) d2 = date(2012, 12, 31) r = DateRange(d1, d2) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateRange)) self.assertEqual(r1.lower, d1) self.assertEqual(r1.upper, d2) self.assertTrue(r1.lower_inc) self.assertTrue(not r1.upper_inc) r = DateTimeRange(empty=True) cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateTimeRange)) self.assertTrue(r1.isempty) ts1 = datetime(2000,1,1, tzinfo=FixedOffsetTimezone(600)) ts2 = datetime(2000,12,31,23,59,59,999, tzinfo=FixedOffsetTimezone(600)) r = DateTimeTZRange(ts1, ts2, '(]') cur.execute("select %s", (r,)) r1 = cur.fetchone()[0] self.assertTrue(isinstance(r1, DateTimeTZRange)) self.assertEqual(r1.lower, ts1) self.assertEqual(r1.upper, ts2) self.assertTrue(not r1.lower_inc) self.assertTrue(r1.upper_inc)