├── iphoneExample └── NLDP │ ├── NLDP │ ├── en.lproj │ │ ├── InfoPlist.strings │ │ └── KMViewController.xib │ ├── NLDP-Prefix.pch │ ├── main.m │ ├── KMViewController.h │ ├── KMAppDelegate.h │ ├── NLDP-Info.plist │ ├── KMViewController.m │ └── KMAppDelegate.m │ └── NLDP.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── kmussel.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ ├── xcuserdata │ └── kmussel.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── NLDP.xcscheme │ └── project.pbxproj ├── LICENSE ├── TimeParser.h ├── README.md ├── TimeParser.c ├── tokeIt.l └── parseIt.ym /iphoneExample/NLDP/NLDP/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP.xcodeproj/project.xcworkspace/xcuserdata/kmussel.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/problem/Moment/master/iphoneExample/NLDP/NLDP.xcodeproj/project.xcworkspace/xcuserdata/kmussel.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/NLDP-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'NLDP' target in the 'NLDP' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 4/29/12. 6 | // Copyright (c) 2012 FrenzyLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "KMAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KMAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/KMViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KMViewController.h 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 4/29/12. 6 | // Copyright (c) 2012 FrenzyLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KMViewController : UIViewController 12 | 13 | @property (nonatomic, retain) IBOutlet UITextField *field; 14 | @property (nonatomic, retain) IBOutlet UILabel *timeLabel; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/KMAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KMAppDelegate.h 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 4/29/12. 6 | // Copyright (c) 2012 FrenzyLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class KMViewController; 12 | 13 | @interface KMAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) KMViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP.xcodeproj/xcuserdata/kmussel.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NLDP.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 39D534DD154DC32100990982 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Kevin Musselman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/NLDP-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | kmussel.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /TimeParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // TimeParser.h 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 6/28/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define DIGILEN (int)(log10 (INT_MAX) +3) 17 | 18 | 19 | extern int yyparse(); 20 | extern char * yytext; 21 | typedef struct yy_buffer_state *YY_BUFFER_STATE; 22 | void yy_switch_to_buffer(YY_BUFFER_STATE); 23 | YY_BUFFER_STATE yy_scan_string (const char *); 24 | 25 | struct modifier 26 | { 27 | int amount[9]; 28 | int specAmount[3]; 29 | int specValue[3]; 30 | 31 | }; 32 | 33 | struct modifier mymodifier; 34 | struct modifier fromModifier; 35 | 36 | struct tm currentTime; 37 | 38 | struct tm *str_time; 39 | int *timePointer[7]; 40 | 41 | struct tm temp_time; 42 | struct tm set_time; 43 | 44 | time_t curtime; 45 | time_t initialTime; 46 | 47 | 48 | int changeAmount[9]; 49 | int fromChangeAmount[9]; 50 | 51 | int specAmount[3]; 52 | int finalSpecAmount[3]; 53 | 54 | char * unusedText; 55 | 56 | 57 | void setCurrentTime(void); 58 | void setTime(int hr, int min, int sec); 59 | void setDate(int day, int month, int year, int wday); 60 | 61 | void setBoth(int sec, int min, int hr, int day, int month, int year, int wday); 62 | char* join_strings(int* strings, char* seperator, int count); 63 | void setDayOfWeek(int weekday, int *amount); 64 | void setFinalTime(struct tm *temp, int amount[], int *change); 65 | void itoa(int n, char s[]); 66 | 67 | time_t parseDateTimeString(const char *str); 68 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/KMViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // KMViewController.m 3 | // Moment 4 | // 5 | // Created by Kevin Musselman on 4/29/12. 6 | // Copyright (c) 2012 FrenzyLabs. All rights reserved. 7 | // 8 | 9 | #import "KMViewController.h" 10 | #import "TimeParser.h" 11 | 12 | @interface KMViewController () 13 | 14 | @end 15 | 16 | @implementation KMViewController 17 | @synthesize field, timeLabel; 18 | 19 | - (void)viewDidLoad 20 | { 21 | [super viewDidLoad]; 22 | self.field.delegate = self; 23 | 24 | // Do any additional setup after loading the view, typically from a nib. 25 | } 26 | 27 | - (void)viewDidUnload 28 | { 29 | [super viewDidUnload]; 30 | // Release any retained subviews of the main view. 31 | } 32 | 33 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 34 | { 35 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 36 | return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 37 | } else { 38 | return YES; 39 | } 40 | } 41 | 42 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 43 | { 44 | NSString *when = [textField.text lowercaseString]; 45 | char *whenstr = (char *)[when UTF8String]; 46 | time_t finalTime = parseDateTimeString(whenstr); 47 | str_time= localtime(&finalTime); 48 | 49 | // NSLog(@"the string is %s", unusedText); 50 | 51 | NSString *thedate = [NSString stringWithCString:asctime(str_time) encoding:NSUTF8StringEncoding]; 52 | self.timeLabel.text = thedate; 53 | 54 | [textField resignFirstResponder]; 55 | return YES; 56 | } 57 | 58 | 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Moment 2 | ====== 3 | 4 | Natural Language Date/Time Parser Using Lex/Yacc/C 5 | 6 | Moment handles simple and complex expressions. Because it's written in C, it can easily be transferred to many other languages. 7 |
 8 | To use it:
 9 | Add the 4 files to your project.
10 | Include "TimeParser.h"
11 | Then call the method parseDateTimeString(StringToParse), which returns a time_t type.  
12 | You can then turn it into struct tm * with the localtime function. 
13 | 
14 | 15 | Here is what it looks like in objective c:
16 | 17 | NSString *when = @"2 days from now at 3pm";
18 | char *whenstr = (char *)[when UTF8String];
19 | time_t finalTime = parseDateTimeString(whenstr);
20 | str_time= localtime(&finalTime);
21 |
22 | 23 | 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. 24 | 25 |

Example Expressions:

26 | 27 |

Simple

28 |
    29 | 30 | 31 |
  • thursday
  • 32 |
  • november
  • 33 |
  • friday 13:00
  • 34 |
  • mon 2:35
  • 35 |
  • 4pm
  • 36 |
  • 6 in the morning
  • 37 |
  • friday 1pm
  • 38 |
  • sat 7 in the evening
  • 39 |
  • yesterday
  • 40 |
  • today
  • 41 |
  • tomorrow
  • 42 |
  • this tuesday
  • 43 |
  • next month
  • 44 |
  • this morning
  • 45 |
  • last night
  • 46 |
  • this second
  • 47 |
  • yesterday at 4:00
  • 48 |
  • last friday at 20:00
  • 49 |
  • last week tuesday
  • 50 |
  • tomorrow at 6:45pm
  • 51 |
  • afternoon yesterday
  • 52 |
  • thursday last week
  • 53 | 54 |
55 |

Complex

56 |
    57 |
  • 3 years ago
  • 58 |
  • 5 months before now
  • 59 |
  • 7 hours ago
  • 60 |
  • 7 days from now
  • 61 |
  • 1 week hence
  • 62 |
  • in 3 hours
  • 63 |
  • 1 year ago tomorrow
  • 64 |
  • 3 months ago saturday at 5:00 pm
  • 65 |
  • 7 hours before tomorrow at noon
  • 66 |
  • 3rd wednesday in november
  • 67 |
  • 3rd month next year
  • 68 |
  • 3rd thursday this september
  • 69 |
  • 4th day last week
  • 70 |
71 | 72 |

Specific Dates

73 |
    74 |
  • January 5
  • 75 |
  • dec 25
  • 76 |
  • may 27th
  • 77 |
  • October 2006
  • 78 |
  • jan 3 2010
  • 79 |
  • March 14, 2004
  • 80 |
  • March 14th, 2004
  • 81 |
  • 3 jan 2000
  • 82 |
  • 17 april 85
  • 83 |
  • 5/27/1979
  • 84 |
  • 27/5/1979
  • 85 |
  • 1979-05-27
  • 86 |
  • Friday
  • 87 |
  • 5
  • 88 |
  • 4:00
  • 89 |
  • 17:00
  • 90 |
  • 0800
  • 91 |
