hkz1fg
Last Updated: February 25, 2016
·
931
· ivanbokii

Extract time and time intervals from strings

Small library that helps you parse a string and get information about time patterns in it.

It parses next patterns:

  • Meeting at 11:00
  • Meeting at 11am
  • Party at 11:45pm
  • Meet Bob at 11:00 for 30m to discuss the project
  • Meet James at 11:00 for 1h
  • Watch Adventure Time from 11:00 to 11pm to stay ~CRAZY~

it supports modifiers for minutes and hours like:

  • m, min, mins, minutes
  • h, hour, hours

it recognizes time patterns ({time}) as:

  • 11:00
  • 11am/pm
  • 3:45pm

and uses those patterns to recognize intervals like:

  • at {time} for {interval}
  • from {time} to {time}

where {interval} can be "30 minutes" or "1 hour" or "1 hour 34min.

Usage examples:

input = "meet Bob at 16:34"
p TodoTimePatterns.parse input

#prints {:hours=>16, :minutes=>34, :interval=>0, :result_string=>"meet Bob"}

https://github.com/spkenny/todo_time_patterns

Setup:

gem install 'todo_time_patterns'

2 Responses
Add your response

3363

+1

over 1 year ago ·
3367

Nice, thanks

over 1 year ago ·