{"id":29200901,"url":"https://github.com/datopian/flexidate","last_synced_at":"2025-07-02T11:06:20.543Z","repository":{"id":5010336,"uuid":"6168753","full_name":"datopian/flexidate","owner":"datopian","description":"Date parsing and normalization utilities for Python.","archived":false,"fork":false,"pushed_at":"2023-10-18T01:18:57.000Z","size":42,"stargazers_count":22,"open_issues_count":5,"forks_count":15,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-06-23T16:49:19.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"micmro/svg-spinner","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datopian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-11T04:47:18.000Z","updated_at":"2024-11-18T16:42:59.000Z","dependencies_parsed_at":"2024-06-21T03:54:37.727Z","dependency_job_id":"00145374-ee3b-4886-bb2c-510d822e191d","html_url":"https://github.com/datopian/flexidate","commit_stats":{"total_commits":34,"total_committers":8,"mean_commits":4.25,"dds":0.8235294117647058,"last_synced_commit":"b343b08934614fef28672c24f8a277f0e6281ee3"},"previous_names":["okfn/flexidate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/datopian/flexidate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datopian%2Fflexidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datopian%2Fflexidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datopian%2Fflexidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datopian%2Fflexidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datopian","download_url":"https://codeload.github.com/datopian/flexidate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datopian%2Fflexidate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261515912,"owners_count":23170656,"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":[],"created_at":"2025-07-02T11:06:13.946Z","updated_at":"2025-07-02T11:06:15.590Z","avatar_url":"https://github.com/datopian.png","language":"Python","readme":"\u003c!--[![Build Status](https://travis-ci.org/okfn/flexidate.svg?branch=master)](https://travis-ci.org/okfn/flexidate) [![codecov.io](http://codecov.io/github/okfn/flexidate/coverage.svg?branch=master)](http://codecov.io/github/okfn/flexidate?branch=master)--\u003e\n\n\n# About\n\nThe `flexidate` library supports date parsing and normalization using the `FlexiDate` class. It provides functionality to:\n\n1. Cast dates according to the [Anno Domini](https://en.wikipedia.org/wiki/Anno_Domini) notation system (e.g., 399 BC, AD 417) as well as the [Common Era](https://en.wikipedia.org/wiki/Common_Era) notation system (e.g., 399 B.C.E, 417 CE)\n1. Handle dates before  AD 1 or 1 CE\n1. Cast imprecise dates (c.1860, 18??, fl. 1534, etc)\n1. Normalize dates to machine-readable data types\n1. Create sortable date objects\n\nFlexidate builds on the excellent [dateutil](https://dateutil.readthedocs.org/en/latest/).\n\nFor more information see [this blog post](http://www.rufuspollock.org/2009/06/18/flexible-dates-in-python/).\n\n\n# Examples\n\nFirst load a string into the `parse` function, which returns a `FlexiDate` object:\n\n``` python\n\u003e\u003e\u003e from flexidate import parse\n\u003e\u003e\u003e fd = parse('Jan 1890')\n```\n\nOnce you have your date in a `FlexiDate` object, you can get access to attributes:\n\n``` python\n\u003e\u003e\u003e fd.year # u'1890'\n'1890'\n\u003e\u003e\u003e fd.month # u'01'\n'01'\n```\n\nNote how all fields are retained as strings, which prevents the loss of original input data.\n\nThe `FlexiDate` object exports to other formats (e.g., `int` or `datetime`):\n\n``` python\n\u003e\u003e\u003e fd.as_float()\n1890.0833333333333\n\u003e\u003e\u003e fd.as_datetime()\ndatetime.datetime(1890, 1, 1, 0, 0)\n```\n\n\u003c!--1. TODO: figure out how to do BC years and say this up top --\u003e\nTo cast years before AD 1:\n\nTo case dates before Christ (i.e., Anno Domini or Common Era):\n\n``` python\n\u003e\u003e\u003e fd = parse('399 BC')\n\u003e\u003e\u003e fd\n\u003cclass 'flexidate.FlexiDate'\u003e -0399\n\u003e\u003e\u003e fd.year\n'-0399'\n```\n\nOr after:\n``` python\n\u003e\u003e\u003e fd = parse('AD 417')\n\u003e\u003e\u003e fd\n\u003cclass 'flexidate.FlexiDate'\u003e 0417\n```\n\nIncluding with Common Era notation:\n``` python\n\u003e\u003e\u003e fd_ce = parse('399 BCE')\n\u003e\u003e\u003e fd_ce\n\u003cclass 'flexidate.FlexiDate'\u003e -0399\n\u003e\u003e\u003e fd_ad = parse('399 BC')\n\u003e\u003e\u003e fd_ce.year == fd_ad.year\nTrue\n```\n\n``` python\n\u003e\u003e\u003e fd_ce = parse('417 CE')\n\u003e\u003e\u003e fd_ce\n\u003cclass 'flexidate.FlexiDate'\u003e 0417\n\u003e\u003e\u003e fd_ad = parse('AD 417')\n\u003e\u003e\u003e fd_ce.year == fd_ad.year\nTrue\n```\n\n`FlexiDate` supports hour, minute, second, and microsecond:\n\n``` python\n\u003e\u003e\u003e fd = parse('417-06-01 10')\n\u003cclass 'flexidate.FlexiDate'\u003e 2016-01-06 10\n\u003e\u003e\u003e fd.hour\n'10'\n\u003e\u003e\u003e fd.minute\n''\n```\n\n`parse` can capture various fuzzy date attributes. In `FlexiDate` this becomes available as the attribute `qualifier`:\n\n``` python\n\u003e\u003e\u003e fd = parse('417?')\n\u003e\u003e\u003e fd\n\u003cclass 'flexidate.FlexiDate'\u003e  [b'UNPARSED: 417?']\n\u003e\u003e\u003e fd.qualifier\nb'UNPARSED: 417?'\n```\n\n``` python\n\u003e\u003e\u003e fd = parse('c. 417')\n\u003e\u003e\u003e fd\n\u003cclass 'flexidate.FlexiDate'\u003e 0417 [Note 'circa' : c. 417]\n\u003e\u003e\u003e fd.qualifier\n\"Note 'circa' : c. 417\"\n```\n\n``` python\n\u003e\u003e\u003e fd = parse('177?')\n\u003e\u003e\u003e fd\n\u003cclass 'flexidate.FlexiDate'\u003e  [b'UNPARSED: 177?']\n\u003e\u003e\u003e fd.qualifier\nb'UNPARSED: 177?'\n```\n\nComparison of dates:\n\n``` python\n\u003e\u003e\u003e fd1 = parse('399 BC')\n\u003e\u003e\u003e fd2 = parse('AD 200')\n\u003e\u003e\u003e fd1.year \u003c fd2.year\nTrue\n\u003e\u003e\u003e fd1.year \u003e fd2.year\nFalse\n```\n\n\n# Developers\n\nTo install required development dependencies: `pip install -r requirements.txt`.\n\nPatches are welcome. Please include additional tests where relevant.\n\n## Run Tests\n\nTests can be found in `flexidate/test_flexidate.py`. Run using `python flexidate/test_flexidate.py` or, for a full coverage report, `nosetests --no-skip --with-coverage`.\n\n## Package\n\nTo build locally: `python -m build` (you need [`build`](https://github.com/pypa/build) for it).\n\n\n## TODO\n\n* ~~Cast dates written in the [Common Era](https://en.wikipedia.org/wiki/Common_Era) notation system (e.g., 399 BCE, 417 CE)~~\n\n\n# License\n\nMIT. See `LICENSE`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatopian%2Fflexidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatopian%2Fflexidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatopian%2Fflexidate/lists"}