past_date2word is library helps you to convert the past date to text
Project description
past_date2word
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 itsTrue
, and if not, he will not add it
NOTE:
long_sentence
parameter will add the hours, minutes and seconds to the sentence if itsTrue
, 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
)
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
)
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
)
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
)
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
)
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
)
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
)
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 ثانية"
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 دقيقة"
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 ساعة"
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 ايام"
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 ايام"
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 اسابيع"
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65ac13296615d2c0cd5859a427b7cbeaea8e630984023fbdff68fb76beac2788 |
|
MD5 | 76a7ec77f7f5c206320ba26540bf01e1 |
|
BLAKE2b-256 | ce89ed263a4d9696d6618f6e0cf8452dde5e827a370acea2ef948f03d4fde119 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52d0b08224f5579f0502475e43b6f677eee9cae93848cae9033a5ec94b2cd40f |
|
MD5 | fdb9a463fe40918991744debaf702c75 |
|
BLAKE2b-256 | ccba989e7f537e6b7915d394a289c3180ec97209d97adde567b1754e763da18a |