{ "info": { "author": "Alec Nikolas Reiter", "author_email": "alecreiter@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities" ], "description": "=========\ndatestuff\n=========\n\nFor when you need some :code:`datetime` helpers but not a complete replacement for the modules.\n\nWhy?\n====\n\nFrankly, I love the built in :code:`datetime` module. Almost everything I need to do, I can just do with it.\n\nHowever, a few things tend to creep up datetime and datetime again. Things like:\n\n* Creating a range of dates\n* Creating an unfixed date\n* Checking if two datetimes are within a certain delta of one another\n\nHere's a short look at what's included.\n\nRelativeDate and RelativeDateTime\n=================================\n\nThese allow you to create an unfixed :code:`date` or :code:`datetime` instance by providing a :code:`timedelta` offset and/or factory method.\n\nBy default, :code:`RelativeDate` uses :code:`date.today` and :code:`RelativeDateTime` uses :code:`datetime.now` as the default factories and both have a default offset of :code:`timedelta(0)`:\n\n.. code-block:: python\n\n rd = RelativeDate()\n rd.as_date() # date(2016, 7, 24)\n\n rdt = RelativeDateTime()\n rd.as_datetime() # datetime(2016, 7, 24, 12, 29)\n\n\nHowever, it is also possible to provide other factories as well:\n\n\n.. code-block:: python\n\n import arrow\n rdt = RelativeDateTime(clock=arrow.utcnow)\n rdt.as_datetime() # \n\nAnd as long as the underlying factory produces a :code:`date` or :code:`datetime` compatible object, everything will *just work*. By compatible, I mean implements the :code:`date` or :code:`datetime` interface.\n\nAdditionally, if only a static offset from today or now is desired, you can simply provide the offset argument with a :code:`timedelta` or dateutil :code:`relativedelta`. Note that currently, :code:`timedelta` and :code:`relativedelta` are not interoperable.\n\n\n.. code-block:: python\n\n from datetime import timedelta\n rd = RelativeDate(offset=timedelta(days=6))\n rd.as_date() # date(2016, 7, 30)\n\n:code:`RelativeDate` and :code:`RelativeDateTime` also allow comparing against regular :code:`date` and :code:`datetime` instances with the standard operators (==, !=, >, etc). Making these incredibly useful for quickly defining date boundaries that are defined statically (such as in a serializer or ORM model):\n\n.. code-block:: python\n\n from datetime import timedelta, date\n\n rd = RelativeDate(offset=timedelta(days=7))\n\n assert rd > date.today() # always true\n\n\nAdding and subtracting relative instances actually operate on their offsets, rather than underlying :code:`date` or :code:`datetime` values.\n\n.. code-block:: python\n\n from datetime import timedelta\n\n rd = RelativeDate(offset=timedelta(days=1))\n\n rd + rd == RelativeDate(offset(timedelta(days=2)))\n\n rd - rd == RelativeDate()\n\nSome alternate constructors are provided where it makes sense, each allows passing an offset but defaults to :code:`timedelta()`, provided are:\n\n* :code:`RelativeDate.today`: the default constructor\n* :code:`RelativeDateTime.now`: the default constructor, allows passing a tzinfo object to the factory\n* :code:`RelativeDateTime.utcnow`: factory produces UTC-based datetimes (note: these are NAIVE as it relies on the underlying :code:`datetime.utcnow`)\n* :code:`RelativeDateTime.today`: the default constructor, does not allow passing a tzinfo object\n\nFor convenience sake there are also truly static constructors:\n\n* :code:`RelativeDate.fromdate`: hoists a regular date into relative context\n* :code:`RelativeDateTime.fromdatetime`: hoists a regular datetime into\n* :code:`RelativeDateTime.fromdate`: hoists a date into a :code:`RelativeDateTime` context, allows passing a tzinfo object, factory looks like :code:`datetime.combine(the_date, time(tzinfo=tzinfo))`\n\nAny additional static constructors, such as :code:`datetime.strptime`, can be derived from these if truly needed.\n\n.. code-block:: python\n\n from datetime import date, time, timedelta\n\n rd = RelativeDate.fromdate(date(2016, 7, 24), offset=timedelta(days=7))\n rd.as_date() # date(2016, 7, 31), always\n\n\nFinally, any functionality not implemented directly in the relative instance is proxied to the underlying :code:`date` or :code:`datetime` instance.\n\nDateRange\n=========\n\nA range of dates is another tool I find myself needing from time to time, however eager creation can sometimes be very expensive for a large range.\n\nInstead, :code:`DateRange` is modeled after the Python 3 :code:`range` type, which has fast path lookup for membership, lazy iteration, indexing and slicing (slices return new :code:`DateRange` objects)\n\n.. code-block:: python\n\n from datestuff import DateRange\n from datetime import date, timedelta\n\n dr = DateRange(start=date(2016, 1, 1), stop=date(2016, 12, 31), step=timedelta(days=7))\n\n date(2016, 1, 8) in dr # true\n\n len(dr) # 53, yes this is correct\n\n list(dr) # [date(2016, 1, 1), date(2016, 1, 8), ...]\n\n dr[1] == date(2016, 1, 8) # True\n dr[1:-1:2] == DateRange(date(2016, 1, 8), date(2016, 12, 30), step=timedelta(days=14)) # True\n\n:code:`DateRange` also allows creating an open ended range by simply omitting the stop argument. In this case, the only functionality that will not work is using :code:`len` and negative indexing/slicing (as there is no end)\n\nCurrently, :code:`DateRange` does not support :code:`relativedelta` as under the hood it uses :code:`timedelta.total_seconds` for Python 2 and 3 compatiblity. This could be resolved in the future, but is unlikely. :code:`DateRange` is, however, compatible with :code:`date` and :code:`datetime` like objects and other :code:`timedelta` like objects. Interestingly, this would apply to :code:`RelativeDate` and :code:`RelativeDateTime` as well.\n\n\nutils\n=====\n\nCurrently, the only util is :code:`within_delta` which is useful for comparing two :code:`date` or :code:`datetime` (or like) instances within a certain delta.\n\n.. code-block:: python\n\n from datetime import datetime, timedelta\n from datestuff import within_delta\n\n d1 = datetime.now()\n d2 = datetime.now()\n\n d1 == d2 # false\n\n within_delta(d1, d2, timedelta(seconds=1)) # true\n\nIf simple boundary checking is needed, this tool is much more light weight than either :code:`DateRange` or :code:`RelativeDate`. Sadly, this is another tool that cannot interoperate with :code:`relativedelta` as it and :code:`timedelta` are unorderable (at least in Python 3).\n\n\nThe MIT License (MIT)\nCopyright (c) 2016 Alec Nikolas Reiter \n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/justanr/datestuff", "keywords": "dates,datetime", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "datestuff", "package_url": "https://pypi.org/project/datestuff/", "platform": "", "project_url": "https://pypi.org/project/datestuff/", "project_urls": { "Homepage": "https://github.com/justanr/datestuff" }, "release_url": "https://pypi.org/project/datestuff/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "Stuff for dates", "version": "0.3.0" }, "last_serial": 4123331, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4adfba14d75c992865721c08337eaf6f", "sha256": "1a0307ee4bb77ff29b0fd1afc938762d5775e4b6734876e6fa902f1ed723678e" }, "downloads": -1, "filename": "datestuff-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4adfba14d75c992865721c08337eaf6f", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 9667, "upload_time": "2016-07-24T17:55:58", "url": "https://files.pythonhosted.org/packages/51/9b/1fe2264f63411ea5a0cf25e3d03b2cc1da3790fbe47ec5748b689c68a51b/datestuff-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "51ed9de7fbac9a7dc5b2b8e21c1887d8", "sha256": "1a565761daa870912546c4b0b8b5da52f66ae1afe1cd4bea3d9cacd28e47e506" }, "downloads": -1, "filename": "datestuff-0.1.0.tar.gz", "has_sig": false, "md5_digest": "51ed9de7fbac9a7dc5b2b8e21c1887d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6357, "upload_time": "2016-07-24T17:55:56", "url": "https://files.pythonhosted.org/packages/0c/90/00319a65a371a8d05f667b5fc770a4d7c2e890a0dbb5819dcd78b9ade286/datestuff-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "6e6084a819462bccab16e1760c7dcc65", "sha256": "518258d6ffe3aaea9fcdcf50aaff31511e4731c573a3a15516e9ea3b087b34e4" }, "downloads": -1, "filename": "datestuff-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6e6084a819462bccab16e1760c7dcc65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6977, "upload_time": "2016-09-13T18:55:07", "url": "https://files.pythonhosted.org/packages/2d/69/82500a69c60da64bacc2b01481abf85226b4e18276b230ff1af72d3d0d30/datestuff-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "8cc9ebfdbf63c7d5baa62dc17d0c83ca", "sha256": "bd729269b3aaa70374367f66d760c43a1cc80edb2aa986835e128d4530389c4d" }, "downloads": -1, "filename": "datestuff-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8cc9ebfdbf63c7d5baa62dc17d0c83ca", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8085, "upload_time": "2018-08-01T05:20:58", "url": "https://files.pythonhosted.org/packages/20/29/65973c7fcd55dc3bf0e2255339a67328a5a14a0b18c42f53bfc512dfbabb/datestuff-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b4b8906e9b0aa676a1232b211e701902", "sha256": "03708548f1916eaacccdb10596100cb91d55a2568682627128aa1355a3b2b770" }, "downloads": -1, "filename": "datestuff-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b4b8906e9b0aa676a1232b211e701902", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8711, "upload_time": "2018-08-01T05:20:59", "url": "https://files.pythonhosted.org/packages/ba/af/95e1621ed30081252862f079db3c723a3d1aff4eba728812d75dab326a1a/datestuff-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8cc9ebfdbf63c7d5baa62dc17d0c83ca", "sha256": "bd729269b3aaa70374367f66d760c43a1cc80edb2aa986835e128d4530389c4d" }, "downloads": -1, "filename": "datestuff-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8cc9ebfdbf63c7d5baa62dc17d0c83ca", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8085, "upload_time": "2018-08-01T05:20:58", "url": "https://files.pythonhosted.org/packages/20/29/65973c7fcd55dc3bf0e2255339a67328a5a14a0b18c42f53bfc512dfbabb/datestuff-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b4b8906e9b0aa676a1232b211e701902", "sha256": "03708548f1916eaacccdb10596100cb91d55a2568682627128aa1355a3b2b770" }, "downloads": -1, "filename": "datestuff-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b4b8906e9b0aa676a1232b211e701902", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8711, "upload_time": "2018-08-01T05:20:59", "url": "https://files.pythonhosted.org/packages/ba/af/95e1621ed30081252862f079db3c723a3d1aff4eba728812d75dab326a1a/datestuff-0.3.0.tar.gz" } ] }