2

Are there any ruby gems to parse and standardize store hours? I've seen Chronic, but I don't think it'll work for this specific use case.

For example, how would you parse Mon-Sun 11am-10pm or Hours today: 5:30 AM – 10:00 PM? Do you have to create rules specific to each context? Is there a library that does this already?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
paniwani
  • 659
  • 3
  • 9
  • 18
  • 1
    Have you tried using Chronic with some test cases to see if it fails? Once you have, you can write a little code to massage the values it doesn't cover into something it understands, or write your own DateTime or Time parsers using `strptime`. – the Tin Man Jan 18 '12 at 21:52
  • Both examples failed if parsed directly with Chronic. I think the problem is that Chronic tries to identify a fixed point in time whereas these are durations. So my real question should be how can I parse a generic "duration string" into two fixed points in time. – paniwani Jan 19 '12 at 19:21
  • Good point about the durations. It's not a hard nut to crack. I'll try to remember to take a look at it tonight. Basically though, `String.scan` with a short regex to retrieve the HMS and AM/PM values will be the starting point. – the Tin Man Jan 19 '12 at 20:34

1 Answers1

1

Chronic Duration solves the problem of parsing duration time strings.

paniwani
  • 659
  • 3
  • 9
  • 18