Skip to main content

Dates for humans

Project description

https://github.com/AleCandido/human_dates/workflows/test/badge.svg https://codecov.io/gh/AleCandido/human_dates/branch/master/graph/badge.svg https://img.shields.io/pypi/v/human-dates2 https://img.shields.io/pypi/dm/human-dates2 https://www.codefactor.io/repository/github/alecandido/human_dates/badge

This is a fork of the original package human_dates made by Jonathan Tushman, but currently unmaintained.

The original package, in turn, was based on a Stack Overflow answer, referencing still another sources (check the post).


I came from the Ruby/Rails world and I missed some of my date sugar. And instead of keeping complaining about it, I thought I would do something about it

It offers two sets of functionality:

  1. and foremost it has a nice time_ago_in_words function.
  2. has some natural language for getting to the beginning and end of things

Note I stole much of this from the following StackOverflow post: http://stackoverflow.com/a/1551394/192791

Note: when you do not pass a time into a function it uses datetime.utcnow()

Installation

$ pip install human_dates

time_ago_in_words Usage

from human_dates import time_ago_in_words, beginning_of_day

print time_ago_in_words()
#prints "just now"

print time_ago_in_words(beginning_of_day())
# prints "8 hours ago"

Natural Language Helpers

from human_dates import *

print beginning_of_day()
print beginning_of_hour()
print beginning_of_year()
print end_of_month()
# and so on ....

# you can also pass a datetime to each of these functions
import human_dates
from datetime import datetime
date = datetime.strptime('Feb 13 2008  1:33PM', '%b %d %Y %I:%M%p')
result = human_dates.end_of_month(date)
print result
# 2008-02-29 23:59:59.999999

Alternatives

Other Important Time Libraries

Project details


Download files

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

Files for human-dates2, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size human_dates2-1.0.2-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size human-dates2-1.0.2.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page