当前位置: 首页>>代码示例>>Python>>正文


Python utils.add_timezone函数代码示例

本文整理汇总了Python中timepiece.utils.add_timezone函数的典型用法代码示例。如果您正苦于以下问题:Python add_timezone函数的具体用法?Python add_timezone怎么用?Python add_timezone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_timezone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invoice_confirm_rounding

    def test_invoice_confirm_rounding(self):
        """Verify that the per activity totals are rounded correctly."""
        ACTIVITY_NAME = 'activity_n'
        # Make a few extra entries to test per activity totals
        start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8, 0, 0))
        end = utils.add_timezone(datetime.datetime(2011, 1, 1, 8, 3, 1))
        # 3m1s = 0.05166667h
        # 0.05166667 rounds to 0.05, at two decimal places
        # 0.05 * 5 = 0.25
        # 0.05166667 * 5 = 0.25833335
        # 0.25833335 rounds to 0.26, at two decimal places
        # If rounding happens before summation, then the total will be 0.25
        # If rounding happens after summation, then the total will be 0.26

        activity = factories.Activity(billable=True, name=ACTIVITY_NAME)
        for num in range(0, 5):
            factories.Entry(
                user=self.user, project=self.project_billable,
                start_time=start - relativedelta(days=num),
                end_time=end - relativedelta(days=num),
                status=Entry.APPROVED, activity=activity)
        self.make_hourgroups()
        to_date = datetime.datetime(2011, 1, 31)
        kwargs = {
            'project': self.project_billable.id,
            'to_date': to_date.strftime(DATE_FORM_FORMAT),
        }
        url = self.get_create_url(**kwargs)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        for name, hours_activities in response.context['billable_totals']:
            total, activities = hours_activities
            if name == ACTIVITY_NAME:
                self.assertEqual(total, 0.25)
                self.assertNotAlmostEqual(float(total), 0.26, places=2)
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:35,代码来源:test_invoices.py

示例2: test_approved

 def test_approved(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     unapproved_entry_a = factories.Entry(user=self.user,
         project=self.project_non_billable,
         start_time=start + relativedelta(hours=11),
         end_time=end + relativedelta(hours=15), status=Entry.VERIFIED
     )
     unapproved_entry_b = factories.Entry(user=self.user,
         project=self.project_non_billable,
         start_time=start + relativedelta(hours=11),
         end_time=end + relativedelta(hours=15), status=Entry.VERIFIED
     )
     response = self._get()
     self.assertEquals(response.status_code, 200)
     form = response.context['form']
     self.assertTrue(form.is_valid(), form.errors)
     unverified = set(response.context['unverified'])
     unapproved = set(response.context['unapproved'])
     user_a, user_b = unapproved_entry_a.user, unapproved_entry_b.user
     expected_unapproved = set([
         (user_a.pk, user_a.first_name, user_a.last_name),
         (user_b.pk, user_b.first_name, user_b.last_name),
     ])
     self.assertEquals(unverified, set())
     self.assertEquals(unapproved, expected_unapproved)
开发者ID:Focus3D,项目名称:django-timepiece,代码行数:26,代码来源:test_invoices.py

示例3: testWeeklyOvertimes

    def testWeeklyOvertimes(self):
        """Date_trunc on week should result in correct overtime totals"""
        dates = self.dates
        for day_num in xrange(28, 31):
            dates.append(utils.add_timezone(
                datetime.datetime(2011, 4, day_num)
            ))
        for day_num in xrange(5, 9):
            dates.append(utils.add_timezone(
                datetime.datetime(2011, 5, day_num)
            ))
        for day in dates:
            self.make_logs(day)

        def check_overtime(week0=Decimal('55.00'), week1=Decimal('55.00'),
                           overtime=Decimal('30.00')):
            self.client.login(username='superuser', password='abc')
            response = self.client.get(self.url, self.args)
            weekly_totals = response.context['weekly_totals'][0][0][0][2]
            self.assertEqual(weekly_totals[0], week0)
            self.assertEqual(weekly_totals[1], week1)
            self.assertEqual(weekly_totals[5], overtime)
        check_overtime()
        #Entry on following Monday doesn't add to week1 or overtime
        self.make_logs(utils.add_timezone(datetime.datetime(2011, 5, 9)))
        check_overtime()
        #Entries in previous month before last_billable do not change overtime
        self.make_logs(utils.add_timezone(datetime.datetime(2011, 4, 24)))
        check_overtime()
        #Entry in previous month after last_billable change week0 and overtime
        self.make_logs(utils.add_timezone(
            datetime.datetime(2011, 4, 25, 1, 0)
        ))
        check_overtime(Decimal('66.00'), Decimal('55.00'), Decimal('41.00'))
开发者ID:antonlopatin,项目名称:django-timepiece,代码行数:34,代码来源:payroll.py

示例4: bulk_entries

 def bulk_entries(self, start=datetime.datetime(2011, 1, 2), end=datetime.datetime(2011, 1, 4)):
     start = utils.add_timezone(start)
     end = utils.add_timezone(end)
     dates = utils.generate_dates(start, end, "day")
     projects = [self.p1, self.p2, self.p2, self.p4, self.p5, self.sick]
     self.make_entries(projects=projects, dates=dates, user=self.user, hours=2)
     self.make_entries(projects=projects, dates=dates, user=self.user2, hours=1)
开发者ID:gtp,项目名称:django-timepiece,代码行数:7,代码来源:reports.py

示例5: setUp

 def setUp(self):
     super(InvoiceCreateTestCase, self).setUp()
     self.user = factories.Superuser()
     self.login_user(self.user)
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     self.project_billable = factories.BillableProject()
     self.project_billable2 = factories.BillableProject()
     self.project_non_billable = factories.NonbillableProject()
     self.entry1 = factories.Entry(
         user=self.user, project=self.project_billable,
         activity=factories.Activity(billable=True),
         start_time=start, end_time=end, status=Entry.APPROVED)
     self.entry2 = factories.Entry(
         user=self.user, project=self.project_billable,
         activity=factories.Activity(billable=True),
         start_time=start - relativedelta(days=5),
         end_time=end - relativedelta(days=5), status=Entry.APPROVED)
     self.entry3 = factories.Entry(
         user=self.user, project=self.project_billable2,
         activity=factories.Activity(billable=False),
         start_time=start - relativedelta(days=10),
         end_time=end - relativedelta(days=10), status=Entry.APPROVED)
     self.entry4 = factories.Entry(
         user=self.user, project=self.project_non_billable,
         start_time=start + relativedelta(hours=11),
         end_time=end + relativedelta(hours=15), status=Entry.APPROVED)
开发者ID:robmoggach,项目名称:django-timepiece,代码行数:27,代码来源:test_invoices.py

示例6: testWeeklyTotal

 def testWeeklyTotal(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 3))
     end = utils.add_timezone(datetime.datetime(2011, 1, 6))
     self.bulk_entries(start, end)
     trunc = 'week'
     date_headers = utils.generate_dates(start, end, trunc)
     pj_totals = self.get_project_totals(date_headers, trunc)
     self.assertEqual(pj_totals[0][0], [48])
     self.assertEqual(pj_totals[0][1], [24])
     self.assertEqual(pj_totals[1], [72])
