Skip to main content

past_date2word

PyPI - Python Version PyPI License Code style: black past_date2word-test

past_date2word is library helps you to convert the past date to text


Requirements


Installation

Use PyPi to install past_date2word.

pip3 install past_date2word

Example

NOTE: Not all cases will be written because they are many, do not worry, you can see the tests file that contains all the possible cases (if you think otherwise, add the test and do a PR, we will be happy with that)

NOTE: with_ago parameter will add "ago" to the end of the sentence if its True, and if not, he will not add it

NOTE: long_sentence parameter will add the hours, minutes and seconds to the sentence if its True, and if not, he will not add it

English

Seconds EN

time = datetime.now() - timedelta(seconds=1)

assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "1 second" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "1 second ago" # Output of past_date2word
)

[Back To Top 🔝]

Minutes EN

time = datetime.now() - timedelta(minutes=9, seconds=34)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "9 minutes and 34 seconds ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "9 minutes and 34 seconds" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "9 minutes ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "9 minutes" # Output of past_date2word
)

[Back To Top 🔝]

Hours EN

time = datetime.now() - timedelta(hours=12, minutes=44)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "12 hours and 44 minutes ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "12 hours and 44 minutes" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "12 hours ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "12 hours" # Output of past_date2word
)

[Back To Top 🔝]

Days EN

time = datetime.now() - timedelta(days=5, hours=15)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "5 days and 15 hours ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "5 days and 15 hours" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "5 days ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "5 days" # Output of past_date2word
)

[Back To Top 🔝]

Weeks EN

time = datetime.now() - timedelta(weeks=2, days=4)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "2 weeks and 4 days ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "2 weeks and 4 days" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "2 weeks and 4 days ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "2 weeks and 4 days" # Output of past_date2word
)

[Back To Top 🔝]

Months EN

# 4 weeks == 1 month
one_month_to_week = 4 * 1

time = datetime.now() - timedelta(weeks=(one_month_to_week * 3) + 2)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "3 months and 2 weeks ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "3 months and 2 weeks" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "3 months and 2 weeks ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "3 months and 2 weeks" # Output of past_date2word
)

[Back To Top 🔝]

Years EN

# 12 month == 1 year
# 4 weeks == 1 month
one_month_to_week = 4 * 1
one_year_to_week = one_month_to_week * 12

time = datetime.now() - timedelta(
    weeks=(one_year_to_week * 12) + (one_month_to_week * 5)
)

assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=True)
    == "12 years and 5 months ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=True)
    == "12 years and 5 months" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=True, long_sentence=False)
    == "12 years and 5 months ago" # Output of past_date2word
)
assert (
    past_date2word(date=time, language="en", with_ago=False, long_sentence=False)
    == "12 years and 5 months" # Output of past_date2word
)

[Back To Top 🔝]

Arabic

Seconds AR

time = datetime.now() - timedelta(seconds=13)

print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 13 ثانية"
"13 ثانية"
"منذ 13 ثانية"
"13 ثانية"

[Back To Top 🔝]

Minutes AR

time = datetime.now() - timedelta(minutes=13, seconds=13)

print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 13 دقيقة و 13 ثانية"
"13 دقيقة و 13 ثانية"
"منذ 13 دقيقة"
"13 دقيقة"

[Back To Top 🔝]

Hours AR

time = datetime.now() - timedelta(hours=13, minutes=13)

print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 13 ساعة و 13 دقيقة"
"13 ساعة و 13 دقيقة"
"منذ 13 ساعة"
"13 ساعة"

[Back To Top 🔝]

Days AR

time = datetime.now() - timedelta(days=6, hours=15)

print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 6 ايام و 15 ساعة"
"6 ايام و 15 ساعة"
"منذ 6 ايام"
"6 ايام"

[Back To Top 🔝]

Weeks AR

time = datetime.now() - timedelta(weeks=3, days=4)

print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 3 اسابيع و 4 ايام"
"3 اسابيع و 4 ايام"
"منذ 3 اسابيع و 4 ايام"
"3 اسابيع و 4 ايام"

[Back To Top 🔝]

Months AR

one_month_to_week = 4 * 1


time = datetime.now() - timedelta(weeks=(one_month_to_week * 11) + 3)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 11 شهر و 3 اسابيع"
"11 شهر و 3 اسابيع"
"منذ 11 شهر و 3 اسابيع"
"11 شهر و 3 اسابيع"

[Back To Top 🔝]

Years AR

# 12 month == 1 year
# 4 weeks == 1 month
one_month_to_week = 4 * 1
one_year_to_week = one_month_to_week * 12

time = datetime.now() - timedelta(
    weeks=(one_year_to_week * 12) + (one_month_to_week * 5)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=True)
)
print(
    past_date2word(date=time, language="ar", with_ago=True, long_sentence=False)
)
print(
    past_date2word(date=time, language="ar", with_ago=False, long_sentence=False)
)
المخرجات
"منذ 12 سنة و 5 اشهر"
"12 سنة و 5 اشهر"
"منذ 12 سنة و 5 اشهر"
"12 سنة و 5 اشهر"

License

GPLv3

Metadata

Release files for past-date2word 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for past-date2word 0.1.0
File Size Uploaded Provenance Actions
past_date2word-0.1.0.tar.gz 6.3 kB Without provenance Details for past_date2word-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for past-date2word 0.1.0
File Interpreter ABI Platform Actions
past_date2word-0.1.0-py3-none-any.whl Python 3 none any Details for past_date2word-0.1.0-py3-none-any.whl

Total release size: 23.4 kB

Release files / past_date2word-0.1.0.tar.gz

Download URL past_date2word-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
65ac13296615d2c0cd5859a427b7cbeaea8e630984023fbdff68fb76beac2788
BLAKE2b-256 checksum
How to use checksums
ce89ed263a4d9696d6618f6e0cf8452dde5e827a370acea2ef948f03d4fde119
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.0.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / past_date2word-0.1.0-py3-none-any.whl

Download URL past_date2word-0.1.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52d0b08224f5579f0502475e43b6f677eee9cae93848cae9033a5ec94b2cd40f
BLAKE2b-256 checksum
How to use checksums
ccba989e7f537e6b7915d394a289c3180ec97209d97adde567b1754e763da18a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.0.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for past-date2word 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page