Coder Social home page Coder Social logo

intellidate's Introduction

Intellidate

Intelligent parsing of date-time strings.

This package is inspired by the R package lubridate, and the Ruby gem stamp

Installation

This package can be installed from github using the devtools package.

require(devtools)
install_github("intellidate", "ramnathv")

Usage

intellidate provides five main functions to work with date-time strings.

  1. str_to_date: converts a date string to a Date object
  2. stamp: stamps a date object, given a template string
  3. guess_date_format: detects all formats matching a date string
  4. guess_time_format: detects the format of a time string
  5. guess_datetime_format: detects all formats matching a date-time string

String to Date (str_to_date)

Converts a date string to a Date object.

str_to_date uses a set of simple heuristics to resolve the date components uniquely. If the date cannot be resolved uniquely, str_to_date uses a default ordering of month-date-year to break the ambiguity.

str_to_date("12/14/2011")        #= 2011-12-14
str_to_date("14/12/2011")        #= 2011-12-14
str_to_date("11/10/1989", 'mdy') #= 1989-11-10

Stamp (stamp)

Formats a date-time string based on a user provided template. This function is inspired by the Ruby gem stamp.

Suppose you want to stamp all your graphs based on the message template "Created on Nov 22, 2009 at 23:00 hours". You could do it with stamp by calling

now <- Sys.time() #= "2011-12-15 08:28:58 EST"
stamp("Created on Nov 22, 2009 at 23:00 hours", now)
[1] "Created on Dec 15, 2011 at 08:29 hours"

stamp("21 Aug 2011, 11:15pm", now)

Guess Date Format (guess_date_format)

Given a date string, returns all date formats that match it.

guess_date_format("Jan 1, 1999")           #= "%b %e, %Y"
guess_date_format("Sunday, May 1, 2000")   #= "%A, %B %e, %Y"
guess_date_format("Sun Aug 5")             #= "%a %b %e"
guess_date_format('20 01 89')              #= "%d %m %y"
guess_date_format('1 13 89')               #= "%m %d %y" 
guess_date_format('00/13/10')              #= "%y/%d/%m"
guess_date_format("01-01/99") #= c("%m-%d/%y", "%d-%m/%y"))
guess_date_format("12/11/00") #= c("%m/%d/%y", "%d/%m/%y"))

TODO

intellidate's People

Contributors

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