arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.7k stars 673 forks source link

Humanize doesn't support "quarter" for granularity #1019

Closed krisfremen closed 2 years ago

krisfremen commented 3 years ago

Issue Description

Humanize doesn't seem to support granularity of "quarter".

But the error raised seems to suggest that it does:

if not granularity:
    raise ValueError(
        "Empty granularity list provided. "
        "Please select one or more from ['second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year']."
    )
>>> arrow.Arrow.utcnow().humanize(granularity=["quarter"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/krisfremen/projects/arrow/arrow/arrow.py", line 1251, in humanize
    raise ValueError(
ValueError: Invalid level of granularity. Please select between 'second', 'minute', 'hour', 'day', 'week', 'month' or 'year'.
>>> arrow.Arrow.utcnow().humanize(granularity=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/krisfremen/projects/arrow/arrow/arrow.py", line 1263, in humanize
    raise ValueError(
ValueError: Empty granularity list provided. Please select one or more from ['second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'].

System Info

systemcatch commented 3 years ago

I think we could support this if we add a class attribute _SECS_PER_QUARTER on https://github.com/arrow-py/arrow/blob/master/arrow/arrow.py#L134 then integrate that into the humanize method.

Alig1493 commented 2 years ago

Quarter as in every three months? I could take a look at this issue if it's up for grabs

krisfremen commented 2 years ago

Quarter as in every three months? I could take a look at this issue if it's up for grabs

Correct. Sure, go for it!

Alig1493 commented 2 years ago
Traceback (most recent call last):
  File "/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/bin/black", line 5, in <module>
    from black import patched_main
  File "/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/black/__init__.py", line 10, in <module>
    import regex as re
  File "/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: code signature in (/Users/ali/.cache/pre-commit/repo7bat5wn8/py_env-python3/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library

Getting the following traceback on make lint

jadchaar commented 2 years ago

Fixed in https://github.com/arrow-py/arrow/pull/1048