Coder Social home page Coder Social logo

digyter / timeago Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hustcc/timeago

0.0 2.0 0.0 33 KB

:hourglass: A very simple python library, used to format datetime with `*** time ago` statement. eg: "3 hours ago".

Home Page: http://timeago.org/

License: MIT License

Python 99.55% Shell 0.45%

timeago's Introduction

timeago

A very simple python lib, used to format datetime with *** time ago statement. Javascript version here. timeago.js.

Build Status PyPi Status Python Versions PyPi Downloads

Such as:

just now
12 seconds ago
3 minutes ago
2 hours ago
24 days ago
6 months ago
2 years ago

in 12 seconds
in 3 minutes
in 2 hours
in 24 days
in 6 months
in 2 years

or Chinese locale statement.

Install

pip install timeago

Usage & Example

# -*- coding: utf-8 -*-
import timeago, datetime

now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)

date = datetime.datetime.now()

# locale
print (timeago.format(date, now, 'zh_CN')) # will print `3分钟前`

# input datetime
print (timeago.format(date, now)) # will print 3 minutes ago

# input timedelta
print (timeago.format(datetime.timedelta(seconds = 60 * 3.4))) # will print 3 minutes ago

# input date, auto add time(0, 0, 0)
print (timeago.format(datetime.date(2016, 5, 27), now))

# input datetime formated string
print (timeago.format('2016-05-27 12:12:03', '2016-05-27 12:12:12')) # will print just now

# inverse two parameters
print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print a while

Method & Parameter

only one API format.

Three parameters of method format:

  • date: the parameter which will be formated, must be instance of datetime / timedelta or datetime formated string.
  • now: reference time, must be instance of datetime or datetime formated string.
  • locale: the locale code, only zh_CN / en supported, default en. Other locale, you can pull request.

Localization

  1. foke the project
  2. add locale.py file in the locales folder.
  3. pull a request.

timeago's People

Contributors

meyt avatar ajphukan avatar zjuchenyuan avatar hakashun avatar justinwhite avatar digyter avatar hustcc avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.