{ "info": { "author": "UNKNOWN", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [], "description": "=======\nzc.time\n=======\n\nzc.time provides a single point of creating datetime objects with the current\ntime. It is easily swappable with a test method without having to monkeypatch\nthe standard datetime classes.\n\n >>> import time\n >>> import zc.time\n\n >>> now = zc.time.now()\n\n >>> type(now)\n \n\nIt also defaults to UTC, which the vanilla datetime does not.\n\n >>> now.tzinfo\n \n\nThere's also a ``utcnow()`` function, which returns the naive UTC time\ncorresponding to the ``now()`` function's return value. This provides a\nutcnow() implementation that's similarly affected by replacing the\n``now()`` function:\n\n >>> now = zc.time.utcnow()\n\n >>> type(now)\n \n\n >>> now.tzinfo\n\nThis relationship holds even if ``now()`` is replaced (not recommended):\n\n >>> import datetime\n >>> import pytz\n\n >>> t = datetime.datetime(2010, 4, 1, 10, 50, 30, 2345, pytz.UTC)\n >>> old_now = zc.time.now\n\n >>> zc.time.now = lambda: t\n\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 10, 50, 30, 2345, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 10, 50, 30, 2345)\n\nThe ``reset()`` function provided cleans up modifications made to\ncontrol the time:\n\n >>> zc.time.reset()\n >>> zc.time.now is old_now\n True\n\nA ``set_now()`` function is provided that takes a datetime, and causes\n``now()`` and ``utcnow()`` to pretend that's the real time. The time\npassed in can be in any time zone; naive times are converted to UTC\nusing ``pytz.UTC.localize``:\n\n >>> zc.time.set_now(t)\n\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 10, 50, 30, 2345, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 10, 50, 30, 2345)\n >>> time.time()\n 1270137030.002345\n\n >>> naive = datetime.datetime(2010, 4, 1, 12, 27, 3, 5432)\n\n >>> zc.time.set_now(naive)\n\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 12, 27, 3, 5432, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 12, 27, 3, 5432)\n >>> time.time()\n 1270142823.005432\n\n >>> t = datetime.datetime(2010, 4, 1, 11, 17, 3, 5432,\n ... pytz.timezone(\"US/Eastern\"))\n\n >>> zc.time.set_now(t)\n\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 16, 17, 3, 5432, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 16, 17, 3, 5432)\n >>> time.time()\n 1270156623.005432\n\nTo move forward in time, simply use ``set_now()`` again:\n\n >>> zc.time.set_now(t + datetime.timedelta(hours=1))\n\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 17, 17, 3, 5432, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 17, 17, 3, 5432)\n >>> time.time()\n 1270160223.005432\n\nIf an application sleeps using ``time.sleep``, that'll be reflected in\nthe times reported:\n\n >>> import time\n\n >>> time.sleep(0.25)\n >>> zc.time.now()\n datetime.datetime(2010, 4, 1, 17, 17, 3, 255432, tzinfo=)\n >>> zc.time.utcnow()\n datetime.datetime(2010, 4, 1, 17, 17, 3, 255432)\n >>> time.time()\n 1270160223.255432\n\nThe reported time will be updated by the exact delay requested of the\n``time.sleep`` call, rather than by the actual delay.\n\nThe ``reset()`` function is used to clean up after this as well:\n\n >>> zc.time.reset()\n\nThe ``reset()`` is registered as a general cleanup handler if\n``zope.testing`` is available. This is generally not sufficient for\nfunctional tests, which will need to call ``reset`` themselves.\n\n\nChanges\n=======\n\n\n1.0.2 (2015-04-20)\n------------------\n\n- Fix packaging bug.\n\n\n1.0.0 (2015-04-20)\n------------------\n\n- Include ``time.time`` in what's controlled by ``zc.time.set_now``.\n\n\n0.3 (2010-07-23)\n----------------\n\n- Added time.sleep() support.\n\n\n0.2 (2010-04-01)\n----------------\n\n- Added utcnow().\n- Added set_now(), reset().\n\n\n0.1\n---\n\nInitial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": null, "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "zc.time", "package_url": "https://pypi.org/project/zc.time/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zc.time/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/zc.time/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "Hook time for testing", "version": "1.0.2" }, "last_serial": 1513639, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "1794c3ed3d4d04a21b486a3951095531", "sha256": "ee2a35344b00a6fde1126af21836eccbaebd05a076fd260a0b84b35c3e161995" }, "downloads": -1, "filename": "zc.time-1.0.0.tar.gz", "has_sig": false, "md5_digest": "1794c3ed3d4d04a21b486a3951095531", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3210, "upload_time": "2015-04-20T21:30:49", "url": "https://files.pythonhosted.org/packages/4b/0f/cc17bdbc1e23e5955452827404a95f639b7a5db880cc23d701430e69957d/zc.time-1.0.0.tar.gz" } ], "1.0.1": [], "1.0.2": [ { "comment_text": "", "digests": { "md5": "a039333d2aa3a3b75ced445fca1b7eb5", "sha256": "c3bbfd5b878c9b8d478ba97ecd7af9efcc87886bacc030c6213c3adb71b08f3a" }, "downloads": -1, "filename": "zc.time-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a039333d2aa3a3b75ced445fca1b7eb5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3716, "upload_time": "2015-04-20T21:52:50", "url": "https://files.pythonhosted.org/packages/d2/2f/1882e604d12621d0acf929d11723735a0c8f25280d5c59db70648a54545a/zc.time-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a039333d2aa3a3b75ced445fca1b7eb5", "sha256": "c3bbfd5b878c9b8d478ba97ecd7af9efcc87886bacc030c6213c3adb71b08f3a" }, "downloads": -1, "filename": "zc.time-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a039333d2aa3a3b75ced445fca1b7eb5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3716, "upload_time": "2015-04-20T21:52:50", "url": "https://files.pythonhosted.org/packages/d2/2f/1882e604d12621d0acf929d11723735a0c8f25280d5c59db70648a54545a/zc.time-1.0.2.tar.gz" } ] }