跳转到主要内容

bda.intellidatetime

项目描述

bda.intellidatetime

概述

bda.intellidatetime 提供了将日期和时间输入转换为python datetime.datetime 对象的转换器。

输入格式由locale2pattern映射定义,并通过单独的接口提供。

目前提供的区域设置有

  • en

  • de

  • fr

  • es

  • uk

  • it

  • cs

  • 以及特殊区域设置iso,默认使用。

示例

使用转换函数

>>> from bda.intellidatetime import convert
>>> convert('1.1.08', locale='de')
datetime.datetime(2008, 1, 1, 0, 0)

API

bda.intellidatetime.convert 的签名如下

def convert(date, time=None, tzinfo=None, locale='iso'):
    """Convert the input to a datetime object.

    The convert function accepts unicode or non-unicode strings and tries
    to parse out Date and Time information as follows:
      * First try to get the localized datetime pattern information
      * If no one is found, a default pattern is used.
      * Parse the input by the definitions of the localized datetime pattern
      * Create a datetime object and return it

    The 'intelligence' is defined by following behaviour:

    Date:
      * If only one value is found f.e. '1', this value is handled as the
        day value, for month and for year the current ones are used.
      * Respective, if two values are given, they are handled as day and
        month, year is auto completed with the current year.
      * 3 values are a complete date information, if year is a 2-character
        string, it is handled as year in the current century
      * as limiters are all non-numeric values accepted
      * date input can be done without limiters, therefor all characters
        must be numbers, and the string length must be either 2, 4, 6 or 8
        characters. 2 characters define the day, 4 characters the day and
        the month, 6 characters day, month and the year of the current
        century and 8 characters define a complete date.

    Time:
      * If time is None, time is set to 00:00
      * if time is a 2-character string, it is handled as the hour, minutes
        are defined as 00
      * time input can be done without a limiter, therefor time must be an
        all numeric 4-character string, the first 2 chars are handled as
        hour, the second 2 chars as minute.
      * as limiter are all non-numeric values accepted
      * seconds are never computed and are therefor ALWAYS handled as '00'

    Limiters can be any 1 or more character non numeric values. An input
    can look like ``  %_2008 1 abcde 5 ---`` and is still valid and with
    default locale converted to ``datetime.datetime(2008, 1, 5, 0, 0)``.

    If parsing of the input values is not possible or converting the parsed
    values to numeric values is not possible or the valid date and time
    range falls out of scope, a ``DateTimeConversionError`` is raised.

    @param date - a date as string
    @param time - a time as string
    @param tzinfo - a tzinfo object to be considered, defaults to None. If
                    given the date and time taken as in the given timezone.
                    If the timezone is DST-aware time will be normalized
                    for DST/non-DST.
    @param locale - a locale name, which is used to determine the date and
                    time patterns. There exists a special locale named
                    'iso', which is default and expects the input in ISO
                    format.
    @return datetime - datetime.datetime object
    @raise DateTimeConversionError - if conversion fails
    """

许可证

  • 简化版BSD

贡献者

  • Robert Niederreiter(作者)

  • Jens W. Klein

变更

1.4 (2022-12-05)

  • 发布轮。 [rnix]

1.3 (2018-07-16)

  • Python 3 兼容性。 [rnix]

  • 将doctests转换为unittests。 [rnix]

1.2.2

  • 清理包。 [rnix, 2017-03-29]

1.2.1

  • 修复MANIFEST.in 以包括发布中的 configure.zcml [jensens, 2013-09-23]

1.2

  • 使用 zope.interface.implementer 而不是 zope.interface.implements。 [rnix, 2012-05-18]

1.1

  • 提供方便的 convert 函数。 [rnix, 2010-05-08]

  • 更改包结构。 [rnix,2010-05-08]

  • 将测试移动到单独的文件中。 [rnix,2010-05-08]

  • 更改转换器的签名。现在也可以根据需要将其注册为工具。 [rnix,2010-05-08]

  • 弃用适配器模式。 [rnix,2010-05-08]

1.0

  • 使其工作 [rnix,jensens]

许可证

版权所有 © 2010-2022,奥地利BlueDynamics Alliance。保留所有权利。

在满足以下条件的情况下,允许重新分发和使用源代码和二进制形式,无论是否修改:

  • 源代码重新分发必须保留上述版权声明、本许可列表和以下免责声明。

  • 二进制形式重新分发必须复制上述版权声明、本许可列表和以下免责声明在随分发提供的文档和其他材料中。

  • 未经事先书面许可,不得使用BlueDynamics Alliance的名称或其贡献者的名称来认可或推广源自本软件的产品。

本软件由BlueDynamics Alliance提供“按原样”并且不承担任何明示或暗示的保证,包括但不限于适销性和针对特定目的的适用性保证。在任何情况下,BlueDynamics Alliance均不对任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代货物或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论此类损害是由于何种原因造成的,以及基于何种责任理论,即使是因使用本软件或因已告知可能发生此类损害的可能性而造成的。

项目详细信息


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

bda.intellidatetime-1.4.tar.gz (10.3 kB 查看哈希值)

上传时间 源代码

构建分发

bda.intellidatetime-1.4-py3-none-any.whl (11.3 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面