arrow-py / arrow

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

Humanize more human version #1125

Open Ione03 opened 1 year ago

Ione03 commented 1 year ago

Increased ability to convert to yesterday instead of 1 day ago, or tomorrow instead of in 1 day. For example :


present = arrow.now() # september 29th (thursday)
past = present.shift(day=1) 
present.humanize(past)  # Tomorrow
past = present.shift(day=0) 
present.humanize(past)  # Just Now, if have second become 10 second ago etc... using existing arrow humanize function
past = present.shift(day=-1)
present.humanize(past)  # Yesterday
past = present.shift(day=-2)
present.humanize(past)  # Tuesday (only get days of week)
past = present.shift(day=-3)
present.humanize(past)  # Monday
past = present.shift(day=-4)
present.humanize(past)  # Sunday
past = present.shift(day=-5)
present.humanize(past)  # Saturday
past = present.shift(day=-6)
present.humanize(past)  # Friday
past = present.shift(day=-7)
present.humanize(past)  # Last Week
past = present.shift(day=-8)
present.humanize(past)  # september 21th (just get date, or use existing arrow humanize function)

I got inspiration from whatsapp app

nijek commented 1 year ago

Is there anybody working on this? If not I'd like to do it.

krisfremen commented 1 year ago

@nijek you can give it a shot, I'm working on generating locales off of CLDR, so if you can work within the data and ranges they have, that would be great!