开发者ID:eschipul,项目名称:django-timepiece,代码行数:10,代码来源:reports.py

示例7: argsHelper

 def argsHelper(self, args={}, start=datetime.datetime(2011, 1, 2),
                end=datetime.datetime(2011, 1, 4)):
     start = utils.add_timezone(start)
     end = utils.add_timezone(end)
     args.update({
         'from_date': start.strftime('%m/%d/%Y'),
         'to_date': end.strftime('%m/%d/%Y'),
         'export': True,
     })
     return args
开发者ID:eschipul,项目名称:django-timepiece,代码行数:10,代码来源:reports.py

示例8: testDailyTotal

 def testDailyTotal(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1))
     day2 = utils.add_timezone(datetime.datetime(2011, 1, 2))
     end = utils.add_timezone(datetime.datetime(2011, 1, 3))
     self.log_daily(start, day2, end)
     trunc = "day"
     date_headers = utils.generate_dates(start, end, trunc)
     pj_totals = self.get_project_totals(date_headers, trunc)
     self.assertEqual(pj_totals[0][0], [Decimal("1.00"), Decimal("1.50"), ""])
     self.assertEqual(pj_totals[0][1], ["", Decimal("3.00"), Decimal("2.00")])
     self.assertEqual(pj_totals[1], [Decimal("1.00"), Decimal("4.50"), Decimal("2.00")])
开发者ID:gtp,项目名称:django-timepiece,代码行数:11,代码来源:reports.py

示例9: args_helper

 def args_helper(self, **kwargs):
     start = utils.add_timezone(kwargs.pop('start', datetime.datetime(2011, 1, 2)))
     end = utils.add_timezone(kwargs.pop('end', datetime.datetime(2011, 1, 4)))
     defaults = {
         'from_date': start.strftime('%Y-%m-%d'),
         'to_date': end.strftime('%Y-%m-%d'),
         'export_users': True,
         'billable': True,
         'non_billable': True,
         'paid_leave': True,
         'trunc': 'week',
     }
     defaults.update(kwargs)
     return defaults
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:14,代码来源:test_hourly.py

示例10: testDailyTotal

 def testDailyTotal(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1))
     day2 = utils.add_timezone(datetime.datetime(2011, 1, 2))
     end = utils.add_timezone(datetime.datetime(2011, 1, 3))
     self.log_daily(start, day2, end)
     trunc = 'day'
     date_headers = utils.generate_dates(start, end, trunc)
     pj_totals = self.get_project_totals(date_headers, trunc)
     self.assertEqual(pj_totals[0][0],
                      [Decimal('1.00'), Decimal('1.50'), ''])
     self.assertEqual(pj_totals[0][1],
                      ['', Decimal('3.00'), Decimal('2.00')])
     self.assertEqual(pj_totals[1],
                      [Decimal('1.00'), Decimal('4.50'), Decimal('2.00')])