92 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/KMAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // KMAppDelegate.m 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 4/29/12. 6 | // Copyright (c) 2012 FrenzyLabs. All rights reserved. 7 | // 8 | 9 | #import "KMAppDelegate.h" 10 | 11 | #import "KMViewController.h" 12 | 13 | @implementation KMAppDelegate 14 | 15 | @synthesize window = _window; 16 | @synthesize viewController = _viewController; 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 21 | // Override point for customization after application launch. 22 | self.viewController = [[KMViewController alloc] initWithNibName:@"KMViewController" bundle:nil]; 23 | self.window.rootViewController = self.viewController; 24 | [self.window makeKeyAndVisible]; 25 | return YES; 26 | } 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application 29 | { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 32 | } 33 | 34 | - (void)applicationDidEnterBackground:(UIApplication *)application 35 | { 36 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | - (void)applicationWillEnterForeground:(UIApplication *)application 41 | { 42 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | - (void)applicationDidBecomeActive:(UIApplication *)application 46 | { 47 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | } 49 | 50 | - (void)applicationWillTerminate:(UIApplication *)application 51 | { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP.xcodeproj/xcuserdata/kmussel.xcuserdatad/xcschemes/NLDP.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 50 | 51 | 57 | 58 | 59 | 60 | 61 | 62 | 68 | 69 | 75 | 76 | 77 | 78 | 80 | 81 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP/en.lproj/KMViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1296 5 | 11D50d 6 | 2182 7 | 1138.32 8 | 568.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 1179 12 | 13 | 14 | IBUILabel 15 | IBUIView 16 | IBUITextField 17 | IBProxyObject 18 | 19 | 20 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 21 | 22 | 23 | PluginDependencyRecalculationVersion 24 | 25 | 26 | 27 | 28 | IBFilesOwner 29 | IBCocoaTouchFramework 30 | 31 | 32 | IBFirstResponder 33 | IBCocoaTouchFramework 34 | 35 | 36 | 37 | 274 38 | 39 | 40 | 41 | 292 42 | {{20, 20}, {262, 31}} 43 | 44 | 45 | 46 | _NS:9 47 | NO 48 | YES 49 | IBCocoaTouchFramework 50 | 0 51 | 52 | 3 53 | 54 | 3 55 | MAA 56 | 57 | 2 58 | 59 | 60 | YES 61 | 17 62 | 63 | YES 64 | IBCocoaTouchFramework 65 | 66 | 67 | 1 68 | 14 69 | 70 | 71 | Helvetica 72 | 14 73 | 16 74 | 75 | 76 | 77 | 78 | 292 79 | {{20, 80}, {47, 30}} 80 | 81 | 82 | 83 | _NS:9 84 | NO 85 | YES 86 | 7 87 | NO 88 | IBCocoaTouchFramework 89 | Time: 90 | 91 | 1 92 | MCAwIDAAA 93 | 94 | 95 | 0 96 | 10 97 | 98 | 1 99 | 17 100 | 101 | 102 | Helvetica 103 | 17 104 | 16 105 | 106 | 107 | 108 | 109 | 292 110 | {{75, 80}, {207, 30}} 111 | 112 | 113 | _NS:9 114 | NO 115 | YES 116 | 7 117 | NO 118 | IBCocoaTouchFramework 119 | 120 | 121 | 122 | 0 123 | 10 124 | 125 | 126 | 127 | 128 | {{0, 20}, {320, 460}} 129 | 130 | 131 | 132 | 3 133 | MC43NQA 134 | 135 | 136 | NO 137 | 138 | IBCocoaTouchFramework 139 | 140 | 141 | 142 | 143 | 144 | 145 | view 146 | 147 | 148 | 149 | 7 150 | 151 | 152 | 153 | field 154 | 155 | 156 | 157 | 11 158 | 159 | 160 | 161 | timeLabel 162 | 163 | 164 | 165 | 12 166 | 167 | 168 | 169 | 170 | 171 | 0 172 | 173 | 174 | 175 | 176 | 177 | -1 178 | 179 | 180 | File's Owner 181 | 182 | 183 | -2 184 | 185 | 186 | 187 | 188 | 6 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 8 199 | 200 | 201 | 202 | 203 | 9 204 | 205 | 206 | 207 | 208 | 10 209 | 210 | 211 | 212 | 213 | 214 | 215 | KMViewController 216 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 217 | UIResponder 218 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 219 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 220 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 221 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 222 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 223 | 224 | 225 | 226 | 227 | 228 | 12 229 | 230 | 231 | 232 | 233 | KMViewController 234 | UIViewController 235 | 236 | UITextField 237 | UILabel 238 | 239 | 240 | 241 | field 242 | UITextField 243 | 244 | 245 | timeLabel 246 | UILabel 247 | 248 | 249 | 250 | IBProjectSource 251 | ./Classes/KMViewController.h 252 | 253 | 254 | 255 | 256 | 0 257 | IBCocoaTouchFramework 258 | 259 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 260 | 261 | 262 | YES 263 | 3 264 | 1179 265 | 266 | 267 | -------------------------------------------------------------------------------- /TimeParser.c: -------------------------------------------------------------------------------- 1 | // 2 | // TimeParser.c 3 | // NLDP 4 | // 5 | // Created by Kevin Musselman on 6/28/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include "TimeParser.h" 10 | 11 | 12 | void setCurrentTime() 13 | { 14 | 15 | curtime = time(NULL); 16 | str_time= localtime(&curtime); 17 | 18 | timePointer[0] = &(str_time->tm_sec); 19 | timePointer[1] = &(str_time->tm_min); 20 | timePointer[2] = &(str_time->tm_hour); 21 | timePointer[3] = &(str_time->tm_mday); 22 | timePointer[4] = &(str_time->tm_wday); 23 | timePointer[5] = &(str_time->tm_mon); 24 | timePointer[6] = &(str_time->tm_year); 25 | 26 | initialTime = time(NULL); 27 | temp_time = *(localtime(&initialTime)); 28 | temp_time.tm_sec = -1; 29 | temp_time.tm_min = -1; 30 | temp_time.tm_hour = -1; 31 | temp_time.tm_mday = -1; 32 | temp_time.tm_wday = -1; 33 | temp_time.tm_mon = -1; 34 | temp_time.tm_year = -1; 35 | 36 | set_time.tm_sec = -1; 37 | set_time.tm_min = -1; 38 | set_time.tm_hour = -1; 39 | set_time.tm_mday = -1; 40 | set_time.tm_wday = -1; 41 | set_time.tm_mon = -1; 42 | set_time.tm_year = -1; 43 | 44 | fromModifier.specAmount[0] = mymodifier.specAmount[0] = finalSpecAmount[0] = specAmount[0] = 0; 45 | fromModifier.specAmount[1] = mymodifier.specAmount[1] = finalSpecAmount[1] = specAmount[1] = 0; 46 | fromModifier.specAmount[2] = mymodifier.specAmount[2] = finalSpecAmount[2] = specAmount[2] = 0; 47 | mymodifier.specValue[0] = -1; 48 | mymodifier.specValue[1] = -1; 49 | mymodifier.specValue[2] = -1; 50 | fromModifier.specValue[0] = -1; 51 | fromModifier.specValue[1] = -1; 52 | fromModifier.specValue[2] = -1; 53 | int len=sizeof(changeAmount)/sizeof(int); 54 | for(int i=0; i< len; i++) 55 | { 56 | changeAmount[i] = 0; 57 | fromChangeAmount[i] = 0; 58 | mymodifier.amount[i] = 0; 59 | fromModifier.amount[i] = 0; 60 | } 61 | 62 | unusedText = NULL; 63 | 64 | // str_time->tm_year = 139; 65 | // time_t finalTime = mktime(str_time); 66 | // str_time= localtime(&finalTime); 67 | // printf("after year change = %s\n", asctime(str_time)); 68 | 69 | } 70 | 71 | void setTime(int sec, int min, int hr) 72 | { 73 | str_time->tm_hour = hr; 74 | str_time->tm_min = min; 75 | str_time->tm_sec = sec; 76 | } 77 | void setDate(int day, int month, int year, int wday) 78 | { 79 | str_time->tm_mday = day; 80 | str_time->tm_wday = wday; 81 | str_time->tm_mon = month; 82 | str_time->tm_year = year; 83 | } 84 | 85 | void setBoth(int sec, int min, int hr, int day, int month, int year, int wday) 86 | { 87 | setDate(day, month, year, wday); 88 | setTime(sec, min, hr); 89 | 90 | } 91 | 92 | char* join_strings(int* strings, char* seperator, int count) { 93 | char* str = NULL; /* Pointer to the joined strings */ 94 | char intstr[DIGILEN]; 95 | size_t total_length = 0; /* Total length of joined strings */ 96 | int i = 0; /* Loop counter */ 97 | 98 | /* Find total length of joined strings */ 99 | 100 | 101 | for (i = 0; i < count; i++) 102 | { 103 | sprintf(intstr, "%d", strings[i]); 104 | total_length += strlen(intstr); 105 | } 106 | total_length++; /* For joined string terminator */ 107 | total_length += strlen(seperator) * (count - 1); // for seperators 108 | 109 | str = (char*) malloc(total_length); /* Allocate memory for joined strings */ 110 | str[0] = '\0'; /* Empty string we can append to */ 111 | 112 | /* Append all the strings */ 113 | for (i = 0; i < count; i++) { 114 | sprintf(intstr, "%d", strings[i]); 115 | strcat(str, intstr); 116 | if (i < (count - 1)) strcat(str, seperator); 117 | } 118 | 119 | return str; 120 | } 121 | 122 | 123 | void setFinalTime(struct tm *temp, int amount[], int *change) 124 | { 125 | 126 | // printf("set final time BEFORE= temp time= %s\n", asctime(str_time)); 127 | time_t tempTime = mktime(str_time); 128 | 129 | str_time= localtime(&tempTime); 130 | 131 | if(temp->tm_year >= 0) 132 | { 133 | str_time->tm_year = temp->tm_year; 134 | amount[2] = 0; 135 | } 136 | *timePointer[6] += change[6]; 137 | 138 | tempTime = mktime(str_time); 139 | 140 | str_time= localtime(&tempTime); 141 | 142 | 143 | int mon = str_time->tm_mon; 144 | if(temp->tm_mon >= 0) 145 | { 146 | amount[2] = 0; 147 | if(temp->tm_mon >=12) 148 | { 149 | str_time->tm_mon = mon = temp->tm_mon-12; 150 | str_time->tm_year +=1; 151 | 152 | } 153 | else 154 | { 155 | if(str_time->tm_mon > temp->tm_mon && (temp->tm_year < 0 && change[6]==0)) 156 | { 157 | if(amount[0] <= 0) 158 | str_time->tm_year += (amount[0]+1); 159 | else 160 | str_time->tm_year += amount[0]; 161 | } 162 | else if(str_time->tm_mon < temp->tm_mon) 163 | { 164 | if(amount[0] <= 0) 165 | str_time->tm_year += (amount[0]); 166 | else 167 | str_time->tm_year += (amount[0]-1); 168 | } 169 | else if(str_time->tm_mon == temp->tm_mon) 170 | { 171 | str_time->tm_year += amount[0]; 172 | } 173 | str_time->tm_mon = mon = temp->tm_mon; 174 | } 175 | 176 | } 177 | // printf("set final time after= temp time= %s\n", asctime(str_time)); 178 | 179 | *timePointer[5] += change[5]; 180 | 181 | 182 | tempTime = mktime(str_time); 183 | str_time= localtime(&tempTime); 184 | 185 | if(str_time->tm_mon != (mon+change[5])) 186 | str_time->tm_mon = (mon+change[5]); 187 | 188 | 189 | /******* change[7] is the number of weeks ******/ 190 | if(change[7]) 191 | { 192 | 193 | str_time->tm_mday += 7*change[7]; 194 | str_time->tm_mday -= str_time->tm_wday; 195 | tempTime = mktime(str_time); 196 | str_time= localtime(&tempTime); 197 | // printf("main time after month/year change = %s\n", asctime(str_time)); 198 | } 199 | 200 | if(temp->tm_mday >=0) 201 | { 202 | if(change[7]) 203 | { 204 | str_time->tm_mday += temp->tm_mday; 205 | } 206 | else 207 | str_time->tm_mday = temp->tm_mday; 208 | 209 | tempTime = mktime(str_time); 210 | str_time= localtime(&tempTime); 211 | // printf("the set day %d and is %s \n", temp->tm_mday, asctime(str_time)); 212 | } 213 | if(amount[1]>0 && temp->tm_mday >=0 && temp->tm_wday <0) temp->tm_wday = 0;//str_time->tm_wday; 214 | setDayOfWeek(temp->tm_wday, amount); 215 | 216 | // printf("amount2 = %d and change3 = %d", amount[2], change[3]); 217 | if(amount[2]!= 0 && change[3]==0) 218 | { 219 | switch(change[8]) 220 | { 221 | case 'm': 222 | { 223 | // printf("in the morning"); 224 | if(temp->tm_hour >= 0) 225 | { 226 | if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) 227 | str_time->tm_mday += 1; 228 | 229 | } 230 | else if(str_time->tm_hour > 12) 231 | str_time->tm_mday += 1; 232 | } 233 | break; 234 | case 'a': 235 | { 236 | // printf("in the afternoon"); 237 | if(temp->tm_hour >= 0) 238 | { 239 | if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) 240 | str_time->tm_mday += 1; 241 | 242 | } 243 | else if(str_time->tm_hour > 17) 244 | str_time->tm_mday += 1; 245 | } 246 | break; 247 | case 'e': 248 | { 249 | // printf("in the evening %d", temp->tm_hour); 250 | if(temp->tm_hour >= 0) 251 | { 252 | if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) 253 | str_time->tm_mday += 1; 254 | 255 | } 256 | else if(str_time->tm_hour > 20) 257 | str_time->tm_mday += 1; 258 | } 259 | break; 260 | case 'n': 261 | { 262 | } 263 | break; 264 | default: 265 | break; 266 | } 267 | } 268 | 269 | if(temp->tm_hour >= 0) 270 | str_time->tm_hour = temp->tm_hour; 271 | if(temp->tm_min >= 0) 272 | str_time->tm_min = temp->tm_min; 273 | if(temp->tm_sec >= 0) 274 | str_time->tm_sec = temp->tm_sec; 275 | 276 | 277 | change[6] = 0; 278 | change[5] = 0; 279 | 280 | for(int i=0; i<7; i++){ 281 | *timePointer[i] += change[i]; 282 | } 283 | tempTime = mktime(str_time); 284 | str_time= localtime(&tempTime); 285 | 286 | temp->tm_sec = -1; 287 | temp->tm_min = -1; 288 | temp->tm_hour = -1; 289 | temp->tm_mday = -1; 290 | temp->tm_wday = -1; 291 | temp->tm_mon = -1; 292 | temp->tm_year = -1; 293 | amount[0] = 0; 294 | amount[1] = 0; 295 | amount[2] = 0; 296 | 297 | 298 | for(int i=0; i< 9; i++) 299 | { 300 | change[i] = 0; 301 | } 302 | 303 | time_t finalTime = mktime(str_time); 304 | str_time= localtime(&finalTime); 305 | } 306 | 307 | 308 | void setDayOfWeek(int weekday, int *amount) 309 | { 310 | 311 | if(weekday >= 0) 312 | { 313 | // printf("weekday = %d and amount = %d", weekday, amount[1]); 314 | amount[2] = 0; 315 | if(str_time->tm_wday > weekday) 316 | { 317 | int dif = str_time->tm_wday - weekday; 318 | if (amount[1]==0) { 319 | str_time->tm_mday += (7-dif); 320 | } 321 | else if(amount[1]>0) 322 | { 323 | str_time->tm_mday += (7-dif)+(amount[1]-1)*7; 324 | } 325 | else if(amount[1] < 0) 326 | { 327 | str_time->tm_mday += ((amount[1]+1)*7)-dif; 328 | } 329 | 330 | } 331 | else if(str_time->tm_wday < weekday) 332 | { 333 | int dif = weekday - str_time->tm_wday; 334 | if (amount[1]==0) { 335 | str_time->tm_mday += dif; 336 | } 337 | else if(amount[1]>0) 338 | { 339 | str_time->tm_mday += (dif+(amount[1]-1)*7); 340 | } 341 | else if(amount[1] < 0) 342 | { 343 | str_time->tm_mday += (dif-7)+((amount[1]+1)*7); 344 | } 345 | } 346 | else if(str_time->tm_wday == weekday) 347 | { 348 | str_time->tm_mday += (amount[1]*7); 349 | } 350 | 351 | str_time->tm_wday = weekday; 352 | time_t tempTime = mktime(str_time); 353 | str_time= localtime(&tempTime); 354 | 355 | // printf("the string after wday = %s \n ", asctime(str_time)); 356 | 357 | } 358 | 359 | } 360 | 361 | /* reverse: reverse string s in place */ 362 | static void reverse(char s[]) 363 | { 364 | int i, j; 365 | char c; 366 | 367 | for (i = 0, j = strlen(s)-1; i 0); /* delete it */ 384 | if (sign < 0) 385 | s[i++] = '-'; 386 | s[i] = '\0'; 387 | reverse(s); 388 | } 389 | 390 | 391 | time_t parseDateTimeString(const char *str) 392 | { 393 | yy_switch_to_buffer(yy_scan_string(str)); 394 | yyparse(); 395 | time_t tempTime = mktime(str_time); 396 | str_time= localtime(&tempTime); 397 | 398 | 399 | setFinalTime(&set_time, finalSpecAmount, fromChangeAmount); 400 | 401 | tempTime = mktime(str_time); 402 | str_time= localtime(&tempTime); 403 | if(fromModifier.specValue[1]) 404 | { 405 | setDayOfWeek(fromModifier.specValue[1], fromModifier.specAmount); 406 | } 407 | 408 | return mktime(str_time); 409 | 410 | } 411 | -------------------------------------------------------------------------------- /tokeIt.l: -------------------------------------------------------------------------------- 1 | /* date convert #1 */ 2 | 3 | 4 | %{ 5 | 6 | 7 | #include 8 | #include "y.tab.h" 9 | 10 | #define YY_NO_INPUT 11 | 12 | extern time_t curtime; 13 | extern struct tm temp_time; 14 | 15 | extern struct tm *str_time; 16 | extern char * unusedText; 17 | 18 | void yyerror(char *); 19 | 20 | void concatUnusedString(char *newstr); 21 | void parseMonthDayStr(char *text, char *tok); 22 | void parseDayMonthStr(char *text, char *tok); 23 | void parseYearMonthDayStr(char *text, char *tok); 24 | 25 | %} 26 | 27 | %option nounput 28 | 29 | %x error 30 | 31 | dateTimeTerms (sec(ond)?|min(ute)?|hour|hr|day|week|month|year)s? 32 | 33 | regularTime ((0?[1-9])|(1[0|1|2]))((:[0-5][0-9](" "?(a|p)\.?m\.?)?)|(" "?(a|p)\.?m\.?)) 34 | militaryTime (([0-1][0-9])|([2][0-3])):?([0-5][0-9]) 35 | specificTimes noon|midnight 36 | generalTime (morning|afternoon|evening|night|tonight|tonite)s? 37 | 38 | 39 | 40 | months (jan(uary|uaries)?|feb(ruary|ruaries)?|mar(ch|ches)?|apr(il)?|may|june?|jul(y|ies)?|aug(ust)?|sep(t)?(ember)?|oct(ober)?|nov(ember)?|dec(ember)?)(s?)\.? 41 | days sun|mon|tues|wed(nes)?|thurs|fri|sat(ur)? 42 | 43 | 44 | genericNum (([0][1-9])|([1][0-2])|([1-9])) 45 | daydate (([1][3-9])|([2][0-9])|(3[01])) 46 | yeardate ([12]([0-9]{3})) 47 | 48 | setModifier on 49 | 50 | 51 | 52 | times {regularTime}|{militaryTime} 53 | onDay (on)" "{days}(day)? 54 | 55 | 56 | 57 | %% 58 | 59 | in" "the { return INTHE; } 60 | now { return NOW; }; 61 | 62 | tomorrow { yylval.number = 8; return DAYOFWEEK; } 63 | yesterday { yylval.number = -1; return DAYOFWEEK; } 64 | today { yylval.number = 0; return DAYOFWEEK; } 65 | from { yylval.number = 1; return FROM; } 66 | last { yylval.number = -1; return LASTNEXT; } 67 | next { yylval.number = 1; return LASTNEXT; } 68 | ago|past { yylval.number = -1; return HENCEAGO; } 69 | hence { yylval.number = 1; return HENCEAGO; } 70 | before { yylval.number = -1; return BEFOREAFTER; } 71 | after { yylval.number = 1; return BEFOREAFTER; } 72 | in { yylval.number = 1; return IN; } 73 | this { yylval.number = 0; return THIS; } 74 | 75 | 76 | 77 | {dateTimeTerms} { 78 | switch(yytext[0]) 79 | { 80 | case 's': 81 | { 82 | yylval.number=0; 83 | } 84 | break; 85 | case 'm': 86 | { 87 | if(yytext[1]=='i') 88 | yylval.number=1; 89 | else 90 | yylval.number = 5; 91 | } 92 | break; 93 | case 'h': 94 | { 95 | yylval.number=2; 96 | } 97 | break; 98 | case 'd': 99 | { 100 | yylval.number=3; 101 | } 102 | break; 103 | case 'w': 104 | { 105 | yylval.number=4; 106 | } 107 | break; 108 | case 'y': 109 | { 110 | yylval.number=6; 111 | } 112 | break; 113 | } 114 | return TYPENAMES; 115 | 116 | } 117 | 118 | 119 | {generalTime} { 120 | 121 | yylval.number = yytext[0]; 122 | return GENERALTIME; 123 | 124 | } 125 | {specificTimes} { 126 | if(yytext[0]=='m') 127 | { 128 | yylval.string= strdup("00:00"); 129 | } 130 | else 131 | { 132 | yylval.string = strdup("12:00"); 133 | } 134 | return WHENTIME; 135 | 136 | } 137 | 138 | {regularTime} { 139 | 140 | int i, j=strlen(yytext); 141 | 142 | char apm[3] = ":am"; 143 | for(i = 1; yytext[i] != '\0'; i++){ 144 | if(yytext[i] == 'a'){ 145 | j = i; 146 | break; 147 | } 148 | else if(yytext[i]== 'p') 149 | { 150 | apm[1] = 'p'; 151 | j=i; 152 | break; 153 | 154 | } 155 | } 156 | 157 | 158 | char hr[j+4]; 159 | 160 | strncpy(hr, yytext, j); 161 | hr[j] = '\0'; 162 | strcat(hr, apm); 163 | 164 | yylval.string=strdup(hr); 165 | return WHENTIME; 166 | } 167 | 168 | {militaryTime} { 169 | 170 | char *new = strdup(yytext); 171 | 172 | char hr[7] = ""; 173 | strncat(hr, new, 2); 174 | hr[2] = ':'; 175 | strncat(hr, &new[strlen(new)-2], 2); 176 | 177 | hr[2] = ':'; 178 | strncat(hr, &new[1], 2); 179 | hr[5] = '\0'; 180 | 181 | yylval.string = strdup(hr); 182 | return MILITARYTIME; 183 | } 184 | 185 | {months} { 186 | switch(yytext[0]) 187 | { 188 | case 'j': 189 | { 190 | if(yytext[1]=='a') 191 | { 192 | yylval.number=0; 193 | } 194 | else if(yytext[2]=='n') 195 | { 196 | yylval.number=5; 197 | } 198 | else 199 | { 200 | yylval.number = 6; 201 | } 202 | } 203 | break; 204 | case 'f': 205 | yylval.number=1; 206 | break; 207 | case 'm': 208 | { 209 | if(yytext[2]=='r') 210 | { 211 | yylval.number=2; 212 | } 213 | else 214 | { 215 | yylval.number=4; 216 | } 217 | } 218 | break; 219 | case 'a': 220 | { 221 | if(yytext[1]=='p') 222 | { 223 | yylval.number=3; 224 | } 225 | else 226 | { 227 | yylval.number=7; 228 | } 229 | } 230 | break; 231 | case 's': 232 | { 233 | yylval.number=8; 234 | } 235 | break; 236 | case 'o': 237 | { 238 | yylval.number=9; 239 | } 240 | break; 241 | case 'n': 242 | { 243 | yylval.number=10; 244 | } 245 | break; 246 | case 'd': 247 | { 248 | yylval.number=11; 249 | } 250 | break; 251 | } 252 | return MONTHNUM; 253 | } 254 | 255 | {days}(\.|days?)? { 256 | 257 | switch(yytext[0]) 258 | { 259 | case 's': 260 | { 261 | if(yytext[1]=='a') 262 | { 263 | yylval.number=7; 264 | } 265 | else 266 | { 267 | yylval.number=1; 268 | } 269 | } 270 | break; 271 | case 'm': 272 | yylval.number=2; 273 | break; 274 | case 't': 275 | { 276 | if(yytext[1]=='h') 277 | { 278 | yylval.number=5; 279 | } 280 | else 281 | { 282 | yylval.number=3; 283 | } 284 | } 285 | break; 286 | case 'w': 287 | { 288 | yylval.number=4; 289 | } 290 | break; 291 | case 'f': 292 | { 293 | yylval.number=6; 294 | } 295 | break; 296 | } 297 | return DAYOFWEEK; 298 | } 299 | 300 | {daydate}"/"{genericNum}"/"{yeardate} { /***** ex. 23/05/2012 *****/ 301 | parseDayMonthStr(yytext, "/"); 302 | return SETDATE; 303 | } 304 | 305 | {genericNum}"/"{daydate}"/"{yeardate} { /***** ex. 11/23/2011 *****/ 306 | parseMonthDayStr(yytext, "/"); 307 | return SETDATE; 308 | } 309 | 310 | {genericNum}"/"{genericNum}"/"{yeardate} { /***** ex. 11/11/2012 *****/ 311 | parseMonthDayStr(yytext, "/"); 312 | return SETDATE; 313 | } 314 | {daydate}"-"{genericNum}"-"{yeardate} { /***** ex. 23-05-2012 *****/ 315 | parseDayMonthStr(yytext, "-"); 316 | return SETDATE; 317 | } 318 | 319 | {genericNum}"-"{daydate}"-"{yeardate} { /***** ex. 11-23-2011 *****/ 320 | parseMonthDayStr(yytext, "-"); 321 | return SETDATE; 322 | } 323 | 324 | {genericNum}"-"{genericNum}"-"{yeardate} { /***** ex. 11-11-2012 *****/ 325 | parseMonthDayStr(yytext, "-"); 326 | return SETDATE; 327 | } 328 | 329 | {yeardate}"/"{genericNum}"/"({genericNum}|{daydate}) { /***** ex. 2012/11/11 *****/ 330 | parseYearMonthDayStr(yytext, "/"); 331 | return SETDATE; 332 | } 333 | 334 | {yeardate}"-"{genericNum}"-"({genericNum}|{daydate}) { /***** ex. 2012-11-11 *****/ 335 | parseYearMonthDayStr(yytext, "-"); 336 | return SETDATE; 337 | } 338 | 339 | [0-9]+(st|nd|rd|th) { 340 | size_t thesize = strlen(yytext)-2; 341 | char *to = (char*) malloc(thesize); 342 | strncpy(to, yytext, thesize); 343 | yylval.number=atoi(to); 344 | 345 | return DTPOSITION; 346 | } 347 | 348 | [0-9]+ { 349 | 350 | yylval.number= atoi(yytext); 351 | return INTEGER; 352 | } 353 | 354 | 355 | 356 | 357 | at|@ {yylval.string = yytext; return ARTICLEPREP; } 358 | the ; 359 | [ \t,] { concatUnusedString(strdup(yytext)); BEGIN(INITIAL); } /* skip whitespace */ 360 | [ \t,] { concatUnusedString(strdup(yytext)); BEGIN(INITIAL); } /* skip whitespace in error state */ 361 | \+|plus { yylval.number = 1; return PLUS;} 362 | 363 | 364 | . { 365 | 366 | BEGIN(error); 367 | concatUnusedString(strdup(yytext)); 368 | // yyerror("Unknown character"); 369 | } 370 | 371 | . { 372 | concatUnusedString(strdup(yytext)); 373 | // printf("error character is = %s\n", yytext); 374 | } 375 | 376 | %% 377 | 378 | void parseMonthDayStr(char *text, char *tok) 379 | { 380 | 381 | char *parts = strtok(yytext, tok); 382 | temp_time.tm_mon= atoi(parts)-1; 383 | parts = strtok (NULL, tok); 384 | if(parts != NULL) 385 | { 386 | temp_time.tm_mday = atoi(parts); 387 | parts = strtok (NULL, tok); 388 | if(parts != NULL) 389 | temp_time.tm_year = atoi(parts)-1900; 390 | } 391 | } 392 | void parseDayMonthStr(char *text, char *tok) 393 | { 394 | 395 | char *parts = strtok(yytext, tok); 396 | temp_time.tm_mday= atoi(parts); 397 | parts = strtok (NULL, tok); 398 | if(parts != NULL) 399 | { 400 | temp_time.tm_mon = atoi(parts)-1; 401 | parts = strtok (NULL, tok); 402 | if(parts != NULL) 403 | temp_time.tm_year = atoi(parts)-1900; 404 | } 405 | } 406 | 407 | void parseYearMonthDayStr(char *text, char *tok) 408 | { 409 | 410 | char *parts = strtok(yytext, tok); 411 | temp_time.tm_year= atoi(parts)-1900; 412 | parts = strtok (NULL, tok); 413 | if(parts != NULL) 414 | { 415 | temp_time.tm_mon = atoi(parts)-1; 416 | parts = strtok (NULL, tok); 417 | if(parts != NULL) 418 | temp_time.tm_mday = atoi(parts); 419 | } 420 | } 421 | 422 | void concatUnusedString(char *strnew) 423 | { 424 | 425 | size_t len = 0; 426 | char *str = ""; 427 | if(unusedText!=NULL) 428 | { 429 | 430 | len = strlen(unusedText); /* could use 'sizeof' instead of strlen in this example */ 431 | str = unusedText; 432 | } 433 | 434 | char *str2 = malloc(len + strlen(strnew) + 1 ); 435 | strcpy(str2, str); 436 | strcat (str2, strnew); 437 | 438 | free(unusedText); 439 | unusedText = str2; 440 | 441 | } 442 | 443 | int yywrap(void) { 444 | return 1; 445 | } 446 | -------------------------------------------------------------------------------- /iphoneExample/NLDP/NLDP.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 39D534E3154DC32100990982 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39D534E2154DC32100990982 /* UIKit.framework */; }; 11 | 39D534E5154DC32100990982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39D534E4154DC32100990982 /* Foundation.framework */; }; 12 | 39D534E7154DC32100990982 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39D534E6154DC32100990982 /* CoreGraphics.framework */; }; 13 | 39D534ED154DC32100990982 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 39D534EB154DC32100990982 /* InfoPlist.strings */; }; 14 | 39D534EF154DC32100990982 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 39D534EE154DC32100990982 /* main.m */; }; 15 | 39D534F3154DC32100990982 /* KMAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 39D534F2154DC32100990982 /* KMAppDelegate.m */; }; 16 | 39D534F6154DC32100990982 /* KMViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 39D534F5154DC32100990982 /* KMViewController.m */; }; 17 | 39D534F9154DC32100990982 /* KMViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 39D534F7154DC32100990982 /* KMViewController.xib */; }; 18 | 39D53507154DC38A00990982 /* parseIt.ym in Sources */ = {isa = PBXBuildFile; fileRef = 39D53503154DC38A00990982 /* parseIt.ym */; }; 19 | 39D53508154DC38A00990982 /* TimeParser.c in Sources */ = {isa = PBXBuildFile; fileRef = 39D53504154DC38A00990982 /* TimeParser.c */; }; 20 | 39D53509154DC38A00990982 /* tokeIt.l in Sources */ = {isa = PBXBuildFile; fileRef = 39D53506154DC38A00990982 /* tokeIt.l */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 39D534DE154DC32100990982 /* NLDP.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NLDP.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 39D534E2154DC32100990982 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 26 | 39D534E4154DC32100990982 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 27 | 39D534E6154DC32100990982 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 28 | 39D534EA154DC32100990982 /* NLDP-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "NLDP-Info.plist"; sourceTree = ""; }; 29 | 39D534EC154DC32100990982 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 30 | 39D534EE154DC32100990982 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | 39D534F0154DC32100990982 /* NLDP-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NLDP-Prefix.pch"; sourceTree = ""; }; 32 | 39D534F1154DC32100990982 /* KMAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KMAppDelegate.h; sourceTree = ""; }; 33 | 39D534F2154DC32100990982 /* KMAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KMAppDelegate.m; sourceTree = ""; }; 34 | 39D534F4154DC32100990982 /* KMViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KMViewController.h; sourceTree = ""; }; 35 | 39D534F5154DC32100990982 /* KMViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KMViewController.m; sourceTree = ""; }; 36 | 39D534F8154DC32100990982 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/KMViewController.xib; sourceTree = ""; }; 37 | 39D53503154DC38A00990982 /* parseIt.ym */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; name = parseIt.ym; path = ../../../parseIt.ym; sourceTree = ""; }; 38 | 39D53504154DC38A00990982 /* TimeParser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = TimeParser.c; path = ../../../TimeParser.c; sourceTree = ""; }; 39 | 39D53506154DC38A00990982 /* tokeIt.l */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.lex; name = tokeIt.l; path = ../../../tokeIt.l; sourceTree = ""; }; 40 | 39D5350A154DC5DC00990982 /* TimeParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimeParser.h; path = ../../../TimeParser.h; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 39D534DB154DC32100990982 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | 39D534E3154DC32100990982 /* UIKit.framework in Frameworks */, 49 | 39D534E5154DC32100990982 /* Foundation.framework in Frameworks */, 50 | 39D534E7154DC32100990982 /* CoreGraphics.framework in Frameworks */, 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | 39D534D3154DC32100990982 = { 58 | isa = PBXGroup; 59 | children = ( 60 | 39D534E8154DC32100990982 /* NLDP */, 61 | 39D534E1154DC32100990982 /* Frameworks */, 62 | 39D534DF154DC32100990982 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 39D534DF154DC32100990982 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 39D534DE154DC32100990982 /* NLDP.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 39D534E1154DC32100990982 /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 39D534E2154DC32100990982 /* UIKit.framework */, 78 | 39D534E4154DC32100990982 /* Foundation.framework */, 79 | 39D534E6154DC32100990982 /* CoreGraphics.framework */, 80 | ); 81 | name = Frameworks; 82 | sourceTree = ""; 83 | }; 84 | 39D534E8154DC32100990982 /* NLDP */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 39D5350A154DC5DC00990982 /* TimeParser.h */, 88 | 39D53503154DC38A00990982 /* parseIt.ym */, 89 | 39D53504154DC38A00990982 /* TimeParser.c */, 90 | 39D53506154DC38A00990982 /* tokeIt.l */, 91 | 39D534F1154DC32100990982 /* KMAppDelegate.h */, 92 | 39D534F2154DC32100990982 /* KMAppDelegate.m */, 93 | 39D534F4154DC32100990982 /* KMViewController.h */, 94 | 39D534F5154DC32100990982 /* KMViewController.m */, 95 | 39D534F7154DC32100990982 /* KMViewController.xib */, 96 | 39D534E9154DC32100990982 /* Supporting Files */, 97 | ); 98 | path = NLDP; 99 | sourceTree = ""; 100 | }; 101 | 39D534E9154DC32100990982 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 39D534EA154DC32100990982 /* NLDP-Info.plist */, 105 | 39D534EB154DC32100990982 /* InfoPlist.strings */, 106 | 39D534EE154DC32100990982 /* main.m */, 107 | 39D534F0154DC32100990982 /* NLDP-Prefix.pch */, 108 | ); 109 | name = "Supporting Files"; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 39D534DD154DC32100990982 /* NLDP */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 39D534FC154DC32100990982 /* Build configuration list for PBXNativeTarget "NLDP" */; 118 | buildPhases = ( 119 | 39D534DA154DC32100990982 /* Sources */, 120 | 39D534DB154DC32100990982 /* Frameworks */, 121 | 39D534DC154DC32100990982 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = NLDP; 128 | productName = NLDP; 129 | productReference = 39D534DE154DC32100990982 /* NLDP.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 39D534D5154DC32100990982 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | CLASSPREFIX = KM; 139 | LastUpgradeCheck = 0430; 140 | ORGANIZATIONNAME = FrenzyLabs; 141 | }; 142 | buildConfigurationList = 39D534D8154DC32100990982 /* Build configuration list for PBXProject "NLDP" */; 143 | compatibilityVersion = "Xcode 3.2"; 144 | developmentRegion = English; 145 | hasScannedForEncodings = 0; 146 | knownRegions = ( 147 | en, 148 | ); 149 | mainGroup = 39D534D3154DC32100990982; 150 | productRefGroup = 39D534DF154DC32100990982 /* Products */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 39D534DD154DC32100990982 /* NLDP */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 39D534DC154DC32100990982 /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 39D534ED154DC32100990982 /* InfoPlist.strings in Resources */, 165 | 39D534F9154DC32100990982 /* KMViewController.xib in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXSourcesBuildPhase section */ 172 | 39D534DA154DC32100990982 /* Sources */ = { 173 | isa = PBXSourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 39D534EF154DC32100990982 /* main.m in Sources */, 177 | 39D534F3154DC32100990982 /* KMAppDelegate.m in Sources */, 178 | 39D534F6154DC32100990982 /* KMViewController.m in Sources */, 179 | 39D53507154DC38A00990982 /* parseIt.ym in Sources */, 180 | 39D53508154DC38A00990982 /* TimeParser.c in Sources */, 181 | 39D53509154DC38A00990982 /* tokeIt.l in Sources */, 182 | ); 183 | runOnlyForDeploymentPostprocessing = 0; 184 | }; 185 | /* End PBXSourcesBuildPhase section */ 186 | 187 | /* Begin PBXVariantGroup section */ 188 | 39D534EB154DC32100990982 /* InfoPlist.strings */ = { 189 | isa = PBXVariantGroup; 190 | children = ( 191 | 39D534EC154DC32100990982 /* en */, 192 | ); 193 | name = InfoPlist.strings; 194 | sourceTree = ""; 195 | }; 196 | 39D534F7154DC32100990982 /* KMViewController.xib */ = { 197 | isa = PBXVariantGroup; 198 | children = ( 199 | 39D534F8154DC32100990982 /* en */, 200 | ); 201 | name = KMViewController.xib; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXVariantGroup section */ 205 | 206 | /* Begin XCBuildConfiguration section */ 207 | 39D534FA154DC32100990982 /* Debug */ = { 208 | isa = XCBuildConfiguration; 209 | buildSettings = { 210 | ALWAYS_SEARCH_USER_PATHS = NO; 211 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 212 | CLANG_ENABLE_OBJC_ARC = YES; 213 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 214 | COPY_PHASE_STRIP = NO; 215 | GCC_C_LANGUAGE_STANDARD = gnu99; 216 | GCC_DYNAMIC_NO_PIC = NO; 217 | GCC_OPTIMIZATION_LEVEL = 0; 218 | GCC_PREPROCESSOR_DEFINITIONS = ( 219 | "DEBUG=1", 220 | "$(inherited)", 221 | ); 222 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 223 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 224 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 228 | SDKROOT = iphoneos; 229 | }; 230 | name = Debug; 231 | }; 232 | 39D534FB154DC32100990982 /* Release */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | ALWAYS_SEARCH_USER_PATHS = NO; 236 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 237 | CLANG_ENABLE_OBJC_ARC = YES; 238 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 239 | COPY_PHASE_STRIP = YES; 240 | GCC_C_LANGUAGE_STANDARD = gnu99; 241 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 246 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 247 | SDKROOT = iphoneos; 248 | VALIDATE_PRODUCT = YES; 249 | }; 250 | name = Release; 251 | }; 252 | 39D534FD154DC32100990982 /* Debug */ = { 253 | isa = XCBuildConfiguration; 254 | buildSettings = { 255 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 256 | GCC_PREFIX_HEADER = "NLDP/NLDP-Prefix.pch"; 257 | INFOPLIST_FILE = "NLDP/NLDP-Info.plist"; 258 | PRODUCT_NAME = "$(TARGET_NAME)"; 259 | WRAPPER_EXTENSION = app; 260 | }; 261 | name = Debug; 262 | }; 263 | 39D534FE154DC32100990982 /* Release */ = { 264 | isa = XCBuildConfiguration; 265 | buildSettings = { 266 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 267 | GCC_PREFIX_HEADER = "NLDP/NLDP-Prefix.pch"; 268 | INFOPLIST_FILE = "NLDP/NLDP-Info.plist"; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | WRAPPER_EXTENSION = app; 271 | }; 272 | name = Release; 273 | }; 274 | /* End XCBuildConfiguration section */ 275 | 276 | /* Begin XCConfigurationList section */ 277 | 39D534D8154DC32100990982 /* Build configuration list for PBXProject "NLDP" */ = { 278 | isa = XCConfigurationList; 279 | buildConfigurations = ( 280 | 39D534FA154DC32100990982 /* Debug */, 281 | 39D534FB154DC32100990982 /* Release */, 282 | ); 283 | defaultConfigurationIsVisible = 0; 284 | defaultConfigurationName = Release; 285 | }; 286 | 39D534FC154DC32100990982 /* Build configuration list for PBXNativeTarget "NLDP" */ = { 287 | isa = XCConfigurationList; 288 | buildConfigurations = ( 289 | 39D534FD154DC32100990982 /* Debug */, 290 | 39D534FE154DC32100990982 /* Release */, 291 | ); 292 | defaultConfigurationIsVisible = 0; 293 | }; 294 | /* End XCConfigurationList section */ 295 | }; 296 | rootObject = 39D534D5154DC32100990982 /* Project object */; 297 | } 298 | -------------------------------------------------------------------------------- /parseIt.ym: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #import 4 | #include "TimeParser.h" 5 | 6 | int yylex(void); 7 | void yyerror(char *); 8 | 9 | %} 10 | 11 | 12 | 13 | %union 14 | { 15 | int number; 16 | char *string; 17 | } 18 | 19 | %token INTEGER DTPOSITION DAYOFWEEK MONTHNUM GENERALTIME MODIFIERS FROM LASTNEXT BEFOREAFTER HENCEAGO IN THIS NOW INTHE PLUS SETDATE 20 | %token MONTH PASTMODIFIER WHENTIME TYPENAMES DTMODIFIERS ARTICLEPREP MILITARYTIME 21 | 22 | %% 23 | 24 | 25 | program: { setCurrentTime(); 26 | //NSLog(@"Parsing Started"); 27 | } 28 | | 29 | program expr { 30 | 31 | 32 | 33 | time_t curtime2 = mktime(str_time); 34 | 35 | // NSLog(@"UNIXTIMESTAMP = %d \n", curtime2); 36 | // NSLog(@"perty time = %s\n", asctime(str_time)); 37 | // NSLog(@"modifier num = %d", *mymodifier.changePointer); 38 | 39 | $$ = curtime2; 40 | 41 | for(int i=0; i<9; i++){ 42 | fromChangeAmount[i] += changeAmount[i]; 43 | changeAmount[i] = 0; 44 | } 45 | 46 | set_time.tm_sec = temp_time.tm_sec >=0 ? temp_time.tm_sec : set_time.tm_sec; 47 | set_time.tm_min = temp_time.tm_min >=0 ? temp_time.tm_min : set_time.tm_min; 48 | set_time.tm_hour = temp_time.tm_hour >=0 ? temp_time.tm_hour : set_time.tm_hour; 49 | set_time.tm_mday = temp_time.tm_mday >=0 ? temp_time.tm_mday : set_time.tm_mday; 50 | set_time.tm_wday = temp_time.tm_wday >= 0 ? temp_time.tm_wday : set_time.tm_wday; 51 | set_time.tm_mon = temp_time.tm_mon >= 0 ? temp_time.tm_mon : set_time.tm_mon; 52 | set_time.tm_year = temp_time.tm_year >= 0 ? temp_time.tm_year : set_time.tm_year; 53 | 54 | 55 | // printf("temp time = %s", asctime(&temp_time)); 56 | 57 | temp_time.tm_sec = -1; 58 | temp_time.tm_min = -1; 59 | temp_time.tm_hour = -1; 60 | temp_time.tm_mday = -1; 61 | temp_time.tm_wday = -1; 62 | temp_time.tm_mon = -1; 63 | temp_time.tm_year = -1; 64 | 65 | finalSpecAmount[0] = specAmount[0] != 0 ? specAmount[0] : finalSpecAmount[0]; 66 | finalSpecAmount[1] = specAmount[1] != 0 ? specAmount[1] : finalSpecAmount[1]; 67 | finalSpecAmount[2] = specAmount[2] != 0 ? specAmount[2] : finalSpecAmount[2]; 68 | 69 | 70 | // NSLog(@"topLevel change amount = %s\n", join_strings(fromChangeAmount, ",", 9)); 71 | // NSLog(@"topLevel spec amount = %s\n", join_strings(fromModifier.specAmount, ",", 3)); 72 | // NSLog(@"topLevel spec value = %s\n", join_strings(fromModifier.specValue, ",", 3)); 73 | } 74 | 75 | ; 76 | 77 | expr: 78 | 79 | expr BEFOREAFTER 80 | { 81 | 82 | // NSLog(@"inside before = %s\n", join_strings(fromModifier.amount, ",", 9)); 83 | 84 | if($2 == -1) 85 | { 86 | int i=0; 87 | for(i=0; i < 8; i++) 88 | { 89 | mymodifier.amount[i] = mymodifier.amount[i]>0 ? -mymodifier.amount[i] : mymodifier.amount[i]; 90 | } 91 | for(int j=0; j<3; j++) 92 | { 93 | if(mymodifier.specValue[j] >=0) 94 | mymodifier.specAmount[j] *= -1; 95 | } 96 | } 97 | int j=0; 98 | for(j=0; j<3; j++) 99 | { 100 | if(mymodifier.specValue[j] >= 0) 101 | { 102 | fromModifier.specAmount[j] = mymodifier.specAmount[j]; 103 | fromModifier.specValue[j] = mymodifier.specValue[j]; 104 | mymodifier.specValue[j] = -1; 105 | mymodifier.specAmount[j] = 0; 106 | } 107 | } 108 | int i = 0; 109 | for(i=0; i < 8; i++) 110 | { 111 | fromChangeAmount[i] += mymodifier.amount[i]; 112 | mymodifier.amount[i] = 0; 113 | } 114 | } 115 | | 116 | FROM expr { 117 | 118 | setFinalTime(&temp_time, specAmount, changeAmount); 119 | time_t tempTime = mktime(str_time); 120 | 121 | str_time= localtime(&tempTime); 122 | 123 | for(int i=0; i<7; i++){ 124 | *timePointer[i] += mymodifier.amount[i]; 125 | mymodifier.amount[i] = 0; 126 | } 127 | 128 | if(mymodifier.specValue[1]) 129 | { 130 | // NSLog(@"spec amount in from= %d", mymodifier.specAmount[1]); 131 | setDayOfWeek(mymodifier.specValue[1], mymodifier.specAmount); 132 | mymodifier.specValue[1] = -1; 133 | mymodifier.specAmount[1] = 0; 134 | } 135 | 136 | } 137 | | 138 | SETDATE { } 139 | | 140 | ARTICLEPREP {} 141 | | 142 | IN { } 143 | | 144 | THIS { } 145 | | 146 | NOW { } 147 | | 148 | INTEGER { /******** ex. 6 (means the time if only a number) ******/ 149 | 150 | if(fromChangeAmount[8] && fromChangeAmount[8] != 'm') 151 | { 152 | if($1 < 12) $1 += 12; 153 | else if($1 == 12) $1 = 0; 154 | } 155 | temp_time.tm_hour = $1; 156 | temp_time.tm_min = 0; 157 | temp_time.tm_sec = 0; 158 | } 159 | 160 | | 161 | MONTHNUM 162 | { /***** ex. "June" ******/ 163 | temp_time.tm_mon = $1; 164 | temp_time.tm_mday = 1; 165 | } 166 | | 167 | DAYOFWEEK /***** ex. "Friday" *****/ 168 | { 169 | if($1==-1) changeAmount[3] = -1; 170 | else if($1 == 8) changeAmount[3] = 1; 171 | else if($1 == 0) changeAmount[3] = 0; 172 | else 173 | temp_time.tm_wday = $1-1; 174 | } 175 | | 176 | IN INTEGER 177 | { 178 | if($2 > 1000) 179 | temp_time.tm_year = $2-1900; 180 | $$ = 6; 181 | } 182 | | 183 | 184 | IN MILITARYTIME 185 | { 186 | char *timeparts = strtok($2, ":"); 187 | char thedate[5] = ""; 188 | int actualdate= 0; 189 | strncat(thedate, timeparts, 2); 190 | timeparts = strtok (NULL, ":"); 191 | strncat(thedate, timeparts, 2); 192 | thedate[4] = '\0'; 193 | actualdate= atoi(thedate); 194 | 195 | temp_time.tm_year = actualdate-1900; 196 | $$ = 6; 197 | } 198 | | 199 | IN INTEGER TYPENAMES { /******** ex. "in 3 days" or "in 5 weeks" or "in 8 hours" ******/ 200 | if($3 == 4){ 201 | $3 = 3; 202 | $2 *= 7; 203 | } 204 | changeAmount[$3] = $2; 205 | } 206 | | 207 | TYPENAMES { 208 | if ($1 == 3) 209 | { 210 | mymodifier.amount[$1] += 1; 211 | } 212 | } 213 | | 214 | 215 | INTEGER TYPENAMES { /******** ex. "3 days" mostly used with "before" or "after" as in "3 days before yesterday" ****/ 216 | if($2 == 4) 217 | { 218 | $1 *= 7; 219 | $2 = 3; 220 | } 221 | // changeAmount[$2] = $1; 222 | mymodifier.amount[$2] += $1; 223 | 224 | } 225 | 226 | | 227 | 228 | INTEGER TYPENAMES HENCEAGO { /******* ex. "3 days ago" or "5 years hence" ******/ 229 | if($2 == 4){ 230 | $1 *= 7; 231 | $2 = 3; 232 | } 233 | changeAmount[$2] = $1*$3; 234 | } 235 | 236 | | 237 | INTEGER generalTimes /******* ex. "3 mornings" mainly used with "before" or "after" *****/ 238 | { 239 | mymodifier.amount[3] += $1; 240 | } 241 | | 242 | INTEGER generalTimes HENCEAGO /**** ex. "3 mornings ago" or "5 afternoons hence" *****/ 243 | { 244 | changeAmount[3] = $1*$3; 245 | } 246 | 247 | | 248 | LASTNEXT TYPENAMES { /********** ex. "Last Month" or "Next Year" *******/ 249 | $$ = 0; 250 | if($2 == 4){ 251 | $2 = 7; 252 | $$ = 4; 253 | } 254 | changeAmount[$2] = $1; 255 | } 256 | | 257 | LASTNEXT DAYOFWEEK { /******** ex. "last friday" or "next friday" ******/ 258 | if($2 > 0 && $2 < 8) 259 | temp_time.tm_wday = $2-1; 260 | specAmount[1] = $1; 261 | if($1 >0) 262 | changeAmount[7] = $1; 263 | } 264 | 265 | | 266 | LASTNEXT MONTHNUM /******** ex. "last May" or "next May" ******/ 267 | { 268 | if($1 >0) $2 += 12; 269 | temp_time.tm_mon = $2; 270 | specAmount[0] = $1; 271 | } 272 | 273 | | 274 | INTEGER INTHE generalTimes { /******** ex. " 6 in the morning" ******/ 275 | 276 | if($3 > 0) 277 | { 278 | if($1 < 12) 279 | temp_time.tm_hour = $1+12; 280 | 281 | else if($1 == 12) 282 | temp_time.tm_hour = 0; 283 | } 284 | else 285 | { 286 | temp_time.tm_hour = $1; 287 | } 288 | 289 | 290 | specAmount[2] = 1; 291 | } 292 | | 293 | INTEGER THIS generalTimes { /******** ex. " 6 this morning" ******/ 294 | 295 | if($3 > 0) 296 | { 297 | if($1 < 12) 298 | temp_time.tm_hour = $1+12; 299 | else if($1 == 12) 300 | temp_time.tm_hour = 0; 301 | } 302 | else 303 | { 304 | temp_time.tm_hour = $1; 305 | } 306 | specAmount[2] = 0; 307 | } 308 | | 309 | 310 | INTHE generalTimes { /******** ex. "in the morning" ******/ 311 | // NSLog(@"just in the morning"); 312 | specAmount[2] = 1; 313 | } 314 | | 315 | whenTime { } 316 | 317 | | 318 | 319 | whenTime INTHE generalTimes /******* 4:30 in the afternoon *******/ 320 | { 321 | if($3 > 0) 322 | { 323 | if(temp_time.tm_hour < 12) 324 | temp_time.tm_hour += 12; 325 | 326 | else if(temp_time.tm_hour == 12) 327 | temp_time.tm_hour = 0; 328 | } 329 | specAmount[2] = 1; 330 | } 331 | | 332 | generalTimes {} /****** ex. "morning" *******/ 333 | | 334 | 335 | LASTNEXT generalTimes /******* ex. "last night" **********/ 336 | { 337 | changeAmount[3] = $1; 338 | } 339 | | 340 | 341 | whenTime LASTNEXT generalTimes /****** ex. "7:30 last night" ********/ 342 | { 343 | changeAmount[3] = $2; 344 | specAmount[2] = 0; 345 | } 346 | | 347 | whenTime LASTNEXT DAYOFWEEK /****** ex. "7:30pm last Tuesday" ********/ 348 | { 349 | if($3 > 0 && $3 < 8) 350 | temp_time.tm_wday = $3-1; 351 | specAmount[1] = $2; 352 | 353 | } 354 | | 355 | whenTime THIS generalTimes /********* 3:30 this morning *********/ 356 | { 357 | if($3 > 0) 358 | { 359 | if(temp_time.tm_hour < 12) 360 | temp_time.tm_hour += 12; 361 | 362 | else if(temp_time.tm_hour == 12) 363 | temp_time.tm_hour = 0; 364 | } 365 | specAmount[2] = 0; 366 | } 367 | 368 | | 369 | DTPOSITION TYPENAMES expr /******* ex. "4th day last week", "3rd month next year" *******/ 370 | { 371 | switch($2) 372 | { 373 | case 3: 374 | { 375 | if($3 == 4) $1 -=1; 376 | else if($3 == 6) temp_time.tm_mon = 0; 377 | temp_time.tm_mday = $1; 378 | } 379 | break; 380 | case 4: 381 | { 382 | temp_time.tm_mday = 1; 383 | specAmount[1] = $1-1; 384 | } 385 | break; 386 | case 5: 387 | temp_time.tm_mon = $1-1; 388 | break; 389 | } 390 | } 391 | | 392 | DTPOSITION DAYOFWEEK expr /******* ex. "4th saturday next month", "3rd wed. in November" *******/ 393 | { 394 | if($2>0 && $2 < 8) 395 | { 396 | temp_time.tm_mday = 0; 397 | temp_time.tm_wday = $2-1; 398 | specAmount[1] = $1; 399 | } 400 | } 401 | 402 | 403 | | 404 | 405 | specAmountDayOrMonth { //NSLog(@"spec amount"); 406 | } 407 | 408 | 409 | ; 410 | 411 | 412 | 413 | 414 | specAmountDayOrMonth : 415 | INTEGER DAYOFWEEK /**** ex. "3 Fridays" used with "before or after" "2 tues after next thurs" ****/ 416 | { 417 | if($2 > 0 && $2 < 8) 418 | { 419 | mymodifier.specAmount[1] = $1; 420 | mymodifier.specValue[1] = $2-1; 421 | } 422 | } 423 | | 424 | INTEGER DAYOFWEEK HENCEAGO { /***** ex. "3 fridays hence" ****/ 425 | if($2 > 0 && $2 < 8) 426 | temp_time.tm_wday = $2-1; 427 | specAmount[1] = $1*$3; 428 | } 429 | | 430 | INTEGER MONTHNUM HENCEAGO { /***** ex. "3 Junes ago" ******/ 431 | temp_time.tm_mon = $2; 432 | specAmount[0] = $1*$3; 433 | } 434 | | 435 | INTEGER MONTHNUM INTEGER /**** ex. "3 june 1997" ******/ 436 | { 437 | temp_time.tm_mon = $2; 438 | temp_time.tm_mday = $1; 439 | if($3 < 1000) 440 | { 441 | if($3 < 15) 442 | $3 += (2000-1900); 443 | } 444 | temp_time.tm_year = $3; 445 | } 446 | | 447 | INTEGER MONTHNUM MILITARYTIME /**** ex. "3 june 2011" (had to do another to differentiate between military time and Year) ******/ 448 | { 449 | char *timeparts = strtok($3, ":"); 450 | char thedate[5] = ""; 451 | int actualdate= 0; 452 | strncat(thedate, timeparts, 2); 453 | timeparts = strtok (NULL, ":"); 454 | strncat(thedate, timeparts, 2); 455 | thedate[4] = '\0'; 456 | actualdate= atoi(thedate); 457 | 458 | temp_time.tm_mon = $2; 459 | temp_time.tm_mday = $1; 460 | temp_time.tm_year = actualdate-1900; 461 | } 462 | | 463 | MONTHNUM INTEGER /**** ex. "june 3" ******/ 464 | { 465 | temp_time.tm_mon = $1; 466 | if($2 >1900) 467 | temp_time.tm_year = $2-1900; 468 | else 469 | temp_time.tm_mday = $2; 470 | 471 | } 472 | | 473 | MONTHNUM MILITARYTIME /**** ex. "june 2008" ******/ 474 | { 475 | char *timeparts = strtok($2, ":"); 476 | char thedate[5] = ""; 477 | int actualdate= 0; 478 | strncat(thedate, timeparts, 2); 479 | timeparts = strtok (NULL, ":"); 480 | strncat(thedate, timeparts, 2); 481 | thedate[4] = '\0'; 482 | actualdate= atoi(thedate); 483 | 484 | temp_time.tm_mon = $1; 485 | temp_time.tm_year = actualdate-1900; 486 | } 487 | | 488 | MONTHNUM DTPOSITION /**** ex. "june 3rd" ******/ 489 | { 490 | temp_time.tm_mon = $1; 491 | temp_time.tm_mday = $2; 492 | } 493 | | 494 | MONTHNUM DTPOSITION INTEGER /***** ex. "june 3rd 1997" *****/ 495 | { 496 | if($3 < 1000) 497 | { 498 | if($3 < 15) 499 | $3 += (2000-1900); 500 | } 501 | temp_time.tm_mon = $1; 502 | temp_time.tm_mday = $2; 503 | temp_time.tm_year = $3; 504 | } 505 | | 506 | MONTHNUM INTEGER INTEGER /**** ex. "june 3 1997" ******/ 507 | { 508 | // NSLog(@"date = %d", $3); 509 | if($3 < 1000) 510 | { 511 | if($3 < 15) 512 | $3 += (2000-1900); 513 | } 514 | temp_time.tm_mon = $1; 515 | temp_time.tm_mday = $2; 516 | temp_time.tm_year = $3; 517 | } 518 | | 519 | MONTHNUM DTPOSITION MILITARYTIME 520 | { 521 | char *timeparts = strtok($3, ":"); 522 | char thedate[5] = ""; 523 | int actualdate= 0; 524 | strncat(thedate, timeparts, 2); 525 | timeparts = strtok (NULL, ":"); 526 | strncat(thedate, timeparts, 2); 527 | thedate[4] = '\0'; 528 | actualdate= atoi(thedate); 529 | 530 | 531 | temp_time.tm_mon = $1; 532 | temp_time.tm_mday = $2; 533 | temp_time.tm_year = actualdate-1900; 534 | } 535 | | 536 | MONTHNUM INTEGER MILITARYTIME 537 | { 538 | char *timeparts = strtok($3, ":"); 539 | char thedate[5] = ""; 540 | int actualdate= 0; 541 | strncat(thedate, timeparts, 2); 542 | timeparts = strtok (NULL, ":"); 543 | strncat(thedate, timeparts, 2); 544 | thedate[4] = '\0'; 545 | actualdate= atoi(thedate); 546 | 547 | temp_time.tm_mon = $1; 548 | temp_time.tm_mday = $2; 549 | temp_time.tm_year = actualdate-1900; 550 | } 551 | ; 552 | 553 | 554 | generalTimes: /****** ex. "morning", "afternoon" ********/ 555 | GENERALTIME { 556 | $$ = 1; 557 | if(temp_time.tm_hour < 0) 558 | { 559 | switch($1) 560 | { 561 | case 'm': 562 | { 563 | temp_time.tm_hour = 7; 564 | $$ = 0; 565 | } 566 | break; 567 | case 'a': 568 | { 569 | temp_time.tm_hour = 15; 570 | } 571 | break; 572 | case 'e': 573 | { 574 | temp_time.tm_hour = 18; 575 | } 576 | break; 577 | case 'n': 578 | { 579 | temp_time.tm_hour = 21; 580 | } 581 | break; 582 | // addition for tonight 583 | case 't': 584 | { 585 | temp_time.tm_hour = 21; 586 | } 587 | break; 588 | } 589 | } 590 | else if($1== 'm') $$ = 0; 591 | 592 | temp_time.tm_min = temp_time.tm_min >=0 ? temp_time.tm_min : 0; 593 | temp_time.tm_sec = temp_time.tm_sec >=0 ? temp_time.tm_sec : 0; 594 | changeAmount[8] = $1; 595 | } 596 | 597 | ; 598 | 599 | whenTime : /****** ex. "3:00" or "3pm" or "1830" ****/ 600 | MILITARYTIME 601 | { 602 | char *timeparts = strtok($1, ":"); 603 | temp_time.tm_hour= atoi(timeparts); 604 | timeparts = strtok (NULL, ":"); 605 | temp_time.tm_min= atoi(timeparts); 606 | temp_time.tm_sec = 0; 607 | } 608 | | 609 | WHENTIME { 610 | 611 | char *timeparts = strtok($1, ":"); 612 | temp_time.tm_hour= atoi(timeparts); 613 | temp_time.tm_min = 0; 614 | temp_time.tm_sec = 0; 615 | timeparts = strtok (NULL, ":"); 616 | while (timeparts != NULL) 617 | { 618 | if(timeparts[0]=='a') 619 | { 620 | if(temp_time.tm_hour == 12) 621 | temp_time.tm_hour = 0; 622 | } 623 | else if(timeparts[0]=='p') 624 | { 625 | if(temp_time.tm_hour < 12) 626 | temp_time.tm_hour += 12; 627 | } 628 | else 629 | { 630 | temp_time.tm_min = atoi(timeparts); 631 | } 632 | timeparts = strtok (NULL, ":"); 633 | } 634 | } 635 | 636 | ; 637 | 638 | %% 639 | 640 | void yyerror(char *s) { 641 | // NSLog(@"error"); 642 | fprintf(stderr, "%s\n", s); 643 | } 644 | --------------------------------------------------------------------------------