{ "info": { "author": "Stephen Stagg", "author_email": "ste@sta.gg", "bugtrack_url": null, "classifiers": [], "description": " \r\r\n `dateformat` does two things: turn `datetime` objects into strings, and turn strings into `datetime` objects.\r\r\n It's goal is to do these things simply and well, and to satisfy the following criteria:\r\r\n \r\r\n * Be fast enough (see below for benchmarks)\r\r\n * Handle a variety of date formats from multiple sources\r\r\n * Parse and format dates in many timezones and with many timezone offsets\r\r\n * Represent the expected format in a way that a non-technical person may understand\r\r\n * Be explicit about the expected format to prevent heuristic errors\r\r\n \r\r\n > \"But why another date library?\"\r\r\n \r\r\n There isn't currently a python library I've been able to find that matches these \r\r\n requirements well enough for my use-cases. [`Arrow`](http://arrow.readthedocs.io/en/latest/)\r\r\n comes closest, but still isn't quite suitable performance-wise.\r\r\n \r\r\n # Usage\r\r\n \r\r\n All functionality is based around DateFormat() objects:\r\r\n \r\r\n ### `def __init__(self, spec, is_24hour=None)`\r\r\n \r\r\n create a dateformat object from the provided spec string.\r\r\n \r\r\n ```\r\r\n >>> from dateformat import DateFormat\r\r\n \r\r\n >>> date_format = DateFormat(\"YYYY-MM-DD hh:mm:ss.SSSS+HH:MM\")\r\r\n ```\r\r\n \r\r\n If `is_24hour` is not provided, the format will be in 12-hour mode if an am/pm \r\r\n part is present in the spec, otherwise, dates will be in 24-hour mode.\r\r\n \r\r\n DateFormat instances have two methods:\r\r\n \r\r\n ### `def parse(self, data)`\r\r\n \r\r\n Parse a string(`data`) containing a date into a datetime object.\r\r\n \r\r\n ```\r\r\n >>> date = date_format.parse(\"2017-06-03 15:32:00.2364-02:00\")\r\r\n datetime.datetime(2017, 6, 3, 15, 32, 0, 236400, tzinfo=datetime.timezone(datetime.timedelta(-1, 79200)))\r\r\n ```\r\r\n \r\r\n ### `def format(self, date)`\r\r\n \r\r\n Format the passed in `datetime.datetime` object (`date`) as a string:\r\r\n \r\r\n ```\r\r\n >>> print(date_format.format(date))\r\r\n 2017-06-03 15:32:00.2364-02:00\r\r\n ```\r\r\n \r\r\n ## Timezones\r\r\n \r\r\n If any part of the format provides a timezone, or UTC offset, then parsing \r\r\n produces dates with a timezone indicating the relevant UTC offset.\r\r\n \r\r\n Likewise, if a dateformat has a timezone part, then dates passed to `.format()`\r\r\n must include a tzinfo value.\r\r\n \r\r\n If pytz is available, then some level of named timezone support is provided.\r\r\n \r\r\n ## Leading zeros\r\r\n \r\r\n All numeric parts of the date format are zero-padded to the number of characters\r\r\n in the spec. I.e. 'DD' means that the day of the month is zero-padded to 2-digits.\r\r\n \r\r\n During parsing, a missing leading zero is usually ignored, but if there is no separator\r\r\n between parts (for example: YYYYMMDD), then a missing leading zero will cause an error or bad value.\r\r\n \r\r\n Currently, all formatted dates are zero-padded, in the future, this may be controllable.\r\r\n \r\r\n ## Date format specification\r\r\n | Part | Example | Description |\r\r\n |---------|---------|---------------|\r\r\n | `+HHMM` | -0515 | A UTC offset provided as a 2-digit hour, and 2-digit minute, with no separator |\r\r\n | `+HH:MM` | -05:15 | A UTC offset provided as a 2-digit hour, and 2-digit minute, with a ':' separator |\r\r\n | `+HH` | -05 | A UTC offset provided as a 2-digit hour only |\r\r\n | `Dddddd` | Monday | The full locale-specific day of the week (Note, this value is ignored during date parsing, but added during date format) |\r\r\n | `Ddd` | Mon | The locale-specific short name for the day of the week (Ignored during parsing) |\r\r\n | `DD` | 05 | The zero-padded day of the month. |\r\r\n | `MMMMM` | September | Month as locale\u2019s full name |\r\r\n | `MMM` | Sep | Month as locale\u2019s abbreviated name |\r\r\n | `YYYY` | 2017 | Year with century as a number |\r\r\n | `YY` | 17 | Year without century as a zero-padded number |\r\r\n | `hh` | 09 | Hour as a zero-padded number |\r\r\n | `mm` | 06 | Minute as a zero-padded number |\r\r\n | `ss` | 45 | Second as a zero-padded number |\r\r\n | `SSSSSS` | 123456 | Microsecond as a zero-padded decimal number |\r\r\n | `SSSS` | 1234 | 100-microseconds as a zero-padded number |\r\r\n | `SSS` | 123 | milliseconds as a zero-padded number |\r\r\n | `SS` | 12 | 10-milliseconds as a zero-padded number |\r\r\n | `am` `Am` `AM` `pm` `Pm` `PM` | am | either AM or PM depending on the hour. `.format()` matches the case of the spec. If present, the dateformat will default to 12-hour mode |\r\r\n | `of` | | Ignored during parsing, added during formtting |\r\r\n | `st` | th | The appropriate suffix for the day of the month, for example '1_st_ July', '2_nd_ March' |\r\r\n | `\u2423` | T | (Unicode OPEN BOX - U+2423) Matches either the character 'T' or a space ' '. During formatting, 'T' is always used (this is provided to improve flexibility when parsing iso8601 formats) |\r\r\n | space | | Matches one or more spaces during parsing. During formatting, one space will be output |\r\r\n | any of `:/-.,TZ()` | | Ignored during parsing, output as-is during formatting |\r\r\n \r\r\n \r\r\n # Examples\r\r\n \r\r\n | Format | Example |\r\r\n |--------------------------|------------------------|\r\r\n | `YYYY-MM-DDThh:mm:ss` | 2017-06-06T09:45:15 |\r\r\n | `YYYYMMDDhhmmss` | 20170606094515 |\r\r\n | `YYYYMMDDhhmmss.SSSSSSZ` | 20170606094515.123456Z |\r\r\n | `MM/DD/YY hh:mm+HHMM` | 06/06/17 09:45-0500 |\r\r\n \r\r\n \r\r\n # Library comparison\r\r\n \r\r\n ## dateformat \u21c4 datetime (builtin python module)\r\r\n \r\r\n Dateformat is *not* trying to be a replacement for the builtin datetime module. `datetime.datetime` objects are used as the input/output to the parsing and formatting methods.\r\r\n \r\r\n It is designed as a replacement for the `datetime.datetime.strftime` and `datetime.datetime.strptime` methods, providing:\r\r\n \r\r\n * better timezone handling\r\r\n * a simpler/more common syntax for specifying the date formats\r\r\n * slightly faster parsing\r\r\n \r\r\n ## dateformat \u21c4 dateutil.parser.parse()\r\r\n \r\r\n `dateutil.parser.parse`'s intent is to turn a string in an unknown format into a date. It does that by using a variety of heuristics to try to figure out the format the date has been expressed in.\r\r\n \r\r\n This approach is highly useful, and very flexible, but suffers from a couple of drawbacks that dateformat doesn't have:\r\r\n \r\r\n * There is ambiguity about what date will be produced from a given string, there are situations where that risk cannot be accepted, and it's important for the system to only accept a certain date format\r\r\n * Because of all the work that dateutil is doing to work out the format used, it's fairly slow, at just under 10x slower than `strptime`, this is very noticable over 10s - 100s thousands of dates.\r\r\n \r\r\n ## dateformat \u21c4 arrow\r\r\n \r\r\n arrow is the closest to the way dateformat works, the syntax for describing dates is very similar. Unfortunately, arrow constructs its parser every time a date is parsed, creating a significant overhead when parsing each date.\r\r\n \r\r\n ## dateformat \u21c4 iso8601 / ciso8601\r\r\n \r\r\n ciso8601 is _really_ fast. Unfortunately both these libraries only handle a single date format, so are not useful in this situation.\r\r\n \r\r\n # Benchmarks\r\r\n \r\r\n the `benchmark/` dir contains some simple scripts to show how the relative libraries perform at parsing and formatting dates.\r\r\n \r\r\n Running on a 2016 macbook pro, on Python 3.6.3 gave the following results (best of 3 runs):\r\r\n \r\r\n (Please note, the parse time chart y-axis has been clamped to 1s, but dateparser took 16s to complete)\r\r\n \r\r\n ![chart showing relative date parse performance](https://github.com/stestagg/dateformat/raw/master/benchmark/parse_times.png)\r\r\n \r\r\n ![chart showing relative date format performance](https://github.com/stestagg/dateformat/raw/master/benchmark/format_times.png)\r\r\n \r\r\n \r\nKeywords: date time parsing formatting datetime\r\nPlatform: UNKNOWN\r\nClassifier: Development Status :: 3 - Alpha\r\nClassifier: Intended Audience :: Developers\r\nClassifier: Topic :: Software Development :: Build Tools\r\nClassifier: License :: OSI Approved :: MIT License\r\nClassifier: Programming Language :: Python :: 3\r\nClassifier: Programming Language :: Python :: 3.3\r\nClassifier: Programming Language :: Python :: 3.4\r\nClassifier: Programming Language :: Python :: 3.5\r\nProvides-Extra: test\r\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/stestagg/dateformat", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dateformat", "package_url": "https://pypi.org/project/dateformat/", "platform": "", "project_url": "https://pypi.org/project/dateformat/", "project_urls": { "Homepage": "https://github.com/stestagg/dateformat" }, "release_url": "https://pypi.org/project/dateformat/0.9.7/", "requires_dist": null, "requires_python": "", "summary": "Parse and format dates quickly", "version": "0.9.7" }, "last_serial": 5095939, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "c9b071109941dc630a7d8a6250f3773f", "sha256": "e6b565db34f5dfb76d04560d72eafa6fafbbd05b2a364f650bc0a22e2c64fc8f" }, "downloads": -1, "filename": "dateformat-0.9.0.macosx-10.13-x86_64.tar.gz", "has_sig": false, "md5_digest": "c9b071109941dc630a7d8a6250f3773f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14624, "upload_time": "2017-12-08T17:34:01", "url": "https://files.pythonhosted.org/packages/d0/26/954cb8f5c615154cf0f09e9bf3ee900fd2b13e9f3dc166b0ca377376e809/dateformat-0.9.0.macosx-10.13-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "05049ce60e9623a79b468f91ab214e38", "sha256": "05c63d112161c65710cdba110495255d1ebafb398bcc7c94c682a3206128efd8" }, "downloads": -1, "filename": "dateformat-0.9.0-py3.6.egg", "has_sig": false, "md5_digest": "05049ce60e9623a79b468f91ab214e38", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 14587, "upload_time": "2017-12-08T17:34:00", "url": "https://files.pythonhosted.org/packages/20/eb/33aa69a3161ff50d85b8742d75859acd90bfcdbd89e56879a890e3abf86d/dateformat-0.9.0-py3.6.egg" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "5bc007350e249903982c0229f2afe4eb", "sha256": "d13c49568a59986162c77b2f27cfd203b259fa4523ec076d3b683db7dfc06345" }, "downloads": -1, "filename": "dateformat-0.9.1.macosx-10.13-x86_64.tar.gz", "has_sig": false, "md5_digest": "5bc007350e249903982c0229f2afe4eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14657, "upload_time": "2017-12-08T17:35:44", "url": "https://files.pythonhosted.org/packages/70/34/3522ebf6ff66e85470fb9057b90cdd225ea0216378140c785d05c1cf6dd1/dateformat-0.9.1.macosx-10.13-x86_64.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "797bf5c7c300ee4a825a57870dc20c04", "sha256": "068ca93f00199fbe5d537fce633f182b3c983214f6eb50d63da42bca7fa959fd" }, "downloads": -1, "filename": "dateformat-0.9.2.tar.gz", "has_sig": false, "md5_digest": "797bf5c7c300ee4a825a57870dc20c04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10042, "upload_time": "2017-12-08T17:37:46", "url": "https://files.pythonhosted.org/packages/15/ff/5c03c440ededbab084056f093439aa411afcd979547c8cfb94214ecd82e2/dateformat-0.9.2.tar.gz" } ], "0.9.3": [ { "comment_text": "", "digests": { "md5": "b580d91fa30fc1c3ccca9bb2d6607696", "sha256": "c8fc59143c3381111cbaabf62d57ec654e30dd35ee8843d3918be1beffd6ad31" }, "downloads": -1, "filename": "dateformat-0.9.3.tar.gz", "has_sig": false, "md5_digest": "b580d91fa30fc1c3ccca9bb2d6607696", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10535, "upload_time": "2019-03-26T14:06:56", "url": "https://files.pythonhosted.org/packages/42/1f/2c1352ca774ac41e285d845d1e5f1d9dc1a4da7c74bcfee34c45b26ae900/dateformat-0.9.3.tar.gz" } ], "0.9.4": [ { "comment_text": "", "digests": { "md5": "48687e202c48981874dd723c112afde0", "sha256": "c22a873cf8b10c0a05f71c390a43fd2dbc6d7e462fa92b2d21c4525fe172a595" }, "downloads": -1, "filename": "dateformat-0.9.4.tar.gz", "has_sig": false, "md5_digest": "48687e202c48981874dd723c112afde0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10613, "upload_time": "2019-03-26T15:15:36", "url": "https://files.pythonhosted.org/packages/8f/59/4d378ba92ccd10342cfeaec2d86522efa4631e9ac30aa4cc7551cc7066e2/dateformat-0.9.4.tar.gz" } ], "0.9.5": [ { "comment_text": "", "digests": { "md5": "2c158dda9034ad6a089c449aca63d55d", "sha256": "6a6da6837230c8ccb14b3e8182816b5ac56b65cd669d9a448f290859877c30d1" }, "downloads": -1, "filename": "dateformat-0.9.5.tar.gz", "has_sig": false, "md5_digest": "2c158dda9034ad6a089c449aca63d55d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10677, "upload_time": "2019-03-26T16:00:09", "url": "https://files.pythonhosted.org/packages/55/ac/b572d0e16ff5ad1e497134c648d785172a789c3c097f681d39daecb12530/dateformat-0.9.5.tar.gz" } ], "0.9.6": [ { "comment_text": "", "digests": { "md5": "fb85e76cf1189ddbad60ebd36e5af90f", "sha256": "6e59b010cac92d8d34da2990f36f64d51847ce5a0cad115faf04e2fd7e779fa7" }, "downloads": -1, "filename": "dateformat-0.9.6.tar.gz", "has_sig": false, "md5_digest": "fb85e76cf1189ddbad60ebd36e5af90f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10879, "upload_time": "2019-04-03T16:20:25", "url": "https://files.pythonhosted.org/packages/8a/02/f4adaa6a767fa6257f1a6bc0031ac57f989f5b0ed606ae0f2989c459a279/dateformat-0.9.6.tar.gz" } ], "0.9.7": [ { "comment_text": "", "digests": { "md5": "5fddb1144a8c67a805de12136c2d44d1", "sha256": "0bfc5d1ed867ef29ffaccc3c6b4b50dffbb136f5875679fec5fdc436934a4056" }, "downloads": -1, "filename": "dateformat-0.9.7.tar.gz", "has_sig": false, "md5_digest": "5fddb1144a8c67a805de12136c2d44d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10891, "upload_time": "2019-04-04T09:28:44", "url": "https://files.pythonhosted.org/packages/5d/58/05eef6d4a106ad7c64c1f3be19a301ddf384d599e9ca4a53f9ea05b60a5e/dateformat-0.9.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5fddb1144a8c67a805de12136c2d44d1", "sha256": "0bfc5d1ed867ef29ffaccc3c6b4b50dffbb136f5875679fec5fdc436934a4056" }, "downloads": -1, "filename": "dateformat-0.9.7.tar.gz", "has_sig": false, "md5_digest": "5fddb1144a8c67a805de12136c2d44d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10891, "upload_time": "2019-04-04T09:28:44", "url": "https://files.pythonhosted.org/packages/5d/58/05eef6d4a106ad7c64c1f3be19a301ddf384d599e9ca4a53f9ea05b60a5e/dateformat-0.9.7.tar.gz" } ] }