Giter Club home page Giter Club logo

datesense's Introduction

DateSense

Introduction

DateSense is for detecting the format of date strings. It can be used to return a convenient format string that you can pass to strptime or strftime. It accepts any number of dates as input, which it will assume all share the same format. And if the default parser settings aren't working for your data it's easy to customize the rules which tell the parser what to expect.

Usage

To parse one or more date strings using default settings, you need only two lines. Here's an example that outputs the string "%d %b %Y":

>>> import DateSense
>>> print DateSense.detect_format( ["15 Dec 2014", "9 Jan 2015"] )
%d %b %Y

Customization

Various rule objects tell the parser what assumptions to make regarding how dates are formatted. Here's an example - this rule tells the parser how to recognize parts of date strings that look like they fit the pattern HH:MM:SS.

rule_pattern_hms = DateSense.DSPatternRule( (('%H','%I'),':','%M',':','%S'), posscore = 3 )

Custom rules can be useful if, for example, you have a nonstandard format you need to anticipate that the parser wasn't able to recognize using the default rules. You could add the format as a pattern rule to let the parser know what to expect when it encounters directives in that sequence.

There are a few other kinds of rules, thoroughly documented in DSrule.py. The default rules are all defined as attributes of the DSoptions class so that you can pick and choose as you see fit if you don't want to write your own. If you were to create a collection of rules you wanted the parser to use instead of the default, you could use this syntax:

DateSense.detect_format( dates, rules )

Enjoy!

datesense's People

Contributors

dwyerk avatar nlauchande avatar pineapplemachine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.