Пример #1
0
 def test_repr(self):
     d = DateTime('1/1/2001')
     assert repr(d) == "DateTime('01/01/2001 00:00:00')", \
            "wrong __repr__ from datetime"
     d = DateTime('1/1/2001 12:34:56')
     assert repr(d) == "DateTime('01/01/2001 12:34:56')", \
            "wrong __repr__ from datetime"
Пример #2
0
 def test_mxDate(self):
     try:
         import mx
         dtNow = DateTime("1/1/2000")
         mxNow = dtNow.toMx()
         assert mxNow == mx.DateTime.DateTime(2000,1,1)
     except ImportError:
         print "[mxDate not installed, skipping test...]"
Пример #3
0
 def test_to_datetime(self):
     try:
         import datetime
         dtNow = DateTime("1/1/2000")
         pyNow = dtNow.to_datetime()
         assert pyNow == datetime.datetime(2000, 1, 1)
     except ImportError:
         print "[mxDate not installed, skipping test...]"
Пример #4
0
 def test_mxDate(self):
     try:
         import mx
         dtNow = DateTime("1/1/2000")
         mxNow = dtNow.toMx()
         assert mxNow == mx.DateTime.DateTime(2000, 1, 1)
     except ImportError:
         print "[mxDate not installed, skipping test...]"
Пример #5
0
 def test_to_datetime(self):
     try:
         import datetime
         dtNow = DateTime("1/1/2000")
         pyNow = dtNow.to_datetime()
         assert pyNow == datetime.datetime(2000,1,1)
     except ImportError:
         print "[mxDate not installed, skipping test...]"
Пример #6
0
 def test_comparisons(self):
     assert DateTime("06/20/1950 08:30:00") \
            == "1950-6-20 8:30:00", "eq string compare"
     assert DateTime("01/01/2001 00:00:00") \
            == Date("01/01/2001"), "eq comparison"
     assert Date("2001-5-1") <= DateTime("5/1/2001 0:0:0"), \
            "le comparison"
     assert Date("5/1/2001") < DateTime("2001-5-1 00:00:01"), \
            "lt comparison"
Пример #7
0
def newEvent(event, acct=None, posted=None, note=None, amount=None):
    e = Event()
    e.account = acct or None
    e.event = event
    if type(posted) == type(""):
        e.posted = DateTime(posted)
    elif isinstance(posted, DateTime) or isinstance(posted, Date):
        e.posted = posted
    elif not posted:
        e.posted = DateTime("now")
    else:
        raise TypeError, "Event posted with illegal DateTime type"
    e.amount = amount or FixedPoint("0.00")
    e.note = note or ""
    return e
Пример #8
0
 def test_todayandnow(self):
     """
     temporarily set time.time() to return 10/19/2001
     and test for today.
     """
     import time
     _time = time.time
     time.time = lambda: 1003539807.89
     try:
         assert DateTime("today") == DateTime("10/19/2001 00:00:00"), \
                "wrong date from today"
         assert DateTime("now") == DateTime("10/19/2001 21:03:27"), \
                "wrong date or time from now"
     finally:
         time.time = _time
Пример #9
0
    def test_openBalance(self):

        assert Statement(self.acc).openBal == 0
        assert Statement(self.acc).closeBal == 0
        self.acc.events << duckbill.newEvent(
            "charge", amount=5, posted=DateTime("now"))
        assert Statement(self.acc).openBal == 0, \
                "Expected opening balance of 0, got %s" % Statement(self.acc).openBal
        assert Statement(self.acc, start=Date("today"), end=Date("today")+1).closeBal == 5, \
                "Expected closing balance of 5, got %s" \
                % Statement(self.acc, end=Date("today")+1).closeBal
Пример #10
0
"""
duckbill - a python billing system
"""
__ver__ = "$Id: __init__.py,v 1.32 2006/07/02 06:08:09 sabren Exp $"
__release__ = "0.1"

from pytypes import Date, DateTime

TODAY = Date("today")
NOW = DateTime("now")

from Event import Event
from Grace import Grace
from Cyclic import Cyclic
from EncryptedCard import EncryptedCard
from Subscription import Subscription
from Statement import Statement
from Account import Account
from FrontEndApp import FrontEndApp
from Receivables import Receivables

