Giter Site home page Giter Site logo

parsedatetime's Introduction

parsedatetime

Parse human-readable date/time strings.

Python 2.7 or greater is required for parsedatetime version 1.0 or greater.

Downloads Travis CI Codecov Requirements Status Dependency Status

Installing

You can install parsedatetime using:

pip install parsedatetime

Running Tests

From the source directory:

make test

To run tests on several python versions, type tox:

$ tox
[... tox creates a virtualenv for every python version and runs tests inside of each]
py27: commands succeeded
py35: commands succeeded

This assumes that you have python2.7, python3.5, etc in PATH or if your using PyEnv then you need to run:

pyenv local 2.6.6 2.7.10 3.5.0

The tests depend on PyICU being installed. PyICU depends on icu4c which on OS X requires homebrew:

brew install icu4c

and then will require that you pass in the LDFLAGS and CPPFLAGS that homebrew will display after the install:

LDFLAGS:  -L/usr/local/opt/icu4c/lib
CPPFLAGS: -I/usr/local/opt/icu4c/include

The Makefile contains the OS X default values for them so you may need to tweak them.

Using parsedatetime

An example of how to use parsedatetime:

import parsedatetime

cal = parsedatetime.Calendar()

cal.parse("tomorrow")

To get it to a Python datetime object:

from datetime import datetime

time_struct, parse_status = cal.parse("tomorrow")
datetime(*time_struct[:6])

Parse datetime with timezone support (using pytz package):

import parsedatetime
import pytz
from pytz import timezone

cal = parsedatetime.Calendar()

datetime_obj, _ = cal.parseDT(datetimeString="tomorrow", tzinfo=timezone("US/Pacific"))

More detailed examples can be found in the examples directory.

Documentation

The generated documentation is included by default in the docs directory and can also be viewed online at https://bear.im/code/parsedatetime/docs/index.html

The docs can be generated by running:

make docs

Notes

The Calendar class has a member property named ptc which is created during the class init method to be an instance of parsedatetime_consts.CalendarConstants().

History

The code in parsedatetime has been implemented over the years in many different languages (C, Clipper, Delphi) as part of different custom/proprietary systems I've worked on. Sadly the previous code is not "open" in any sense of that word.

When I went to work for Open Source Applications Foundation and realized that the Chandler project could benefit from my experience with parsing of date/time text I decided to start from scratch and implement the code using Python and make it truly open.

After working on the initial concept and creating something that could be shown to the Chandler folks the code has now evolved to it's current state with the help the Chandler folks, most especially Darshana.

parsedatetime's People

Contributors

bear avatar philiptzou avatar idpaterson avatar axsapronov avatar geoffreyfloyd avatar zed avatar thedrow avatar sbonnick avatar sashaacker avatar rob1080 avatar livibetter avatar rl-0x0 avatar fake-name avatar dansteeves68 avatar arcimboldo avatar boppreh avatar inean avatar cpatulea avatar ccho-sevenrooms avatar dirkjankrijnders avatar lborgav avatar oxan avatar rmecham avatar rbu avatar

Watchers

Prabhjot Singh Lamba 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.