• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.add_timezone函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: setUp

 def setUp(self):
     super(PayrollTest, self).setUp()
     self.user = factories.User()
     self.user2 = factories.User()
     self.superuser = factories.Superuser()
     self.devl_activity = factories.Activity(billable=True)
     self.activity = factories.Activity()
     self.sick = factories.Project(name='sick')
     self.vacation = factories.Project(name='vacation')
     settings.TIMEPIECE_PAID_LEAVE_PROJECTS = {
         'sick': self.sick.pk, 'vacation': self.vacation.pk
     }
     self.next = utils.add_timezone(datetime.datetime(2011, 6, 1))
     self.overtime_before = utils.add_timezone(
         datetime.datetime(2011, 4, 29))
     self.first = utils.add_timezone(datetime.datetime(2011, 5, 1))
     self.first_week = utils.add_timezone(datetime.datetime(2011, 5, 2))
     self.middle = utils.add_timezone(datetime.datetime(2011, 5, 18))
     self.last_billable = utils.add_timezone(datetime.datetime(2011, 5, 28))
     self.last = utils.add_timezone(datetime.datetime(2011, 5, 31))
     self.dates = [
         self.overtime_before, self.first, self.first_week, self.middle,
         self.last, self.last_billable, self.next
     ]
     self.url = reverse('report_payroll_summary')
     self.args = {
         'year': self.first.year,
         'month': self.first.month,
     }
开发者ID:Focus3D,项目名称:django-timepiece,代码行数:29,代码来源:test_payroll.py


示例17: testMonthlyTotal

 def testMonthlyTotal(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1))
     end = utils.add_timezone(datetime.datetime(2011, 3, 1))
     trunc = 'month'
     last_day = randint(5, 10)
     worked1 = randint(1, 3)
     worked2 = randint(1, 3)
     for month in xrange(1, 7):
         for day in xrange(1, last_day + 1):
             day = utils.add_timezone(datetime.datetime(2011, month, day))
             self.log_time(start=day, delta=(worked1, 0), user=self.user)
             self.log_time(start=day, delta=(worked2, 0), user=self.user2)
     date_headers = utils.generate_dates(start, end, trunc)
     pj_totals = self.get_project_totals(date_headers, trunc)
     for hour in pj_totals[0][0]:
         self.assertEqual(hour, last_day * worked1)
     for hour in pj_totals[0][1]:
         self.assertEqual(hour, last_day * worked2)
开发者ID:eschipul,项目名称:django-timepiece,代码行数:18,代码来源:reports.py


示例18: test_invoice_confirm_view_user

    def test_invoice_confirm_view_user(self):
        """A regular user should not be able to access this page"""
        self.client.login(username='user2', password='abc')
        to_date = utils.add_timezone(datetime.datetime(2011, 1, 31))
        url = self.get_create_url(project=self.project_billable.pk,
                to_date=to_date.strftime(DATE_FORM_FORMAT))

        response = self.client.get(url)
        self.assertEquals(response.status_code, 403)
开发者ID:huxley,项目名称:django-timepiece,代码行数:9,代码来源:invoices.py


示例19: test_invoice_create_with_from

 def test_invoice_create_with_from(self):
     # Add another entry and make sure from filters it out
     url = reverse('invoice_projects')
     from_date = utils.add_timezone(datetime.datetime(2011, 1, 1, 0, 0, 0))
     to_date = utils.add_timezone(datetime.datetime(2011, 1, 31, 0, 0, 0))
     params = {
         'from_date': from_date.strftime('%m/%d/%Y'),
         'to_date': to_date.strftime('%m/%d/%Y'),
     }
     response = self.client.get(url, params)
     # From date filters out one entry
     num_project_totals = len(response.context['project_totals'])
     self.assertEquals(num_project_totals, 1)
     # Verify that the date on the mark as invoiced links will be correct
     from_date_str = response.context['from_date'].strftime('%Y %m %d')
     self.assertEquals(from_date_str, '2011 01 01')
     to_date_str = response.context['to_date'].strftime('%Y %m %d')
     self.assertEquals(to_date_str, '2011 01 31')
开发者ID:DarioGT,项目名称:schedulall,代码行数:18,代码来源:invoices.py


示例20: get_context_data

    def get_context_data(self, **kwargs):
        context = super(HourlyReport, self).get_context_data(**kwargs)

        # Sum the hours totals for each user & interval.
        entries = context['entries']
        date_headers = context['date_headers']

        summaries = []
        if context['entries']:
            summaries.append(('By User', get_project_totals(
                entries.order_by('user__last_name', 'user__id', 'date'),
                date_headers, 'total', total_column=True, by='user')))

            entries = entries.order_by('project__type__label', 'project__name',
                                       'project__id', 'date')
            func = lambda x: x['project__type__label']
            for label, group in groupby(entries, func):
                title = label + ' Projects'
                summaries.append((
                    title,
                    get_project_totals(
                        list(group),
                        date_headers,
                        'total',
                        total_column=True,
                        by='project',
                    ),
                ))

        # Adjust date headers & create range headers.
        from_date = context['from_date']
        from_date = utils.add_timezone(from_date) if from_date else None
        to_date = context['to_date']
        to_date = utils.add_timezone(to_date) if to_date else None
        trunc = context['trunc']
        date_headers, range_headers = self.get_headers(
            date_headers, from_date, to_date, trunc)

        context.update({
            'date_headers': date_headers,
            'summaries': OrderedDict(summaries),
            'range_headers': range_headers,
        })
        return context
开发者ID:Cashiuus,项目名称:django-timepiece,代码行数:44,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_week_start函数代码示例发布时间:2022-05-27
下一篇:
Python timeoutsocket.setDefaultSocketTimeout函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap