Skip to content

Commit

Permalink
Merge branch 'master' into fix/1089
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii73 authored Nov 11, 2024
2 parents 9a42fe0 + a4144c6 commit 1d86edf
Show file tree
Hide file tree
Showing 109 changed files with 13,841 additions and 9,350 deletions.
6 changes: 6 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[bumpversion]
current_version = 1.2.0
commit = True
tag = True

[bumpversion:file:dateparser/__init__.py]
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]

max-line-length = 119
ignore = W503, E203, E501, E722, F401, E701, E704

exclude =
docs/conf.py
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Apply the auto-formatter black
24c1637dcc77aac006db8ebcfbf5199fa7abac5d
35 changes: 35 additions & 0 deletions .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CIFuzz
on: [pull_request]
permissions: {}
jobs:
Fuzzing:
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'dateparser'
language: python
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'dateparser'
language: python
fuzz-seconds: 600
output-sarif: true
- name: Upload Crash
uses: actions/upload-artifact@v3
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
- name: Upload Sarif
if: always() && steps.build.outcome == 'success'
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: cifuzz-sarif/results.sarif
checkout_path: cifuzz-sarif
50 changes: 35 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: 3.8
- python-version: 3.9
env:
TOXENV: flake8
- python-version: 3.7
env:
TOXENV: py
- python-version: 3.8
env:
TOXENV: py
- python-version: 3.9
env:
TOXENV: py
Expand All @@ -38,18 +32,44 @@ jobs:
- python-version: "3.11"
env:
TOXENV: latest
- python-version: "3.12"
env:
TOXENV: py
- python-version: "3.12"
env:
TOXENV: latest
- python-version: "3.13"
env:
TOXENV: py
- python-version: "3.13"
env:
TOXENV: latest
- python-version: "3.13"
env:
TOXENV: twinecheck
- python-version: "3.12" # Keep in sync with tox.ini
env:
TOXENV: docs
steps:
- uses: actions/checkout@v3
- name: 'Set up Python ${{ matrix.python-version }}'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python-version }}'
python-version: ${{ matrix.python-version }}
- name: Install language-pack-fr
run: sudo apt-get update && sudo apt-get install language-pack-fr
- name: Install python dependencies
run: pip install tox
- name: tox
run: tox -e py
run: sudo apt-get update && sudo apt-get install -y language-pack-fr build-essential
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tests
run: tox -e ${{ matrix.env.TOXENV }}
- name: Upload coverage.xml to codecov
if: ${{ matrix.python-version == '3.9' && matrix.env.TOXENV == 'latest'}}
if: ${{ matrix.env.python-version == '3.9' && matrix.env.TOXENV == 'latest' }}
uses: codecov/codecov-action@v3

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0 # 6.0.0 drops Python 3.7 support
hooks:
- id: flake8
args: ['--config=.flake8']
- repo: https://github.com/psf/black.git
rev: 23.3.0
hooks:
- id: black
exclude: ^dateparser/data/date_translation_data/
- repo: https://github.com/pycqa/isort
rev: 5.12.0 # 5.12 drops Python 3.7 support
hooks:
- id: isort
17 changes: 17 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
formats: all
sphinx:
configuration: docs/conf.py
fail_on_warning: true

build:
os: ubuntu-20.04
tools:
# For available versions, see:
# https://docs.readthedocs.io/en/stable/config-file/v2.html#build-tools-python
python: "3.11" # Keep in sync with .github/workflows/checks.yml

python:
install:
- requirements: docs/requirements.txt
- path: .
70 changes: 70 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,76 @@
History
=======

1.2.0 (2023-11-17)
------------------

New features:

- New ``PREFER_MONTH_OF_YEAR`` setting (#1146)

Fixes:

- Absolute years in Russian are no longer being treated as a number of years in
the past (#1129)

Cleanups and internal improvements:

- Removed the use of ``datetime.utcnow``, deprecated on Python 3.12 (#1179)
- Applied Black formatting to the code base (#1158)
- Initial integration with OSSFuzz (#1198)
- Extended test cases (#1191)


1.1.8 (2023-03-22)
------------------

Improvements:

- Improved date parsing for Chinese (#1148)
- Improved date parsing for Czech (#1151)
- Reorder language by popularity (#1152)
- Fix leak of memory in cache (#1140)
- Add support for "\d units later" (#1154)
- Move modification in CLDR data to yaml (#1153)
- Add support to use timezone via settings to get PREFER_DATES_FROM result (#1155)


1.1.7 (2023-02-02)
------------------

Improvements:

- Add an “ago” synonym for Arabic (#1128)
- Improved date parsing for Czech (#1131)
- Improved date parsing for Indonesian (#1134)


1.1.6 (2023-01-12)
------------------

Improvements:

- Fix the bug where Monday is parsed as a month (#1121)
- Prevent ReDoS in Spanish sentence splitting regex (#1084)


1.1.5 (2022-12-29)
------------------

Improvements:

- Parse short versions of day, month, and year (#1103)
- Add a test for “in 1d” (#1104)
- Update languages_info (#1107)
- Add a workaround for zipimporter not having exec_module before Python 3.10 (#1069)
- Stabilize tests at midnight (#1111)
- Add a test case for French (#1110)

Cleanups:

- Remove the requirements-build file (#1113)


1.1.4 (2022-11-21)
------------------

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include LICENSE
include README.rst
include dateparser_data/settings.py
include requirements.txt
include requirements-build.txt

recursive-include tests *
recursive-exclude * __pycache__
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Key Features
locales <https://dateparser.readthedocs.io/en/latest/supported_locales.html>`__.
- Language autodetection
- Customizable behavior through
`settings <https://dateparser.readthedocs.io/en/latest/usage.html#settings>`__.
`settings <https://dateparser.readthedocs.io/en/latest/settings.html>`__.
- Support for `non-Gregorian calendar
systems <https://dateparser.readthedocs.io/en/latest/introduction.html#supported-calendars>`__.
- Support for dates with timezones abbreviations or UTC offsets
Expand Down Expand Up @@ -144,8 +144,8 @@ For that reason it is important that the input is a valid date, otherwise it cou

To reduce the possibility of receiving false positives, make sure that:

- The input string it's a valid date and it doesn't contain any other words or numbers.
- If you know the language or languages beforehand you add them through the ``languages`` or ``locales`` properties.
- The input string is a valid date and doesn't contain any other words or numbers.
- If you know the language or languages beforehand, you add them through the ``languages`` or ``locales`` properties.


On the other hand, if you want to exclude any of the default parsers
Expand All @@ -156,7 +156,7 @@ are executed, you can do so through the
Installation
------------

Dateparser supports Python >= 3.7. You can install it by doing:
Dateparser supports Python >= 3.9. You can install it by doing:

::

Expand All @@ -172,7 +172,7 @@ If you want to use the jalali or hijri calendar, you need to install the
Common use cases
----------------

**dateparser** can be used with a really different number of purposes,
**dateparser** can be used for a wide variety of purposes,
but it stands out when it comes to:

Consuming data from different sources:
Expand All @@ -191,7 +191,7 @@ Offering natural interaction with users:

- **Tooling and CLI**: allow users to write “3 days ago” to retrieve
information.
- **Search engine**: allow people to search by date in an easiest /
- **Search engine**: allow people to search by date in an easy /
natural format.
- **Bots**: allow users to interact with a bot easily

Expand Down
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ def pytest_collection_modifyitems(session, config, items):
# Avoid executing tests when executing `--flake8` flag (pytest-flake8)
try:
from pytest_flake8 import Flake8Item
if config.getoption('--flake8'):

if config.getoption("--flake8"):
items[:] = [item for item in items if isinstance(item, Flake8Item)]
except ImportError:
pass
34 changes: 26 additions & 8 deletions dateparser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
__version__ = '1.1.4'
__version__ = "1.2.0"

from .date import DateDataParser
from .conf import apply_settings
from .date import DateDataParser

_default_parser = DateDataParser()


@apply_settings
def parse(date_string, date_formats=None, languages=None, locales=None,
region=None, settings=None, detect_languages_function=None):
def parse(
date_string,
date_formats=None,
languages=None,
locales=None,
region=None,
settings=None,
detect_languages_function=None,
):
"""Parse date and time from given date string.
:param date_string:
Expand Down Expand Up @@ -54,11 +61,22 @@ def parse(date_string, date_formats=None, languages=None, locales=None,
"""
parser = _default_parser

if languages or locales or region or detect_languages_function or not settings._default:
parser = DateDataParser(languages=languages, locales=locales,
region=region, settings=settings, detect_languages_function=detect_languages_function)
if (
languages
or locales
or region
or detect_languages_function
or not settings._default
):
parser = DateDataParser(
languages=languages,
locales=locales,
region=region,
settings=settings,
detect_languages_function=detect_languages_function,
)

data = parser.get_date_data(date_string, date_formats)

if data:
return data['date_obj']
return data["date_obj"]
Loading

0 comments on commit 1d86edf

Please sign in to comment.