django.utils.timezone.datetime - python examples

Here are the examples of the python api django.utils.timezone.datetime taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

27 Examples 7

3 View Complete Implementation : test_models.py
Copyright MIT License
Author : aclowes
@mock.patch('yawn.workflow.models.Crontab')
def test_next_run(mock_cron):
    next_run = timezone.datetime(2011, 1, 1, tzinfo=pytz.UTC)
    mock_cron().next_run.return_value = next_run

    name = WorkflowName.objects.create(name='workflow1')
    workflow = Workflow.objects.create(
        name=name, version=2, schedule_active=True,
        schedule='*'
    )
    astert workflow.next_run == next_run

3 View Complete Implementation : atom_scraper.py
Copyright MIT License
Author : ben174
def parse_time(input_time):
    """Parse an Atom time stamp."""
    parsed = None
    try:
        parsed = timezone.make_aware(timezone.datetime(*input_time[:-3]),
                                     timezone.utc)
    except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
        added_hour = (timezone.datetime(*input_time[:-3]) +
                      datetime.timedelta(hours=1))
        parsed = timezone.make_aware(added_hour, timezone.utc)
    return parsed.astimezone(TZ)

3 View Complete Implementation : save.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@database_sync_to_async
def _do_mark_result_unchanged(
    workflow_id: int, wf_module: WfModule, now: timezone.datetime
) -> None:
    """
    Do database manipulations for mark_result_unchanged().

    Modify `wf_module` in-place.

    Raise WfModule.DoesNotExist or Workflow.DoesNotExist in case of a race.
    """
    with _locked_wf_module(workflow_id, wf_module):
        wf_module.is_busy = False
        wf_module.last_update_check = now
        wf_module.save(update_fields=["is_busy", "last_update_check"])

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_daily_price(self):
        start_date = timezone.datetime(2017, 7, 14)
        end_date = timezone.datetime(2017, 7, 31, 23, 59, 59)
        offering = support_factories.OfferingFactory(unit=common_mixins.UnitPriceMixin.Units.PER_DAY)
        with freeze_time(start_date):
            offering.state = support_models.Offering.States.OK
            offering.save(update_fields=['state'])

        expected_price = utils.get_full_days(start_date, end_date) * offering.unit_price
        offering_item = models.InvoiceItem.objects.get(scope=offering)
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_monthly_price(self):
        start_date = timezone.datetime(2017, 7, 20)
        month_days = monthrange(2017, 7)[1]
        usage_days = month_days - start_date.day + 1
        offering = support_factories.OfferingFactory(unit=common_mixins.UnitPriceMixin.Units.PER_MONTH)
        with freeze_time(start_date):
            offering.state = support_models.Offering.States.OK
            offering.save(update_fields=['state'])

        expected_price = offering.unit_price * quantize_price(decimal.Decimal((usage_days / month_days)))
        offering_item = models.InvoiceItem.objects.get(scope=offering)
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_half_monthly_price_with_start_in_first_half(self):
        start_date = timezone.datetime(2017, 7, 14)
        usage_days = 2
        offering = support_factories.OfferingFactory(unit=common_mixins.UnitPriceMixin.Units.PER_HALF_MONTH)
        with freeze_time(start_date):
            offering.state = support_models.Offering.States.OK
            offering.save(update_fields=['state'])

        month_days = monthrange(2017, 7)[1]
        expected_price = offering.unit_price * quantize_price(1 + (usage_days / decimal.Decimal(month_days / 2)))
        offering_item = models.InvoiceItem.objects.get(scope=offering)
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_half_monthly_price_with_start_in_second_half(self):
        start_date = timezone.datetime(2017, 7, 16)
        offering = support_factories.OfferingFactory(unit=common_mixins.UnitPriceMixin.Units.PER_HALF_MONTH)
        with freeze_time(start_date):
            offering.state = support_models.Offering.States.OK
            offering.save(update_fields=['state'])

        expected_price = offering.unit_price
        offering_item = models.InvoiceItem.objects.get(scope=offering)
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_half_monthly_price_with_end_in_first_half(self):
        start_date = timezone.datetime(2017, 7, 10)
        end_date = timezone.datetime(2017, 7, 14)
        usage_days = 5
        offering, offering_item = self._start_end_offering(start_date, end_date)
        month_days = monthrange(2017, 7)[1]
        expected_price = offering.unit_price * quantize_price(usage_days / decimal.Decimal(month_days / 2))
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_half_monthly_price_with_end_in_second_half(self):
        start_date = timezone.datetime(2017, 7, 10)
        end_date = timezone.datetime(2017, 7, 20)
        usage_days = 11
        offering, offering_item = self._start_end_offering(start_date, end_date)
        month_days = monthrange(2017, 7)[1]
        expected_price = offering.unit_price * quantize_price(usage_days / decimal.Decimal(month_days / 2))
        self.astertEqual(offering_item.price, expected_price)

3 View Complete Implementation : test_invoice_price_workflow.py
Copyright MIT License
Author : opennode
    def test_invoice_item_with_both_halves(self):
        start_date = timezone.datetime(2017, 7, 1)
        month_days = monthrange(2017, 7)[1]
        end_date = timezone.datetime(2017, 7, month_days)
        offering, offering_item = self._start_end_offering(start_date, end_date)
        expected_price = offering.unit_price * 2
        self.astertEqual(offering_item.price, expected_price)