Giter VIP home page Giter VIP logo

go-naturaldate's Introduction

Go Natural Date

Natural date time parsing for Go. This package was designed for parsing human-friendly relative date/time ranges in Apex Logs' command-line log search.

Examples

Here are some examples of the types of expressions currently supported, arbitrary text is currently ignored.

  • now
  • today
  • yesterday
  • 5 minutes ago
  • three days ago
  • last month
  • next month
  • one year from now
  • yesterday at 10am
  • last sunday at 5:30pm
  • sunday at 22:45
  • next January
  • last February
  • December 25th at 7:30am
  • 10am
  • 10:05pm
  • 10:05:22pm
  • Restart the server in 5 days from now
  • Remind me on the 25th of December at 7:30am
  • Message me in two weeks
  • See the tests for more examples

Direction

A default direction can be applied using WithDirection() for ambiguous expressions such as sunday, or september. By default naturaldate.Past is used, so they will be equivalent to last sunday and last september.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

go-naturaldate's People

Contributors

danielhouston avatar sinchang avatar tj avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-naturaldate's Issues

Add option to truncate the parsed part from the input string

Prerequisites

  • I searched to see if the issue already exists.

Description

Add a new method that truncates the parsed part of the inputed string and returns the rest.

E.g. if I input please remind me at sunday 22:21 a new method should return the datetime and the string please remind me

Support "6 month" with the future direction

Prerequisites

  • I searched to see if the issue already exists.

Description

~/scripts/golang
❯ datenat.go 6 months from now
2021/03/03

~/scripts/golang
❯ datenat.go 6 month
2020/08/31

~/scripts/golang
❯ datenat.go 6 months
2020/08/31

~/scripts/golang
❯ datenat.go 6 months later
2020/08/31

Also, it's very jarring that the parsing succeeds on these examples. I think these should throw an error, as they contain important keywords like month that have been discarded.

Add option to require less structured input

Right now you need for example "December 5th at 9:30am", whereas this will not work: "5th of december at 9:30am". If we just had a sequence of possible patterns and change Expr to Expr+ then we can basically just loop those, and ignore stop words.

Add truncation options

I zero in some scenarios which make sense for my use-case but having an option would be nice. For example yesterday to me does not mean yesterday at this exact h:m:s, but maybe for some it does.

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.