import time
from pytypes import FixedPoint
import config

#@TODO: consolidate this db map with the one in .weblib.py
dbTables = {
    Account: "bill_account",
    Subscription: "bill_subscription",
    Event: "bill_event",
}
Пример #11
0
 def test_subtract(self):
     assert DateTime("1/2/2001") - 1 \
            == DateTime("1/1/2001"), \
            "normal subtract didn't work."
     assert DateTime("2/1/2001") - 1 \
            == DateTime("1/31/2001"), \
            "end of month didn't work"
     assert DateTime("3/1/2001 1:2:3") - 1 \
            == DateTime("2/28/2001 1:2:3"), \
            "end of month didn't work for february"
     assert DateTime("1/1/2002 0:0:0") - 1 \
            == DateTime("12/31/2001 0:0:0"), \
            "new year didn't work."
     assert DateTime("3/3/2001 23:59:59") - 31 \
            == DateTime("1/31/2001 23:59:59"), \
            "subtracting more than a month didn't work"
     assert DateTime("1/2/2002 1:23:45") - 366 \
            == DateTime("1/1/2001 1:23:45"), \
            "subtracting more than a year didn't work"
Пример #12
0
 def test_add(self):
     assert DateTime("1/1/2001 1:23:45") + 1 \
            == DateTime("1/2/2001 1:23:45"), \
            "normal add didn't work."
     assert DateTime("1/31/2001 23:59:59") + 1 \
            == DateTime("2/1/2001 23:59:59"), \
            "end of month didn't work"
     assert DateTime("2/28/2001 0:0:01") + 1 \
            == DateTime("3/1/2001 0:0:01"), \
            "end of month didn't work for february"
     assert DateTime("2/28/2001 1:2:3") + 11 \
            == DateTime("3/11/2001 1:2:3"), \
            "end of month + big number didn't work"
     assert DateTime("12/31/2001 00:00:01") + 1 \
            == DateTime("1/1/2002 0:0:1"), \
            "new year didn't work"
     assert DateTime("1/31/2001 12:00:00") + 31 \
            == DateTime("3/3/2001 12:00:00"), \
            "adding more than a month didn't work"
     assert DateTime("1/1/2001 12:00:00") + 366 \
            == DateTime("1/2/2002 12:00:00"), \
            "adding more than a year didn't work"
Пример #13
0
 def save_sale(self):
     sed = zikeshop.SaleEditor(zikeshop.Sale, self.input.get("ID"))
     # new sales get a timestamp:
     if not self.input.get("ID"):
         sed.input["tsSold"] = DateTime("now")
     sed.act("save")
Пример #14
0
# @TODO: get rid of this
class Topic(Strongbox):
    ID = attr(long, default=auto)
    topic = attr(str)
    comments = linkset(Comment, "topic")


class TagTest(unittest.TestCase):
    def test(self):
        s = Story(csvtags=" apples, banANA CREME pie, etc.")
        assert s.tags == ["apples", "banana creme pie", "etc."]
        s = Story()
        assert s.tags == []


now = DateTime("now")
DEFAULTURL = "rants/%s/%02i/" % (now.y, now.m)


class Story(Strongbox):
    """
    A document, blog entry, or other text.
    """
    ID = attr(long, default=auto)
    channel = link(lambda: Channel)
    category = link(lambda: Category)
    posted = attr(DateTime, default="now")
    status = attr(str, okay=['published', 'draft'])
    title = attr(str)
    url = attr(str, default=DEFAULTURL)
    description = attr(str)
Пример #15
0
 def test_daysInYear(self):
     assert DateTime("1/1/1999").daysInYear() == 365
     assert DateTime("1/1/2000").daysInYear() == 366  # leap year
     assert DateTime("1/1/2001").daysInYear() == 365
Пример #16
0
 def test_daysInMonth(self):
     assert DateTime("1/1/2001").daysInMonth() == 31
     assert DateTime("2/1/2001").daysInMonth() == 28
     assert DateTime("2/1/2000").daysInMonth() == 29
Пример #17
0
 def test_convert(self):
     assert Date("1/2/2002") == DateTime("1/2/2002 0:0:0")