Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

past_date2word-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

past_date2word-0.1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file past_date2word-0.1.0.tar.gz.

File metadata

  • Download URL: past_date2word-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for past_date2word-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65ac13296615d2c0cd5859a427b7cbeaea8e630984023fbdff68fb76beac2788
MD5 76a7ec77f7f5c206320ba26540bf01e1
BLAKE2b-256 ce89ed263a4d9696d6618f6e0cf8452dde5e827a370acea2ef948f03d4fde119

See more details on using hashes here.

File details

Details for the file past_date2word-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: past_date2word-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for past_date2word-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52d0b08224f5579f0502475e43b6f677eee9cae93848cae9033a5ec94b2cd40f
MD5 fdb9a463fe40918991744debaf702c75
BLAKE2b-256 ccba989e7f537e6b7915d394a289c3180ec97209d97adde567b1754e763da18a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page