示例#1
0
文件: test_db.py 项目: Afey/pattern
 def test_time(self):
     # Assert Date + time().
     v = db.date("2010-09-21 9:27:00")
     v = v - db.time(days=1, hours=1, minutes=1, seconds=1)
     self.assertEqual(str(v), "2010-09-20 08:25:59")
     # Assert Date + time(years, months)
     v = db.date(2014, 1, 31)
     v = v + db.time(years=1, months=1)
     self.assertEqual(str(v), "2015-02-28 00:00:00")
     print("pattern.db.time()")
示例#2
0
文件: test_db.py 项目: pri-k/pattern
 def test_time(self):
     # Assert Date + time().
     v = db.date("2010-09-21 9:27:00")
     v = v - db.time(days=1, hours=1, minutes=1, seconds=1)
     self.assertEqual(str(v), "2010-09-20 08:25:59")
     # Assert Date + time(years, months)
     v = db.date(2014, 1, 31)
     v = v + db.time(years=1, months=1)
     self.assertEqual(str(v), "2015-02-28 00:00:00")
     print("pattern.db.time()")
示例#3
0
文件: test_db.py 项目: sp00/pattern
 def test_group(self):
     # Assert WHERE with AND/OR combinations from Group object().
     yesterday  = db.date()
     yesterday -= db.time(days=1)
     g1 = db.Group(("name", "garlic bread"))
     g2 = db.Group(("name", "pizza"), ("price", 10, "<"), operator=db.AND)
     g3 = db.Group(g1, g2, operator=db.OR)
     g4 = db.Group(g3, ("date", yesterday, ">"), operator=db.AND)
     self.assertEqual(g1.SQL(), "name='garlic bread'")
     self.assertEqual(g2.SQL(), "name='pizza' and price<10")
     self.assertEqual(g3.SQL(), "(name='garlic bread') or (name='pizza' and price<10)")
     self.assertEqual(g4.SQL(), "((name='garlic bread') or (name='pizza' and price<10)) and date>'%s'" % yesterday)
     # Assert subquery in group.
     q = self._query(fields=["name"])
     g = db.any(("name", u"Gödel"), ("name", q))
     self.assertEqual(g.SQL(), u"name='Gödel' or name in (select persons.name from `persons`)")
     print "pattern.db.Group"
示例#4
0
文件: test_db.py 项目: Afey/pattern
 def test_filterchain(self):
     # Assert WHERE with AND/OR combinations from FilterChain object().
     yesterday  = db.date()
     yesterday -= db.time(days=1)
     f1 = db.FilterChain(("name", "garlic bread"))
     f2 = db.FilterChain(("name", "pizza"), ("price", 10, "<"), operator=db.AND)
     f3 = db.FilterChain(f1, f2, operator=db.OR)
     f4 = db.FilterChain(f3, ("date", yesterday, ">"), operator=db.AND)
     self.assertEqual(f1.SQL(), "name='garlic bread'")
     self.assertEqual(f2.SQL(), "name='pizza' and price<10")
     self.assertEqual(f3.SQL(), "(name='garlic bread') or (name='pizza' and price<10)")
     self.assertEqual(f4.SQL(), "((name='garlic bread') or (name='pizza' and price<10)) and date>'%s'" % yesterday)
     # Assert subquery in filter chain.
     q = self._query(fields=["name"])
     f = db.any(("name", u"Gödel"), ("name", q))
     self.assertEqual(f.SQL(), u"name='Gödel' or name in (select persons.name from `persons`)")
     print("pattern.db.FilterChain")
示例#5
0
文件: test_db.py 项目: Jsa542/pattern
 def test_filterchain(self):
     # Assert WHERE with AND/OR combinations from FilterChain object().
     yesterday  = db.date()
     yesterday -= db.time(days=1)
     f1 = db.FilterChain(("name", "garlic bread"))
     f2 = db.FilterChain(("name", "pizza"), ("price", 10, "<"), operator=db.AND)
     f3 = db.FilterChain(f1, f2, operator=db.OR)
     f4 = db.FilterChain(f3, ("date", yesterday, ">"), operator=db.AND)
     self.assertEqual(f1.SQL(), "name='garlic bread'")
     self.assertEqual(f2.SQL(), "name='pizza' and price<10")
     self.assertEqual(f3.SQL(), "(name='garlic bread') or (name='pizza' and price<10)")
     self.assertEqual(f4.SQL(), "((name='garlic bread') or (name='pizza' and price<10)) and date>'%s'" % yesterday)
     # Assert subquery in filter chain.
     q = self._query(fields=["name"])
     f = db.any(("name", u"Gödel"), ("name", q))
     self.assertEqual(f.SQL(), u"name='Gödel' or name in (select persons.name from `persons`)")
     print "pattern.db.FilterChain"
示例#6
0
文件: test_db.py 项目: sp00/pattern
 def test_time(self):
     # Assert Date + time().
     v = db.date("2010-09-21 9:27:00")
     v = v - db.time(days=1, hours=1, minutes=1, seconds=1)
     self.assertEqual(str(v), "2010-09-20 08:25:59")
     print "pattern.db.time()"
示例#7
0
文件: 03-date.py 项目: clips/pattern
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))

from pattern.db import date, time, NOW
from pattern.web import Bing, NEWS

# It is often useful to keep a date stamp for each row in the table.
# The pattern.db module's date() function can be used for this.
# It is a simple wrapper around Python's datetime.datetime class,
# with extra functionality to make it easy to parse or print it as a string.

print(date(NOW))
print(date())
print(date("2010-11-01 16:30", "%Y-%m-%d %H:%M"))
print(date("Nov 1, 2010", "%b %d, %Y"))
print(date("Nov 1, 2010", "%b %d, %Y", format="%d/%m/%Y"))
print("")

# All possible formatting options:
# http://docs.python.org/library/time.html#time.strftime

for r in Bing(license=None, language="en").search("today", type=NEWS):
    print(r.title)
    print(repr(r.date))  # Result.date is a string (e.g. we can't > <= += with the date).
    print(date(r.date))  # date() can parse any Result.date in the web module.
    print("")

d = date("4 november 2011")
d += time(days=2, hours=5)
print(d)
示例#8
0
from pattern.db import date, time, NOW
from pattern.web import Bing, NEWS

# It is often useful to keep a date stamp for each row in the table.
# The pattern.db module's date() function can be used for this.
# It is a simple wrapper around Python's datetime.datetime class,
# with extra functionality to make it easy to parse or print it as a string.

print date(NOW)
print date()
print date("2010-11-01 16:30", "%Y-%m-%d %H:%M")
print date("Nov 1, 2010", "%b %d, %Y")
print date("Nov 1, 2010", "%b %d, %Y", format="%d/%m/%Y")
print

# All possible formatting options:
# http://docs.python.org/library/time.html#time.strftime

for r in Bing(license=None, language="en").search("today", type=NEWS):
    print r.title
    print repr(
        r.date
    )  # Result.date is a string (e.g. we can't > <= += with the date).
    print date(r.date)  # date() can parse any Result.date in the web module.
    print

d = date("4 november 2011")
d += time(days=2, hours=5)
print d