Skip to content

kmussel/Moment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moment

UPDATE: Moved to its own Repo to be used with multiple languages at MomentLib

Natural Language Date/Time Parser Using Lex/Yacc/C

Moment handles simple and complex expressions. Because it's written in C, it can easily be transferred to many other languages.

To use it:
Add the 4 files to your project.
Include "TimeParser.h"
Then call the method parseDateTimeString(StringToParse), which returns a time_t type.  
You can then turn it into struct tm * with the localtime function. 

Here is what it looks like in objective c:
NSString *when = @"2 days from now at 3pm";
char *whenstr = (char *)[when UTF8String];
time_t finalTime = parseDateTimeString(whenstr);
str_time= localtime(&finalTime);

To get it to work in x-code all you have to do is add the files. X code automatically generates the C files for you.

Example Expressions:

Simple

  • thursday
  • november
  • friday 13:00
  • mon 2:35
  • 4pm
  • 6 in the morning
  • friday 1pm
  • sat 7 in the evening
  • yesterday
  • today
  • tomorrow
  • this tuesday
  • next month
  • this morning
  • last night
  • this second
  • yesterday at 4:00
  • last friday at 20:00
  • last week tuesday
  • tomorrow at 6:45pm
  • afternoon yesterday
  • thursday last week

Complex

  • 3 years ago
  • 5 months before now
  • 7 hours ago
  • 7 days from now
  • 1 week hence
  • in 3 hours
  • 1 year ago tomorrow
  • 3 months ago saturday at 5:00 pm
  • 7 hours before tomorrow at noon
  • 3rd wednesday in november
  • 3rd month next year
  • 3rd thursday this september
  • 4th day last week

Specific Dates

  • January 5
  • dec 25
  • may 27th
  • October 2006
  • jan 3 2010
  • March 14, 2004
  • March 14th, 2004
  • 3 jan 2000
  • 17 april 85
  • 5/27/1979
  • 27/5/1979
  • 1979-05-27
  • Friday
  • 5
  • 4:00
  • 17:00
  • 0800

About

Natural Language Date Parser Using Lex/Yacc/C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published