开发者ID:eschipul,项目名称:django-timepiece,代码行数:14,代码来源:reports.py

示例11: testBillableNonBillable

 def testBillableNonBillable(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1))
     day2 = utils.add_timezone(datetime.datetime(2011, 1, 2))
     end = utils.add_timezone(datetime.datetime(2011, 1, 3))
     self.log_daily(start, day2, end)
     trunc = "day"
     billableQ = Q(project__type__billable=True)
     non_billableQ = Q(project__type__billable=False)
     date_headers = utils.generate_dates(start, end, trunc)
     pj_billable = self.get_project_totals(date_headers, trunc, Q(), "billable")
     pj_billable_q = self.get_project_totals(date_headers, trunc, billableQ, "total")
     pj_non_billable = self.get_project_totals(date_headers, trunc, Q(), "non_billable")
     pj_non_billable_q = self.get_project_totals(date_headers, trunc, non_billableQ, "total")
     self.assertEqual(list(pj_billable), list(pj_billable_q))
     self.assertEqual(list(pj_non_billable), list(pj_non_billable_q))
开发者ID:gtp,项目名称:django-timepiece,代码行数:15,代码来源:reports.py

示例12: test_make_invoice

 def test_make_invoice(self):
     to_date = utils.add_timezone(datetime.datetime(2011, 1, 31))
     kwargs = {
         'project': self.project_billable.id,
         'to_date': to_date.strftime(DATE_FORM_FORMAT),
     }
     url = self.get_create_url(**kwargs)
     response = self.client.post(url, {
         'number': '3',
         'status': EntryGroup.INVOICED,
     })
     self.assertEqual(response.status_code, 302)
     # Verify an invoice was created with the correct attributes
     invoice = EntryGroup.objects.get(number=3)
     self.assertEqual(invoice.project.id, self.project_billable.id)
     self.assertEqual(invoice.start, None)
     self.assertEqual(invoice.end.strftime('%Y %m %d'), '2011 01 31')
     self.assertEqual(len(invoice.entries.all()), 2)
     # Verify that the entries were invoiced appropriately
     # and the unrelated entries were untouched
     entries = Entry.objects.all()
     invoiced = entries.filter(status=EntryGroup.INVOICED)
     for entry in invoiced:
         self.assertEqual(entry.entry_group_id, invoice.id)
     approved = entries.filter(status=Entry.APPROVED)
     self.assertEqual(len(approved), 2)
     self.assertEqual(approved[0].entry_group_id, None)
开发者ID:robmoggach,项目名称:django-timepiece,代码行数:27,代码来源:test_invoices.py

示例13: grouped_totals

def grouped_totals(entries):
    select = {
        "day": {"date": """DATE_TRUNC('day', end_time)"""},
        "week": {"date": """DATE_TRUNC('week', end_time)"""},
    }
    weekly = entries.extra(select=select["week"]).values('date', 'billable')
    weekly = weekly.annotate(hours=Sum('hours')).order_by('date')
    daily = entries.extra(select=select["day"]).values('date', 'project__name',
                                                       'billable')
    daily = daily.annotate(hours=Sum('hours')).order_by('date',
                                                        'project__name')
    weeks = {}
    for week, week_entries in groupby(weekly, lambda x: x['date']):
        if week is not None:
            week = add_timezone(week)
        weeks[week] = get_hours_summary(week_entries)
    days = []
    last_week = None
    for day, day_entries in groupby(daily, lambda x: x['date']):
        week = get_week_start(day)
        if last_week and week > last_week:
            yield last_week, weeks.get(last_week, {}), days
            days = []
        days.append((day, daily_summary(day_entries)))
        last_week = week
    yield week, weeks.get(week, {}), days
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:26,代码来源:utils.py

示例14: generate_dates

def generate_dates(start=None, end=None, by='week'):
    if start:
        start = add_timezone(start)
    if end:
        end = add_timezone(end)
    if by == 'year':
        start = get_year_start(start)
        return rrule.rrule(rrule.YEARLY, dtstart=start, until=end)
    if by == 'month':
        start = get_month_start(start)
        return rrule.rrule(rrule.MONTHLY, dtstart=start, until=end)
    if by == 'week':
        start = get_week_start(start)
        return rrule.rrule(rrule.WEEKLY, dtstart=start, until=end, byweekday=0)
    if by == 'day':
        return rrule.rrule(rrule.DAILY, dtstart=start, until=end)
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:16,代码来源:utils.py

示例15: log_many

 def log_many(self, projects, num_entries=20, start=None, billable=True):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 0, 0, 0))
     for index in range(0, num_entries):
         start += relativedelta(hours=(5 * index))
         project = projects[index % len(projects)]  # Alternate projects
         self.log_time(start=start, status=Entry.APPROVED, project=project,
                       billable=billable)
     return start
开发者ID:robmoggach,项目名称:django-timepiece,代码行数:8,代码来源:test_invoices.py


注:本文中的timepiece.utils.add_timezone函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。