{ "info": { "author": "Vanguardistas LLC", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": ".. contents::\n\nPython Format Functions\n=======================\n\nThe van.timefmt module is a support module for date/time specific operations.\n\n >>> from datetime import date, datetime\n >>> mydate = date(1975, 12, 17)\n >>> mydatetime = datetime(1975, 12, 17, 5, 24, 36)\n\nIt provides a \"timefmt\" function which can take either a date or datetime object:\n\n >>> from van.timeformat import ltimefmt, timefmt\n\nFixed formatting\n----------------\n\nFixed formats are locale independant. They are useful in 2 situations:\n\n* Computer parsable dates\n* Projects with no localization requirement\n\ndefault formatting\n++++++++++++++++++\n\nIf no format argument is specified, dates and datetimes are formatted using .isoformat(\" \"):\n\n >>> print timefmt(mydatetime)\n 1975-12-17T05:24:36\n\n >>> print timefmt(mydate)\n 1975-12-17\n\nThe 'iso' format also triggers this:\n \n >>> print timefmt(mydatetime, format='iso')\n 1975-12-17T05:24:36\n\nIf None is used as an input date, timefmt will return None:\n \n >>> timefmt(None) is None\n True\n\nrfc2822\n+++++++\n\nThe date in compliance with the RFC 2822 Internet email standard.\n\n >>> print timefmt(mydate, 'rfc2822')\n Wed, 17 Dec 1975 00:00:00 +0000\n\n >>> print timefmt(mydatetime, 'rfc2822')\n Wed, 17 Dec 1975 05:24:36 +0000\n\n\nExtending formats\n+++++++++++++++++\n\nIf we want to extend the list of formats available, we can use the\n\"time_format\" zcml command defined in this module's meta.zcml.\n\nAn example of use is in configure.zcml where the rfc2822 format is defined.\n\nNote: it's probably a good idea to use namespaces for registrations. The\nvan.timeformat module promises to not use \".\" in any of it's default\nregistrations.\n\nUnicode\n+++++++\n\nThe return type is a unicode string:\n\n >>> timefmt(mydatetime)\n u'1975-12-17T05:24:36'\n\nAnd we can have unicode in the formats:\n\n >>> timefmt(mydatetime, format='unicode_test')\n u'1975-17-12 Extended Arabic-Indic Digit Seven: \\u06f7:'\n\nLocale dependant translations\n-----------------------------\n\n >>> from zope.i18n.locales import locales\n >>> german = locales.getLocale('de', 'de')\n >>> us = locales.getLocale('en', 'us')\n >>> britain = locales.getLocale('en', 'gb')\n\nReturns unicode:\n\n >>> ltimefmt(mydate, us)\n u'Dec 17, 1975'\n\nDefaults correctly chosen for date and datetime:\n\n >>> print ltimefmt(mydate, us)\n Dec 17, 1975\n >>> print ltimefmt(mydatetime, us)\n Dec 17, 1975 5:24:36 AM\n\nBut we can force format one as the other:\n\n >>> print ltimefmt(mydate, us, category=\"dateTime\")\n Dec 17, 1975 12:00:00 AM\n >>> print ltimefmt(mydatetime, us, category=\"date\")\n Dec 17, 1975\n\nLocalized:\n\n >>> print ltimefmt(mydate, britain, category=\"date\", length=\"long\")\n 17 December 1975\n >>> print ltimefmt(mydate, german, category=\"date\", length=\"long\")\n 17. Dezember 1975\n\nIf None is used as an input date, ltimefmt will return None:\n \n >>> ltimefmt(None, us) is None\n True\n\nLocalized formatting examples\n+++++++++++++++++++++++++++++\n\nShort times:\n\n >>> print ltimefmt(mydate, us, category=\"time\", length=\"short\")\n 12:00 AM\n\nShort dates:\n\n >>> print ltimefmt(mydate, us, category=\"date\", length=\"short\")\n 12/17/75\n\nMedium Dates:\n\n >>> print ltimefmt(mydate, us, category=\"date\", length=\"medium\")\n Dec 17, 1975\n\nLong Dates:\n\n >>> print ltimefmt(mydate, us, category=\"date\", length=\"long\")\n December 17, 1975\n\nShort Datetimes:\n\n >>> print ltimefmt(mydatetime, us, category=\"dateTime\", length=\"short\")\n 12/17/75 5:24 AM\n\nMedium Datetimes:\n\n >>> print ltimefmt(mydatetime, us, category=\"dateTime\", length=\"medium\")\n Dec 17, 1975 5:24:36 AM\n\nLong Datetimes:\n\n >>> print ltimefmt(mydatetime, us, category=\"dateTime\", length=\"long\")\n December 17, 1975 5:24:36 AM +000\n\n\n\nIntegration with ZPT\n====================\n\nIf the zope.app.pagetemplate module is available, the timeformat module will integrate itself with it:\n\n >>> import os\n >>> import tempfile\n >>> from zope.publisher.browser import TestRequest\n\n >>> temp_file = tempfile.mkstemp()[1]\n >>> open(temp_file, 'w').write(\"\"\"\n ... \n ... \n ... RFC 2822 date : \n ... Medium Time : \n ... Medium Date : \n ... Medium DateTime : \n ... Python Expr (ltimefmt): \n ... Python Expr (timefmt) : \n ... \n ... \n ... \"\"\")\n\n >>> from zope.app.pagetemplate.simpleviewclass import SimpleViewClass\n >>> Page = SimpleViewClass(temp_file, name='main.html')\n >>> request = TestRequest()\n >>> print Page(None, request)().strip() # doctest: +NORMALIZE_WHITESPACE\n \n \n RFC 2822 date : Wed, 17 Dec 1975 05:24:36 +0000\n Medium Time : 05:24:36\n Medium Date : 1975 12 17\n Medium DateTime : 1975 12 17 05:24:36\n Python Expr (ltimefmt): 1975 12 17 00:00:00 +000\n Python Expr (timefmt) : Wed, 17 Dec 1975 00:00:00 +0000\n \n \n\nUsing the german locale:\n\n >>> request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'de-de'})\n >>> print Page(None, request)().strip()\n \n \n RFC 2822 date : Wed, 17 Dec 1975 05:24:36 +0000\n Medium Time : 05:24:36\n Medium Date : 17.12.1975\n Medium DateTime : 17.12.1975 05:24:36\n Python Expr (ltimefmt): 17. Dezember 1975 00:00:00 +000\n Python Expr (timefmt) : Wed, 17 Dec 1975 00:00:00 +0000\n \n \n\nLet's see if it works with spaces after the colon (at various places):\n\n >>> open(temp_file, 'w').write(\"\"\"\n ... \n ... \n ... RFC 2822 date : \n ... Medium Date : \n ... Medium DateTime : \n ... Python Expr (ltimefmt): \n ... Python Expr (timefmt) : \n ... \n ... \n ... \"\"\")\n\n >>> Page = SimpleViewClass(temp_file, name='main_with_spaces.html')\n >>> request = TestRequest()\n >>> print Page(None, request)().strip() # doctest: +NORMALIZE_WHITESPACE\n \n \n RFC 2822 date : Wed, 17 Dec 1975 05:24:36 +0000\n Medium Date : 1975 12 17\n Medium DateTime : 1975 12 17 05:24:36\n Python Expr (ltimefmt): 1975 12 17 00:00:00 +000\n Python Expr (timefmt) : Wed, 17 Dec 1975 00:00:00 +0000\n \n \n\nCleanUp:\n\n >>> os.remove(temp_file)\n\n\nChanges\n=======\n\n1.1.1 (2012-01-05)\n------------------\n\nFeatures:\n\n- Add time examples to the documentation.\n\nBugfixes:\n\n- Conform to Zope repository policy.\n- Remove conditional on zope.app.pagetemplate being installed, was a bad idea.\n\n1.1.0 (2010-01-20)\n------------------\n\nFeatures:\n\n- Accept None as an argument for timefmt and ltimefmt. These functions will now\n return None in this case instead of erroring.\n\nBugfixes:\n\n- Re-add tests mistakenly removed.\n- Update dependencies: van.testing is only needed for tests.\n- Update tests to run with new ZTK packages.\n- Add author e-mail.\n\n1.0.0 (2008-11-21)\n------------------\n\n- Initial Release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/van.timeformat", "keywords": null, "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "van.timeformat", "package_url": "https://pypi.org/project/van.timeformat/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/van.timeformat/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/van.timeformat" }, "release_url": "https://pypi.org/project/van.timeformat/1.1.1/", "requires_dist": null, "requires_python": null, "summary": "Convienience functions for formatting dates/times using zope.i18n and TAL", "version": "1.1.1" }, "last_serial": 642329, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "2cd33d9d0df92a4c19506edcde618d61", "sha256": "af286e318d1a81d9db82ff2ec5195df34d37797815c99d95d9209d80e59e37f4" }, "downloads": -1, "filename": "van.timeformat-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2cd33d9d0df92a4c19506edcde618d61", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7721, "upload_time": "2008-11-21T00:17:51", "url": "https://files.pythonhosted.org/packages/df/2d/fd79df85de00dd7850375edc02dd1d7123085f87a2694ddc6a13b734cb81/van.timeformat-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "01146c87bbcb7b9f16c6f5b8350e726f", "sha256": "2969cef20fbc6ae81bed0cb733942c7e5228bf0b82870791cabc78a53199011b" }, "downloads": -1, "filename": "van.timeformat-1.1.0.tar.gz", "has_sig": false, "md5_digest": "01146c87bbcb7b9f16c6f5b8350e726f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8471, "upload_time": "2010-01-20T10:41:13", "url": "https://files.pythonhosted.org/packages/29/93/fb87147cbb28e1dc018ff880c938daebf45765fd132371a9304abc334baa/van.timeformat-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "4f1c332caf7b403f88ca2133abc364a9", "sha256": "7853912fd1059fd9baf15adfc0274db6f3d4c06aa4744c27b86bacbfb8efae4d" }, "downloads": -1, "filename": "van.timeformat-1.1.1.tar.gz", "has_sig": false, "md5_digest": "4f1c332caf7b403f88ca2133abc364a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8614, "upload_time": "2012-01-05T15:58:49", "url": "https://files.pythonhosted.org/packages/ad/01/9fea46ec0729b6c72ccf7bcdc54c33e7f954fb6dfe41c6ca3ef11e4b5c35/van.timeformat-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4f1c332caf7b403f88ca2133abc364a9", "sha256": "7853912fd1059fd9baf15adfc0274db6f3d4c06aa4744c27b86bacbfb8efae4d" }, "downloads": -1, "filename": "van.timeformat-1.1.1.tar.gz", "has_sig": false, "md5_digest": "4f1c332caf7b403f88ca2133abc364a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8614, "upload_time": "2012-01-05T15:58:49", "url": "https://files.pythonhosted.org/packages/ad/01/9fea46ec0729b6c72ccf7bcdc54c33e7f954fb6dfe41c6ca3ef11e4b5c35/van.timeformat-1.1.1.tar.gz" } ] }