智能日期时间
bda.intellidatetime的Python项目详细描述
bda.intellidatetime
概述
bda.intellidatetime为python的日期和时间输入提供了一个转换器 datetime.datetime对象。
输入格式由locale2pattern映射定义,由 一个独立的接口。
当前提供的区域设置是:
- 英语
- de
- fr
- es
- 英国
- 它
- cs
- 以及特殊的语言环境iso,它被用作默认值。
示例
使用转换功能:
>>> frombda.intellidatetimeimportconvert>>> convert('1.1.08',locale='de')datetime.datetime(2008, 1, 1, 0, 0)
api
bda.intellidatetime.convert的签名如下:
defconvert(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
贡献者
- 罗伯特·尼德雷特(作者)
- Jens W.Klein
更改
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。 [詹森,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,詹森斯]
许可证
版权所有(c)2010-2018,Bluedynamics联盟,奥地利 保留所有权利。
以源和二进制形式重新分配和使用,有无 如果满足以下条件,则允许修改:
- 重新发布源代码必须保留上述版权声明 条件列表和以下免责声明。
- 以二进制形式重新分发必须复制上述版权声明,此 文件中的条件列表和以下免责声明和/或 其他随发材料。
- 无论是蓝动力联盟的名字还是它的名字 贡献者可用于支持或推广由此衍生的产品 未经事先书面许可的软件。
此软件由Bluedynamics Alliance^{TT10}$和任何 明示或默示保证,包括但不限于 对特定用途的适销性和适合性的保证 否认。在任何情况下,蓝动力联盟均不对任何 直接、间接、附带、特殊、惩戒性或后果性损害 (包括但不限于替代货物或服务的采购; 使用、数据或利润的损失;或营业中断),无论是何种原因造成的 论任何责任理论,无论是合同责任、严格责任还是侵权责任 (包括疏忽或其他)以任何方式产生的 软件,即使被告知有这种损坏的可能性。