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

Python date_utils.get_time_display函数代码示例

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

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



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

示例1: test_gitlog_date

    def test_gitlog_date(self):
        """
        Make sure the date is timezone-aware and being converted/formatted
        properly.
        """

        tz_names = [
            'America/New_York',  # UTC - 5
            'Asia/Pyongyang',    # UTC + 9
            'Europe/London',     # UTC
            'Canada/Yukon',      # UTC - 8
            'Europe/Moscow',     # UTC + 4
        ]
        tz_format = DEFAULT_DATE_TIME_FORMAT

        self._setstaff_login()
        self._mkdir(settings.GIT_REPO_DIR)

        self._add_edx4edx()
        date = CourseImportLog.objects.first().created.replace(tzinfo=UTC)

        for timezone in tz_names:
            with (override_settings(TIME_ZONE=timezone)):
                date_text = get_time_display(date, tz_format, settings.TIME_ZONE)
                response = self.client.get(reverse('gitlogs'))
                self.assertIn(date_text, response.content.decode('UTF-8'))

        self._rm_edx4edx()
开发者ID:mreyk,项目名称:edx-platform,代码行数:28,代码来源:test_sysadmin.py


示例2: _now_formatted_date

 def _now_formatted_date(self):
     """Retrieve the formatted current date. """
     return get_time_display(
         datetime.datetime.now(UTC),
         DEFAULT_SHORT_DATE_FORMAT,
         settings.TIME_ZONE
     )
开发者ID:ferabra,项目名称:edx-platform,代码行数:7,代码来源:test_credit_requirements.py


示例3: test_save_valid_data

    def test_save_valid_data(self):
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015, 10, 20, 1, 10, 23, tzinfo=timezone(settings.TIME_ZONE))

        data = {
            'course_id': unicode(course.id),
            'mode_slug': 'professional',
            'mode_display_name': 'professional',
            'min_price': 10,
            'currency': 'usd',
            'expiration_datetime_0': expiration.date(),  # due to django admin datetime widget passing as seperate vals
            'expiration_datetime_1': expiration.time(),

        }

        self.client.login(username=user.username, password='test')

        # creating new course mode from django admin page
        response = self.client.post(reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(response, reverse('admin:course_modes_coursemode_changelist'))

        # verifying that datetime is appearing on list page
        response = self.client.get(reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # verifiying the on edit page datetime value appearing without any modifications
        resp = self.client.get(reverse('admin:course_modes_coursemode_change', args=(1,)))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # checking the values in db. comparing values without tzinfo
        course_mode = CourseMode.objects.get(pk=1)
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None), expiration.replace(tzinfo=None))
开发者ID:B-MOOC,项目名称:edx-platform,代码行数:35,代码来源:test_views.py


示例4: test_get_time_display_coerce

def test_get_time_display_coerce():
    test_time_standard = datetime(1992, 1, 12, 15, 3, 30, tzinfo=utc)
    test_time_daylight = datetime(1992, 7, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time_standard, None, coerce_tz="US/Pacific") == "Jan 12, 1992 at 07:03 PST"
    assert get_time_display(test_time_standard, None, coerce_tz="NONEXISTENTTZ") == "Jan 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time_standard, '%b %d %H:%M', coerce_tz="US/Pacific") == "Jan 12 07:03"
    assert get_time_display(test_time_daylight, None, coerce_tz="US/Pacific") == "Jul 12, 1992 at 08:03 PDT"
    assert get_time_display(test_time_daylight, None, coerce_tz="NONEXISTENTTZ") == "Jul 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time_daylight, '%b %d %H:%M', coerce_tz="US/Pacific") == "Jul 12 08:03"
开发者ID:jolyonb,项目名称:edx-platform,代码行数:9,代码来源:test_date_utils.py


示例5: test_expiration_timezone

    def test_expiration_timezone(self):
        # Test that expiration datetimes are saved and retrieved with the timezone set to UTC.
        # This verifies the fix for a bug in which the date displayed to users was different
        # than the date in Django admin.
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015, 10, 20, 1, 10, 23, tzinfo=timezone(settings.TIME_ZONE))

        data = {
            'course_id': unicode(course.id),
            'mode_slug': 'verified',
            'mode_display_name': 'verified',
            'min_price': 10,
            'currency': 'usd',
            'expiration_datetime_0': expiration.date(),  # due to django admin datetime widget passing as seperate vals
            'expiration_datetime_1': expiration.time(),

        }

        self.client.login(username=user.username, password='test')

        # Create a new course mode from django admin page
        response = self.client.post(reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(response, reverse('admin:course_modes_coursemode_changelist'))

        # Verify that datetime is appears on list page
        response = self.client.get(reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # Verify that on the edit page the datetime value appears as UTC.
        resp = self.client.get(reverse('admin:course_modes_coursemode_change', args=(1,)))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # Verify that the expiration datetime is the same as what we set
        # (hasn't changed because of a timezone translation).
        course_mode = CourseMode.objects.get(pk=1)
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None), expiration.replace(tzinfo=None))
开发者ID:johnny-nan,项目名称:edx-platform,代码行数:39,代码来源:test_admin.py


示例6: test_get_time_pass_through

def test_get_time_pass_through():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time))
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time, None))
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time, "%"))
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:5,代码来源:test_date_utils.py


示例7: test_get_time_display

def test_get_time_display():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("dummy text", get_time_display(test_time, 'dummy text'))
    assert_equals("Mar 12 1992", get_time_display(test_time, '%b %d %Y'))
    assert_equals("Mar 12 1992 UTC", get_time_display(test_time, '%b %d %Y %Z'))
    assert_equals("Mar 12 15:03", get_time_display(test_time, '%b %d %H:%M'))
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:6,代码来源:test_date_utils.py


示例8: test_get_time_disp_ret_empty

def test_get_time_disp_ret_empty():
    assert_equals("", get_time_display(None))
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("", get_time_display(test_time, ""))
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:4,代码来源:test_date_utils.py


示例9: expiration_datetime_custom

 def expiration_datetime_custom(self, obj):
     """adding custom column to show the expiry_datetime"""
     if obj.expiration_datetime:
         return get_time_display(obj.expiration_datetime, '%B %d, %Y, %H:%M  %p')
开发者ID:B-MOOC,项目名称:edx-platform,代码行数:4,代码来源:admin.py


示例10: test_get_time_disp_ret_empty

def test_get_time_disp_ret_empty():
    assert get_time_display(None) == ""
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time, "") == ""
开发者ID:jolyonb,项目名称:edx-platform,代码行数:4,代码来源:test_date_utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python date_utils.strftime_localized函数代码示例发布时间:2022-05-26
下一篇:
Python date_utils.get_default_time_display函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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