Giter VIP home page Giter VIP logo

collective.prettydate's Introduction

collective.prettydate

collective.prettydate is a package that helps developers to solve some usability issues associated with the utilization of absolute date formating on sites used among different timezones.

When a date is printed as "01/02/2012" it could represent "February 1" or "January 2", depending on the format used. Also, if the site is located on a different timezone, it could take you to situations when today's date is printed as yesterday, or tomorrow's date.

collective.prettydate represents a date on a relative format so it would be displayed as "4 hours ago", "yesterday" or "last week", which is easier to read and understand for most people.

This feature is really nice for news sites or sites with upcoming events.

Travis CI badge Coveralls badge Downloads

Got an idea? Found a bug? Let us know by opening a support ticket.

This product provides a utility which will convert a DateTime object into a human readable text.

from zope.component import getUtility
from collective.prettydate.interfaces import IPrettyDate
date_utility = getUtility(IPrettyDate)

At this point, you can use the 'date' method to convert the DateTime object:

from DateTime import DateTime
today = DateTime()
str_date = date_utility.date(today)

In previous example, 'str_date' will be "now"

The 'date' method also allows 2 additional parameters: 'short' and 'asdays' which will modify the output to be in short format ('h' instead of 'hours', 'd' instead of 'days', etc) and whole days (it will use 'today' instead of any amount of seconds, minutes or hours for current day). They both default to "False".

If your server timezone is configured correctly, and the DateTime object contains valid timezone info, then the text output will reflect the correct time. You do not need to convert date and time between different timezones.

  • '4 hours ago'
  • '4h ago' (short format)
  • 'in 28 minutes'
  • 'in 6 months'
  • 'today'
  • 'last week'
  • 'yesterday'
  • 'last year'

collective.prettydate is fully compatible with DateTime 3.0 which provides a significantly smaller memory footprint.

collective.prettydate's People

Contributors

agnogueira avatar frapell avatar gborelli avatar hvelarde avatar jone avatar petri avatar

Watchers

 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.