def as_date(date): """Convert a either date (or datetime) or a DateTime object to an xs.date object. """ if IDateTime.providedBy(date): return xs.date(date.year(), date.month(), date.day()) return xs.date(date.year, date.month, date.day)
def testFromText(self): self.verifyTime(xsd.date(' 2002-10-27'), with_usec=False, with_tzinfo=False) self.verifyTime(xsd.date('2002-10-27 '), with_usec=False, with_tzinfo=False) self.verifyTime(xsd.date('2002-10-27'), with_usec=False, with_tzinfo=False)
def test_as_date(self): """Test that different dates can be converted. """ self.assertEqual(xs.date(2010, 1, 1), transform.as_date(date(2010, 1, 1))) self.assertEqual(xs.date(2010, 1, 1), transform.as_date(datetime(2010, 1, 1, 20, 10, 1))) self.assertEqual(xs.date(2010, 1, 1), transform.as_date(DateTime(2010, 1, 1))) self.assertEqual(xs.date(2010, 1, 1), transform.as_date(DateTime(2010, 1, 1, 15, 2, 7)))
def testTimezoned (self): dt = xsd.date('2002-10-10Z') self.assertEqual('2002-10-10T00:00:00+00:00', dt.isoformat()) self.assertEqual('2002-10-10Z', dt.xsdLiteral()) dt = xsd.date('2002-10-10+13:00') self.assertEqual('2002-10-10T00:00:00+13:00', dt.isoformat()) self.assertEqual('2002-10-09-11:00', dt.xsdLiteral()) dt = xsd.date('2002-10-09-11:00') self.assertEqual('2002-10-09T00:00:00-11:00', dt.isoformat()) self.assertEqual('2002-10-09-11:00', dt.xsdLiteral()) dt = xsd.date('2002-10-10+14:00') self.assertEqual('2002-10-10T00:00:00+14:00', dt.isoformat()) self.assertEqual('2002-10-09-10:00', dt.xsdLiteral()) dt = xsd.date('2002-10-09-10:00') self.assertEqual('2002-10-09T00:00:00-10:00', dt.isoformat()) self.assertEqual('2002-10-09-10:00', dt.xsdLiteral()) dt = xsd.date('2002-10-10-14:00') self.assertEqual('2002-10-10T00:00:00-14:00', dt.isoformat()) self.assertEqual('2002-10-11+10:00', dt.xsdLiteral()) dt = xsd.date('2002-10-11+10:00') self.assertEqual('2002-10-11T00:00:00+10:00', dt.isoformat()) self.assertEqual('2002-10-11+10:00', dt.xsdLiteral())
from __future__ import print_function import pyxb import po4 import address import pyxb.binding.datatypes as xs po = po4.purchaseOrder(orderDate=xs.date(1999, 10, 20)) po.shipTo = address.USAddress('Alice Smith', '123 Maple Street', 'Anytown', 'AK', 12341) po.billTo = address.USAddress('Robert Smith', '8 Oak Avenue', 'Anytown', 'AK', 12341) po.items = pyxb.BIND(pyxb.BIND('Lapis necklace', 1, 99.95, partNum='833-AA'), pyxb.BIND('Plastic necklace', 4, 3.95, partNum='833-AB')) print(po.toxml("utf-8"))
# examples/manual/demo4c.py from __future__ import print_function import pyxb import po4 import address import pyxb.binding.datatypes as xs po = po4.purchaseOrder(orderDate=xs.date(1999, 10, 20)) po.shipTo = address.USAddress('Alice Smith', '123 Maple Street', 'Anytown', 'AK', 12341) po.billTo = address.USAddress('Robert Smith', '8 Oak Avenue', 'Anytown', 'AK', 12341) pyxb.RequireValidWhenGenerating(False) print(po.toxml("utf-8"))
def testDate (self): v = xsd.date(datetime.date.today()) c = copy.copy(v) self.assertEqual(c, v)
def testXsdLiteral (self): dt = xsd.date('2002-10-27') self.assertEqual('2002-10-27', dt.xsdLiteral())
def testArguments (self): self.assertRaises(TypeError, xsd.date) self.assertRaises(TypeError, xsd.date, 2002) self.assertRaises(TypeError, xsd.date, 2002, 10) self.verifyTime(xsd.date(2002, 10, 27), with_tzinfo=False)
def testFromText (self): self.verifyTime(xsd.date(' 2002-10-27', _from_xml=True), with_usec=False, with_tzinfo=False) self.verifyTime(xsd.date('2002-10-27 ', _from_xml=True), with_usec=False, with_tzinfo=False) self.verifyTime(xsd.date('2002-10-27'), with_usec=False, with_tzinfo=False)
def testDate(self): v = xsd.date(datetime.date.today()) c = copy.copy(v) self.assertEqual(c, v)
plan.active = True response = litleXml.sendRequest(plan) # Send subscription as a part of an auth auth = litleXmlFields.authorization() auth.orderId = '1' auth.amount = 1 auth.orderSource = 'ecommerce' auth.card = card recurring = litleXmlFields.recurringRequestType() subscription = litleXmlFields.recurringSubscriptionType() subscription.planCode = '3_Year_Monthly' subscription.numberOfPayments = 36 subscription.startDate = pdt.date(2016, 10, 20) subscription.amount = 1000 recurring.subscription = subscription auth.recurringRequest = recurring response = litleXml.sendRequest(auth) # Update subscription with discount update = litleXmlFields.updateSubscription() update.subscriptionId = response.recurringResponse.subscriptionId discount = litleXmlFields.createDiscountType() discount.discountCode = 'SUMMERSALE2016' discount.name = 'Discount Name' discount.amount = 1 discount.startDate = pdt.date(2016, 10, 20)
import pyxb import schema import pyxb.binding.datatypes as xs po = schema.purchaseOrder(orderDate=xs.date(1999, 10, 20)) #po.shipTo = address.USAddress('Alice Smith', '123 Maple Street', 'Anytown', 'AK', 12341) #po.billTo = address.USAddress('Robert Smith', '8 Oak Avenue', 'Anytown', 'AK', 12341) #po.items = pyxb.BIND(pyxb.BIND('Lapis necklace', 1, 99.95, partNum='833-AA'), # pyxb.BIND('Plastic necklace', 4, 3.95, partNum='833-AB')) print(po.toxml("utf-8").decode('utf-8'))