{ "info": { "author": "Chris Caron", "author_email": "lead2gold@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: C++", "Programming Language :: Python", "Programming Language :: Python :: 2.7" ], "description": "[![Paypal](http://repo.nuxref.com/pub/img/paypaldonate.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MHANV39UZNQ5E)\n[![Patreon](http://repo.nuxref.com/pub/img/patreondonate.svg)](https://www.patreon.com/lead2gold)\n\nDate/Time Manipulation\n======================\nDatetools packages itself with 2 tools, dateblock and datemath.\n\n## Dateblock\nDateblock allows you to block (exactly how a Linux/Unix Cron might) _until_ a\nspecific point of time unlike 'sleep' which blocks _for_ a set period of time.\nThe difference is very subtle but can prove to be very useful.\n\nIt offers a few new features that the Internet Systems Consortium (ICS) version\ndoes not (refering to /etc/crontab style). Dateblock specifically offers the ability\nto wake/unblock on a _specific second_ and/or _drift_ for certain period afterwards\nyour calculated time is met (kind of like combining _sleep_ and _ICS Cron_ into one).\n\nPython bindings are additionally included supporting all of the standard datetime\nformats and objects!\n\n__Syntax__:\ndateblock [options]\n\n__Allowed options__:\n```\n -h [ --help ] Show this help screen.\n -t [ --test ] Test (Do not block for the specified period)\n -v [ --verbose ] Verbose mode\n -i [ --isc ] ISC Mode\n -s [ --second ] arg Second (0-59)\n -n [ --minute ] arg Minute (0-59)\n -o [ --hour ] arg Hour (0-23)\n -d [ --dom ] arg Day of Month (1-31)\n -m [ --month ] arg Month (1-12) {Jan=1,...,Dec=12}\n -w [ --dow ] arg Day of Week (0-6) {Sun=0,...,Sat=6}\n -c [ --cron ] arg Cron string formatting\n -x [ --drift ] arg Additional drift time (in seconds).\n```\n\nA variety of syntax is accepted by this tool such as:\n```\n x (Value) where 'x' is represented numerically.\n */x (or /x) (Modulus) where 'x' is represented numerically.\n x-y (or y-x) (Range) where 'x' and 'y' are are represented numerically.\n x,y (Separator) where 'x' and 'y' are are represented numerically.\n```\n\n__Note__: With the exception of the drift option (+), all variations of the syntax\n mentioned above can be mixed if separated using the 'comma' (Separator)\n operator. ie: */a,b,c-d,/e is valid.\n However: x-y-z is not valid, nor is /x/y or /x-y. All values must be\n within the range of it's time type. Thus 400-4000 would never work since\n no time constraint even resides within that range.\n\nThe __--cron__(__-c__) switch allows one to specify the standard cron formatting:\n```\n drift time ----------------------------------------------+\n day of week (0 - 6) (Sunday=0) -----------------------+ |\n month (1 - 12) ------------------------------------+ | |\n day of month (1 - 31) --------------------------+ | | |\n hour (0 - 23) -------------------------------+ | | | |\n min (0 - 59) -----------------------------+ | | | | |\n sec (0 - 59) --------------------------- | | | | | |\n | | | | | | |\n - - - - - - -\n * * * * * * *\n```\nSubstitute an asterisk (*) as a placeholder for arguments you are not\ninterested in. Asterisks are automatically placed in strings missing all 6\narguments (separated by white space).\n\nThe __--isc__ (__-i__) switch makes the cron interpretation equivalent to\nwhat it is today (ISC stands for Internet Systems Consortium). Hence:\n```\n ISC Format (no second or drift)\n\n +----------------------------- min (0 - 59)\n | +----------------------- hour (0 - 23)\n | | +----------------- day of month (1 - 31)\n | | | +----------- month (1 - 12)\n | | | | +----- day of week (0 - 6) (Sunday=0)\n | | | | |\n - - - - -\n * * * * *\n```\n\nThe __--test__(__-t__) switch is your greatest ally. Use this to simply build\nand test your crons to find out when they __would have__ blocked until without\nactually blocking. If you pair the the test with the __--ics__ (__-i__), then\nyou can use this tool to help construct regular crons for _/etc/crontab_ if\nyou're new to the idea and still learning how the crontabs work.\n\n### Drifting:\nDrifting is an option that allows you to adjust the calculated results by some\nadditional time. Lets say you wanted the application to wake up on the 1st\nminute of each 10 min interval (1, 11, 21, 31, 41, 51). Specifying the cron\n(minute) '*/1' would not work. In fact the cron of '*/1' would unblock at\nevery minute. You could however achieve the previous example using a drift\nvalue of '60' (seconds) and a cron (minute) entry of '*/10'.\n\nIn a way, drifting is a little like executing a cron and then sleeping for\nan additional period right afterwards. However this is a much more elegant\nsolution with a more precise blocking period.\n\nSome things to consider about drifting:\n\n- Drifting is always calculated 'after' a specified cron.\n- You can not specify a drifting value on it's own without a cron entry to go\n with it.\n- A drift value is always specified in seconds.\n- You can not drift longer then the interval calculated by the cron itself.\n In the event this occurs, only the remainder (modulus) is kept; the rest is\n is considered overflow and will simply be ignored. Drifting behaves this\n way to prevent missing a segment of time that would have otherwise been\n calculated. For example... lets say you wanted to unblock every hour, your\n cron might look like this: ```dateblock --hour=/1```. With this cron in\n mind, you could never add a drift of a value larger then 1 hour minus \n 1 second (3659 seconds)... Why? Because the _--hour_ entry has already\n pre-defined the time (slice) bounds of 1, therefore a drift value of the\n same (or more) would cause the calculation to spill into _the next_ hour. An\n hour it was pre-calculated to wake on anyway.\n\n Let's say you wanted to wake ever 2 hours. Well your cron would look like this\n ```dateblock --hour=/2```. If you wanted to add a drift into this picture,\n you'd have up to 2 hours minus 1 second (7319) to work with.\n\n However... if you specify a a cron of '*/10' (which would equate to\n unblocking every 10 seconds), your drift window is only a maximum of 9. So\n if you specified a drift of of 11 (seconds), the overflow would leave you\n with an actual drift of '1' (not 11). If you specified 10, then you would\n not drift at all (would be the same as not setting anything at all). This\n is how the modulus works when you overflow the drift value.\n\n- You can use the shortcut character of a _plus_ (_+_) inline on a cron to immediately\n invoke the drift and spare you from writing the extra entries. Hence:\n ```dateblock -c '* */5 +60'``` is the same as writing ```dateblock -c '* */5 * * * * 60'```\n Once you invoke the __+__ character however, any entries found afterwards\n will be treated as an error.\n\n### Examples\nThe following would block until a minute divisible by 10 was reached. Minutes\ndivisible by 10 are: 0,10,20,30,40 and 50.\n```bash\ndateblock -n /10\n```\n\nThe following would block until a second is divisible by 5 was reached and\nonly on hours 3 and 4. This can also be written as such:\n```bash\ndateblock -s /5 -o 3,4\n\n# you can rewrite the above like this too:\ndateblock -c \"/5 * 3,4 * * *\"\n```\n\nThe following would block until the 5 minute of every hour:\n```bash\ndateblock -c \"* 5\"\n\n# you can rewrite the above like this too:\ndateblock -n 5\ndateblock -c \"* 5 * * * *\"\n```\n\nThe following would block until a hour divisible by 5 was reached on the first\nhalf of the month as well as the 20th of the month) Hours divisible by 5 are:\n0, 5,10,15 and 20.\n```bash\ndateblock -o /5 -d 1-14,20\n```\n\nDrifting using the cron was added in v1.0.0 (but was always available using\n__-x__ or __--drift__). The advantage you get from using it inline with the\ncron string is the ability to chain them with multiple drift times using\na comma and or range operator. The modulus one will not work here.\n\nThe following will block until the 5:20 minute mark of each hour (20 seconds\npast)\n```bash\ndateblock -c \"* 5 * * * * 20\"\n\n# you can rewrite the above like this too:\ndateblock -n 5\n\n# You can skip to the drift portion by just denoting a plus (+) as the last\n# entry specified. This is interpreted as a drift time.\ndateblock -c \"* 5 +20\"\n```\nThe expression is considered invalid if more entries are found after the drift\nperiod. However this is still valid:\n```bash\ndateblock -c \"* 5 * * * * +20\"\n```\n\n### DateBlock Python Bindings\nThe DateBlock python bindings are really easy to use too:\n```python\nfrom dateblock import dateblock\nfrom datetime import datetime\n\n# Returns the date object it will unblock at\nresult = dateblock(\"* /20\", block=False)\n\nprint(\"Blocking until %s\" % result.strftime(\"%Y-%m-%d %H:%M:%S\"))\ndateblock(\"* /20\")\nprint(\"Unblocked at %s\" % datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n\n# Perhaps you want to calculate a time relative to somewhere in the past?\n# No problem; lets get a relative time 4 days ago (from now)\nrelative = datetime.now() - timedelta(days=4)\nresult = dateblock(\"* /20\", ref=relative, block=False)\n\n# To use the isc switch with the bindings, just set isc=True (by default\n# it is off). Below would block for the start of each minute (not second\n# had you not set the isc flag)\nresult = dateblock(\"/1\", isc=True)\n\n# Dateblock supports date, time and epoch time too!\n#\n# Date: (yyyy, mm, dd)\nfrom dateblock import date\nresult = dateblock(\"/5\", ref=date(2017, 4, 22))\n\n# Time: (hh, mm, ss)\nfrom dateblock import time\nresult = dateblock(\"/5\", ref=time(10, 5, 0))\n\n# Epoch: seconds\nresult = dateblock(\"/5\", ref=13424236)\n\n```\n\n## Datemath\nDatemath allows you to manipulate a date and or time by adding\nand or subtracting to it. It can help with scripting and calculating\na specific date.\n\n__Syntax__:\ndatemath [options] [-f DateTimeFormat]\n\n__Options__:\n```\n -h [ --help ] Show this help screen.\n -s [ --seconds ] arg Specify the offset (+/-) in seconds.\n -n [ --minutes ] arg Specify the offset (+/-) in minutes.\n -o [ --hours ] arg Specify the offset (+/-) in hours.\n -d [ --days ] arg Specify the offset (+/-) in days.\n -m [ --months ] arg Specify the offset (+/-) in months.\n -y [ --years ] arg Specify the offset (+/-) in years.\n -f [ --format ] arg Specify the desired output format (see $>man date). The\n default is: %Y-%m-%d %H:%M:%S\n```\n\n## Installation\nAssuming you have GNU C++ compiler and the standard development tools that\nusually go with it (make, autoconf, automake, etc) then the following will\ninstall everything for you.\n\n```bash\nautogen.sh\n./configure\nmake\nsudo make install\n```", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/caronc/datetools/", "keywords": "date sleep block time manipulation cron", "license": "GPLv2", "maintainer": "", "maintainer_email": "", "name": "dateblock", "package_url": "https://pypi.org/project/dateblock/", "platform": "", "project_url": "https://pypi.org/project/dateblock/", "project_urls": { "Homepage": "https://github.com/caronc/datetools/" }, "release_url": "https://pypi.org/project/dateblock/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "Python Cron-like date mainpulation", "version": "1.0.3" }, "last_serial": 3825303, "releases": { "1.0.3": [ { "comment_text": "", "digests": { "md5": "76d0a9e00d523ad8cf29013fde09818d", "sha256": "eefa078fbb0b1919d938ec13fd5123e65f58972509b65dbd2f6f80af4edd6d73" }, "downloads": -1, "filename": "dateblock-1.0.3.zip", "has_sig": false, "md5_digest": "76d0a9e00d523ad8cf29013fde09818d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51894, "upload_time": "2018-05-01T23:05:11", "url": "https://files.pythonhosted.org/packages/35/11/7efef857d377e928e108f18ff5b32535c3c1372dab1d5523029be4997649/dateblock-1.0.3.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "76d0a9e00d523ad8cf29013fde09818d", "sha256": "eefa078fbb0b1919d938ec13fd5123e65f58972509b65dbd2f6f80af4edd6d73" }, "downloads": -1, "filename": "dateblock-1.0.3.zip", "has_sig": false, "md5_digest": "76d0a9e00d523ad8cf29013fde09818d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51894, "upload_time": "2018-05-01T23:05:11", "url": "https://files.pythonhosted.org/packages/35/11/7efef857d377e928e108f18ff5b32535c3c1372dab1d5523029be4997649/dateblock-1.0.3.zip" } ] }