{"id":13825824,"url":"https://github.com/kuzmoyev/beautiful-date","last_synced_at":"2025-07-08T22:32:21.323Z","repository":{"id":37919745,"uuid":"126549844","full_name":"kuzmoyev/beautiful-date","owner":"kuzmoyev","description":"Simple and beautiful way to create date and datetime objects in Python.","archived":false,"fork":false,"pushed_at":"2023-09-15T09:25:06.000Z","size":61,"stargazers_count":72,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T11:56:07.979Z","etag":null,"topics":["beautiful","date","date-range","python","simple","timedelta"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuzmoyev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-03-23T23:51:37.000Z","updated_at":"2024-10-09T15:01:50.000Z","dependencies_parsed_at":"2024-01-13T16:26:21.776Z","dependency_job_id":"60adbb14-0af1-4474-a657-1c2f92a482d4","html_url":"https://github.com/kuzmoyev/beautiful-date","commit_stats":{"total_commits":44,"total_committers":4,"mean_commits":11.0,"dds":"0.43181818181818177","last_synced_commit":"5e16466e2bdd3eeb46232a04b19674db91dd81de"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzmoyev%2Fbeautiful-date","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzmoyev%2Fbeautiful-date/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzmoyev%2Fbeautiful-date/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzmoyev%2Fbeautiful-date/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuzmoyev","download_url":"https://codeload.github.com/kuzmoyev/beautiful-date/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225470631,"owners_count":17479366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beautiful","date","date-range","python","simple","timedelta"],"created_at":"2024-08-04T09:01:27.623Z","updated_at":"2024-11-20T04:30:55.259Z","avatar_url":"https://github.com/kuzmoyev.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Beautiful Date\n\n[![PyPI version](https://badge.fury.io/py/beautiful-date.svg)](https://badge.fury.io/py/beautiful-date)\n[![Tests](https://github.com/kuzmoyev/beautiful-date/workflows/Tests/badge.svg)](https://github.com/kuzmoyev/beautiful-date/actions)\n[![Downloads](https://pepy.tech/badge/beautiful-date)](https://pepy.tech/project/beautiful-date)\n\nSimple and beautiful way to create date and datetime objects in Python.\n       \n**Before**:\n\n```python3\nfrom datetime import date, datetime\n\nd = date(year=2018, month=3, day=25)\nt = datetime(year=2018, month=3, day=25, hour=23, minute=45)\n```\n    \n**After**:\n\n```python3\nfrom beautiful_date import *\n\nd = 25/Mar/2018\nt = (25/Mar/2018)[23:45]\n```\n\n## Installation\n\n```bash\npip install beautiful-date\n```\n\n## Examples\n\n### Create Date\n\nUsing months names:\n\n```python3\n\u003e\u003e\u003e from beautiful_date import *\n\n\u003e\u003e\u003e 25/Mar/2018  # European format\nBeautifulDate(2018, 3, 25)\n\u003e\u003e\u003e Mar/25/2018  # US format\nBeautifulDate(2018, 3, 25)\n```\n    \nUsing months numbers:\n    \n```python3\n\u003e\u003e\u003e 25/M[3]/2018  # European format\nBeautifulDate(2018, 3, 25)\n\u003e\u003e\u003e M[3]/25/2018  # US format\nBeautifulDate(2018, 3, 25)\n```\n\nOr alternatively:\n\n```python3\n\u003e\u003e\u003e D @ 25/3/2018  # European format (default)\nBeautifulDate(2018, 3, 25)\n\n\u003e\u003e\u003e D = MDY()  # Add this at the top of your script to use US format. \n\u003e\u003e\u003e d = D @ 3/25/2018  # US format\nBeautifulDate(2018, 3, 25)\n```\n\nYou can also easily retrieve current date as a `BeautifulDate` object and current time using:\n\n```python3\n\u003e\u003e\u003e D.today()\nBeautifulDate(2020, 8, 24)\n\n\u003e\u003e\u003e D.now()\ndatetime.datetime(2020, 8, 24, 0, 59, 12, 451363)\n\n\u003e\u003e\u003e D.tomorrow()\nBeautifulDate(2020, 8, 25)\n\n\u003e\u003e\u003e D.yesterday()\nBeautifulDate(2020, 8, 23)\n```\n\n### Create Datetime\n\nPrevious methods create `BeautifulDate` objects which are inherited from `date` but can be \neasily extended to `datetime` using indexing/slicing:\n \n```python3\n\u003e\u003e\u003e (Oct/16/1995)[:]\ndatetime.datetime(1995, 10, 16, 0, 0)\n\n\u003e\u003e\u003e (Oct/16/1995)[23]\ndatetime.datetime(1995, 10, 16, 23, 0)\n\n\u003e\u003e\u003e (Oct/16/1995)[23:14]\ndatetime.datetime(1995, 10, 16, 23, 14)\n\n\u003e\u003e\u003e (Oct/16/1995)[23:14:10]\ndatetime.datetime(1995, 10, 16, 23, 14, 10)\n```\n\nYou can also use prefix `D @` if you need months by their numbers:    \n    \n```python3\n\u003e\u003e\u003e (D @ 16/10/1995)[:]\ndatetime.datetime(1995, 10, 16, 0, 0)\n\n\u003e\u003e\u003e (D @ 16/10/1995)[23]\ndatetime.datetime(1995, 10, 16, 23, 0)\n\n\u003e\u003e\u003e (D @ 16/10/1995)[23:14]\ndatetime.datetime(1995, 10, 16, 23, 14)\n\n\u003e\u003e\u003e (D @ 16/10/1995)[23:14:10]\ndatetime.datetime(1995, 10, 16, 23, 14, 10)\n```\n    \n### Date/Datetime manipulations:\n\nThis library also provides simple interface for \n[relativedelta](http://dateutil.readthedocs.io/en/stable/relativedelta.html) from \n[dateutil](http://dateutil.readthedocs.io/en/stable/index.html)\n\nNotice that singular time unit (year, month, ...) sets given value, plural (years, months,) adds it.\n\n#### Shortcuts:\n\n```python\n\u003e\u003e\u003e 5*days.from_today\nBeautifulDate(2023, 9, 17)\n\n\u003e\u003e\u003e 1*hours.from_now\ndatetime.datetime(2023, 9, 12, 12, 53, 56)\n\n\u003e\u003e\u003e 3*days.since(15/Mar/2023)\nBeautifulDate(2023, 3, 18)\n\n\u003e\u003e\u003e 5*days.until_today\nBeautifulDate(2023, 9, 7)\n\n\u003e\u003e\u003e 1*hours.until_now\ndatetime.datetime(2023, 9, 12, 11, 13, 4)\n\n\u003e\u003e\u003e 3*days.until(15/Mar/2023)\nBeautifulDate(2023, 3, 12)\n```\n\n#### Adding/Subtracting/Setting timedeltas:\n\n```python3\n\u003e\u003e\u003e d = 26/Mar/2018\n\u003e\u003e\u003e t = d[12:23:15]\n\n\u003e\u003e\u003e d + 2 * years\nBeautifulDate(2020, 3, 26)\n\u003e\u003e\u003e d - 2 * days\nBeautifulDate(2018, 3, 24)\n\n\u003e\u003e\u003e t + 25 * hours\ndatetime.datetime(2018, 3, 27, 13, 23, 15)\n```\n    \nAvailable deltas: `years`, `months`, `weeks`, `days`, `hours`, `minutes`, \n`seconds`, `microseconds`, `leapdays`\n(see [relativedelta](http://dateutil.readthedocs.io/en/stable/relativedelta.html)).\n\n```python3\n\u003e\u003e\u003e d = 26/Mar/2018\n\u003e\u003e\u003e t = d[12:23:15]\n\n\u003e\u003e\u003e d + 2022 * year\nBeautifulDate(2022, 3, 26)\n\u003e\u003e\u003e d += 2 * day\n\u003e\u003e\u003e d\nBeautifulDate(2018, 3, 2)\n\n\u003e\u003e\u003e t + 22 * hour\ndatetime.datetime(2018, 3, 26, 22, 23, 15)\n\u003e\u003e\u003e t += 22 * hour\n\u003e\u003e\u003e t\ndatetime.datetime(2018, 3, 26, 22, 23, 15)\n```\n\nAvailable setters: `year`, `month`, `day`, `hour`, `minute`, `second`, `microsecond`,\n`yearday` and `nlyearday`\n(see [relativedelta](http://dateutil.readthedocs.io/en/stable/relativedelta.html)).\n\n#### Weekdays:\n\nGet next Monday:\n\n```python3\n\u003e\u003e\u003e d = 29/Mar/2018  # Thursday\n\u003e\u003e\u003e d + MO  # Equivalent to MO(1)\nBeautifulDate(2018, 4, 2)\n```\n\nGet second to next Monday:\n\n```python3\n\u003e\u003e\u003e d = 29/Mar/2018\n\u003e\u003e\u003e d + MO(2)\nBeautifulDate(2018, 4, 9)\n```\n\nGet last Saturday:\n\n```python3\n\u003e\u003e\u003e d = 29/Mar/2018\n\u003e\u003e\u003e d - SA\nBeautifulDate(2018, 3, 24)\n```\n\nGet second to last Saturday:\n\n```python3\n\u003e\u003e\u003e d = 29/Mar/2018\n\u003e\u003e\u003e d - SA(2)\nBeautifulDate(2018, 3, 17)\n```\n\nGet second to last Saturday (same as previous):\n\n```python3\n\u003e\u003e\u003e d = 29/Mar/2018\n\u003e\u003e\u003e d + SA(-2)\nBeautifulDate(2018, 3, 17)\n```\n    \n### Util\n\n#### drange:\n\nYou can use `drange` to generate ranges of dates:\n\n```python3\n\u003e\u003e\u003e for d in drange(27/Mar/1994, 5/Apr/1994):\n...     print(d)\n1994-03-27\n1994-03-28\n1994-03-29\n1994-03-30\n1994-03-31\n1994-04-01\n1994-04-02\n1994-04-03\n1994-04-04\n\n\u003e\u003e\u003e for d in drange(27/Mar/1994, 5/Apr/1994, 2*days):\n...     print(d)\n1994-03-27\n1994-03-29\n1994-03-31\n1994-04-02\n1994-04-04\n```\n    \nand datetimes:\n\n```python3\n\u003e\u003e\u003e for dt in drange((27/Mar/1994)[10:25], (4/Apr/1994)[10:10]):\n...     print(dt)\n1994-03-27 10:25:00\n1994-03-28 10:25:00\n1994-03-29 10:25:00\n1994-03-30 10:25:00\n1994-03-31 10:25:00\n1994-04-01 10:25:00\n1994-04-02 10:25:00\n1994-04-03 10:25:00\n\n\u003e\u003e\u003e for dt in drange((27/Mar/1994)[10:25], (4/Apr/1994)[10:10], 20*hours):\n...     print(dt)\n1994-03-27 10:25:00\n1994-03-28 06:25:00\n1994-03-29 02:25:00\n1994-03-29 22:25:00\n1994-03-30 18:25:00\n1994-03-31 14:25:00\n1994-04-01 10:25:00\n1994-04-02 06:25:00\n1994-04-03 02:25:00\n1994-04-03 22:25:00\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuzmoyev%2Fbeautiful-date","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuzmoyev%2Fbeautiful-date","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuzmoyev%2Fbeautiful-date/lists"}