bda.intellidatetime


Namebda.intellidatetime JSON
Version 1.4 PyPI version JSON
download
home_pagehttps://github.com/bluedynamics/bda.intellidatetime
Summarybda.intellidatetime
upload_time2022-12-05 11:32:24
maintainer
docs_urlNone
authorBlueDynamics Alliance
requires_python
licenseSimplified BSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            bda.intellidatetime
===================

Overview
--------

``bda.intellidatetime`` provides a converter for date and time input to python
``datetime.datetime`` objects.

The input format is definded by a locale2pattern mapping and is provided by
a seperate interface.

Currently provided locales are:

- en
- de
- fr
- es
- uk
- it
- cs
- and the special locale ``iso``, which is used as default.


Example
-------

Use the convert function:

.. code-block:: pycon

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


API
---

The signature of ``bda.intellidatetime.convert`` looks like so:

.. code-block:: python

    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
        """


Licence
-------

- Simplified BSD


Contributors
============

- Robert Niederreiter (Author)
- Jens W. Klein


Changes
=======

1.4 (2022-12-05)
----------------

- Release wheel.
  [rnix]


1.3 (2018-07-16)
----------------

- Python 3 compatibility.
  [rnix]

- Convert doctests to unittests.
  [rnix]


1.2.2
-----

- Package cleanup.
  [rnix, 2017-03-29]


1.2.1
-----

- fix ``MANIFEST.in`` to include ``configure.zcml`` in release
  [jensens, 2013-09-23]


1.2
---

- Use ``zope.interface.implementer`` instead of ``zope.interface.implements``.
  [rnix, 2012-05-18]


1.1
---

- Provide convenience ``convert`` function.
  [rnix, 2010-05-08]

- Change package structure.
  [rnix, 2010-05-08]

- Move tests into seperate file.
  [rnix, 2010-05-08]

- Change signature of converter. could now be registered as utility as well if
  desired.
  [rnix, 2010-05-08]

- Adapter pattern deprecated.
  [rnix, 2010-05-08]


1.0
---

- Make it work
  [rnix, jensens]



License
=======

Copyright (c) 2010-2022, BlueDynamics Alliance, Austria
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this 
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this 
  list of conditions and the following disclaimer in the documentation and/or 
  other materials provided with the distribution.
* Neither the name of the BlueDynamics Alliance nor the names of its 
  contributors may be used to endorse or promote products derived from this 
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY BlueDynamics Alliance ``AS IS`` AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BlueDynamics Alliance BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bluedynamics/bda.intellidatetime",
    "name": "bda.intellidatetime",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "BlueDynamics Alliance",
    "author_email": "dev@bluedynamics.com",
    "download_url": "https://files.pythonhosted.org/packages/46/b3/150c3e1c335c8735bd279d17db3486e367f07ca4573c70923f5cf38cc42f/bda.intellidatetime-1.4.tar.gz",
    "platform": null,
    "description": "bda.intellidatetime\n===================\n\nOverview\n--------\n\n``bda.intellidatetime`` provides a converter for date and time input to python\n``datetime.datetime`` objects.\n\nThe input format is definded by a locale2pattern mapping and is provided by\na seperate interface.\n\nCurrently provided locales are:\n\n- en\n- de\n- fr\n- es\n- uk\n- it\n- cs\n- and the special locale ``iso``, which is used as default.\n\n\nExample\n-------\n\nUse the convert function:\n\n.. code-block:: pycon\n\n    >>> from bda.intellidatetime import convert\n    >>> convert('1.1.08', locale='de')\n    datetime.datetime(2008, 1, 1, 0, 0)\n\n\nAPI\n---\n\nThe signature of ``bda.intellidatetime.convert`` looks like so:\n\n.. code-block:: python\n\n    def convert(date, time=None, tzinfo=None, locale='iso'):\n        \"\"\"Convert the input to a datetime object.\n\n        The convert function accepts unicode or non-unicode strings and tries\n        to parse out Date and Time information as follows:\n          * First try to get the localized datetime pattern information\n          * If no one is found, a default pattern is used.\n          * Parse the input by the definitions of the localized datetime pattern\n          * Create a datetime object and return it\n\n        The 'intelligence' is defined by following behaviour:\n\n        Date:\n          * If only one value is found f.e. '1', this value is handled as the\n            day value, for month and for year the current ones are used.\n          * Respective, if two values are given, they are handled as day and\n            month, year is auto completed with the current year.\n          * 3 values are a complete date information, if year is a 2-character\n            string, it is handled as year in the current century\n          * as limiters are all non-numeric values accepted\n          * date input can be done without limiters, therefor all characters\n            must be numbers, and the string length must be either 2, 4, 6 or 8\n            characters. 2 characters define the day, 4 characters the day and\n            the month, 6 characters day, month and the year of the current\n            century and 8 characters define a complete date.\n\n        Time:\n          * If time is None, time is set to 00:00\n          * if time is a 2-character string, it is handled as the hour, minutes\n            are defined as 00\n          * time input can be done without a limiter, therefor time must be an\n            all numeric 4-character string, the first 2 chars are handled as\n            hour, the second 2 chars as minute.\n          * as limiter are all non-numeric values accepted\n          * seconds are never computed and are therefor ALWAYS handled as '00'\n\n        Limiters can be any 1 or more character non numeric values. An input\n        can look like ``  %_2008 1 abcde 5 ---`` and is still valid and with\n        default locale converted to ``datetime.datetime(2008, 1, 5, 0, 0)``.\n\n        If parsing of the input values is not possible or converting the parsed\n        values to numeric values is not possible or the valid date and time\n        range falls out of scope, a ``DateTimeConversionError`` is raised.\n\n        @param date - a date as string\n        @param time - a time as string\n        @param tzinfo - a tzinfo object to be considered, defaults to None. If\n                        given the date and time taken as in the given timezone.\n                        If the timezone is DST-aware time will be normalized\n                        for DST/non-DST.\n        @param locale - a locale name, which is used to determine the date and\n                        time patterns. There exists a special locale named\n                        'iso', which is default and expects the input in ISO\n                        format.\n        @return datetime - datetime.datetime object\n        @raise DateTimeConversionError - if conversion fails\n        \"\"\"\n\n\nLicence\n-------\n\n- Simplified BSD\n\n\nContributors\n============\n\n- Robert Niederreiter (Author)\n- Jens W. Klein\n\n\nChanges\n=======\n\n1.4 (2022-12-05)\n----------------\n\n- Release wheel.\n  [rnix]\n\n\n1.3 (2018-07-16)\n----------------\n\n- Python 3 compatibility.\n  [rnix]\n\n- Convert doctests to unittests.\n  [rnix]\n\n\n1.2.2\n-----\n\n- Package cleanup.\n  [rnix, 2017-03-29]\n\n\n1.2.1\n-----\n\n- fix ``MANIFEST.in`` to include ``configure.zcml`` in release\n  [jensens, 2013-09-23]\n\n\n1.2\n---\n\n- Use ``zope.interface.implementer`` instead of ``zope.interface.implements``.\n  [rnix, 2012-05-18]\n\n\n1.1\n---\n\n- Provide convenience ``convert`` function.\n  [rnix, 2010-05-08]\n\n- Change package structure.\n  [rnix, 2010-05-08]\n\n- Move tests into seperate file.\n  [rnix, 2010-05-08]\n\n- Change signature of converter. could now be registered as utility as well if\n  desired.\n  [rnix, 2010-05-08]\n\n- Adapter pattern deprecated.\n  [rnix, 2010-05-08]\n\n\n1.0\n---\n\n- Make it work\n  [rnix, jensens]\n\n\n\nLicense\n=======\n\nCopyright (c) 2010-2022, BlueDynamics Alliance, Austria\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this \n  list of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice, this \n  list of conditions and the following disclaimer in the documentation and/or \n  other materials provided with the distribution.\n* Neither the name of the BlueDynamics Alliance nor the names of its \n  contributors may be used to endorse or promote products derived from this \n  software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY BlueDynamics Alliance ``AS IS`` AND ANY\nEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL BlueDynamics Alliance BE LIABLE FOR ANY\nDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n",
    "bugtrack_url": null,
    "license": "Simplified BSD",
    "summary": "bda.intellidatetime",
    "version": "1.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "12020f1f1a3d6a94774311a9b4ce79af",
                "sha256": "d71f34adc244c2870638f3318b91acf50e9ca463919bd1694e1036ccd23d286f"
            },
            "downloads": -1,
            "filename": "bda.intellidatetime-1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "12020f1f1a3d6a94774311a9b4ce79af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11321,
            "upload_time": "2022-12-05T11:32:21",
            "upload_time_iso_8601": "2022-12-05T11:32:21.878393Z",
            "url": "https://files.pythonhosted.org/packages/22/4e/b5e0c7028af82e27fc8a05995a646e96459e7d4551ef1e4b484a93653dd3/bda.intellidatetime-1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "6fe8b9a1df5059012acbdf44d031127f",
                "sha256": "6a8009bab189dccf2654d39f1facece365d6d144568638a717ea34dc6f639cec"
            },
            "downloads": -1,
            "filename": "bda.intellidatetime-1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "6fe8b9a1df5059012acbdf44d031127f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10301,
            "upload_time": "2022-12-05T11:32:24",
            "upload_time_iso_8601": "2022-12-05T11:32:24.645568Z",
            "url": "https://files.pythonhosted.org/packages/46/b3/150c3e1c335c8735bd279d17db3486e367f07ca4573c70923f5cf38cc42f/bda.intellidatetime-1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-05 11:32:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "bluedynamics",
    "github_project": "bda.intellidatetime",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "bda.intellidatetime"
}
        
Elapsed time: 0.16817s