kijowski / Nadapa

Simple micro-library for human readable dates parsing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nadapa

Nadapa

Simple micro-library for human readable dates parsing.

Table of contents

Synopsis

Nadapa is a small utility library that can be used for extracting DateTime objects from natural language text.

It is written in F# with the use of FParsec parser combinator library.

Installation

To install Nadapa using Nuget, run the following command in the Package Manager Console:

PM> Install-Package Nadapa 

Alternatively you can use the following Paket command:

$ paket add nuget Nadapa

Usage

open Nadapa
let parser = DateParser()

// Try to parse string using current timestamp as a starting point
let basicCase = parser.TryParse("2 days from now")
// basicCase = Some (System.DateTime(2015,8,10))
// assuming that the code was executed on 8 Aug 2015

// Optionally you can specify starting point
let withAnchor = parser.TryParse("yesterday", System.DateTime(1984, 1, 5))
// withAnchor = Some (System.DateTime(1984, 1, 4))

// You can also make parser case sensitive
let csParser = DateParser(caseSensitive=true)

let good = csParser.TryParse("yesterday", System.DateTime(1984, 1, 5))
// good = Some (System.DateTime(1984, 1, 4))
let bad = csParser.TryParse("yEstErDay", System.DateTime(1984, 1, 5))
// bad = None

// Additionally you can modify parser config by loading modified YAML file
let config = ParserConfig()
config.Load("path/to/config.yaml")
let parserWithConfig = DateParser(config)

Authors

License

The MIT License (MIT)

About

Simple micro-library for human readable dates parsing

License:MIT License


Languages

Language:F# 97.3%Language:Shell 2.7%