Skip to content

TurtleAI/chronic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chronic

Build Status

Like Chronic, but for Elixir.

Usage

Add it as a dependency to your project:

defp deps do
  [
    {:chronic, "~> 1.1.2"},
  ]
end

Then you can use it wherever you wish:

{ :ok, time, offset } = Chronic.parse("tuesday 9am")

The time returned is a Calendar.NaiveDateTime from the calendar package. The offset returned is a time zone offset.

If Chronic encounters a format it doesn't recognise, it will return an error tuple:

{ :error, :unknown_format } = Chronic.parse("definitely not a known format, no siree")

If you're not sure what you're going to get back, use a case:

input = "some user input goes here"
case Chronic.parse(input) do
  { :ok, time, offset } ->
    # do something with time + offset
  { :error, :unknown_format } -> 
    # present a good error message to the user
end

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%