Best JavaScript code snippet using appium-xcuitest-driver
test_en_time_exp.js
Source:test_en_time_exp.js
1test("Test - Single Expression", function() {2 var text = "8:10";3 var results = chrono.parse(text, new Date(2012,7,10));4 ok(results.length == 1, JSON.stringify( results ) )5 var result = results[0];6 if(result){7 ok(result.index == 0, 'Wrong index')8 ok(result.text == '8:10', result.text )9 ok(result.start, JSON.stringify(result.start) )10 ok(result.start.get('hour') == 8, 'Test Result - (Day) ' + JSON.stringify(result.start) )11 ok(result.start.get('minute') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )12 ok(!result.start.isCertain('day'))13 ok(!result.start.isCertain('month'))14 ok(!result.start.isCertain('year'))15 ok(result.start.isCertain('hour'))16 ok(result.start.isCertain('minute'))17 ok(!result.start.isCertain('second'))18 ok(!result.start.isCertain('millisecond'))19 var resultDate = result.start.date();20 var expectDate = new Date(2012, 7, 10, 8, 10);21 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)22 }23 var text = "8:10 PM";24 var results = chrono.parse(text, new Date(2012,7,10));25 ok(results.length == 1, JSON.stringify( results ) )26 var result = results[0];27 if(result){28 ok(result.index == 0, 'Wrong index')29 ok(result.text == '8:10 PM', result.text )30 ok(result.start, JSON.stringify(result.start) )31 ok(result.start.get('hour') == 20, 'Test Result - (Day) ' + JSON.stringify(result.start) )32 ok(result.start.get('minute') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )33 ok(!result.start.isCertain('second'))34 ok(!result.start.isCertain('millisecond'))35 var resultDate = result.start.date();36 var expectDate = new Date(2012, 7, 10, 20, 10);37 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)38 }39 var text = "1230pm";40 var results = chrono.parse(text, new Date(2012,7,10));41 ok(results.length == 1, JSON.stringify( results ) )42 var result = results[0];43 if(result){44 ok(result.index == 0, 'Wrong index')45 ok(result.text == '1230pm', result.text )46 ok(result.start, JSON.stringify(result.start) )47 ok(result.start.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )48 ok(result.start.get('minute') == 30, 'Test Result - (Day) ' + JSON.stringify(result.start) )49 ok(!result.start.isCertain('second'))50 ok(!result.start.isCertain('millisecond'))51 var resultDate = result.start.date();52 var expectDate = new Date(2012, 7, 10, 12, 30);53 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)54 }55 56 var text = "5:16p";57 var results = chrono.parse(text, new Date(2012,7,10));58 ok(results.length == 1, JSON.stringify( results ) )59 var result = results[0];60 if(result){61 ok(result.index == 0, 'Wrong index')62 ok(result.text == '5:16p', result.text )63 ok(result.start, JSON.stringify(result.start) )64 ok(result.start.get('hour') == 17, 'Test Result - (Day) ' + JSON.stringify(result.start) )65 ok(result.start.get('minute') == 16, 'Test Result - (Day) ' + JSON.stringify(result.start) )66 ok(!result.start.isCertain('second'))67 ok(!result.start.isCertain('millisecond'))68 var resultDate = result.start.date();69 var expectDate = new Date(2012, 7, 10, 17, 16);70 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)71 }72 var text = "5:16 p.m.";73 var results = chrono.parse(text, new Date(2012,7,10));74 ok(results.length == 1, JSON.stringify( results ) )75 var result = results[0];76 if(result){77 ok(result.index == 0, 'Wrong index')78 ok(result.text == '5:16 p.m.', result.text )79 ok(result.start, JSON.stringify(result.start) )80 ok(result.start.get('hour') == 17, 'Test Result - (Day) ' + JSON.stringify(result.start) )81 ok(result.start.get('minute') == 16, 'Test Result - (Day) ' + JSON.stringify(result.start) )82 ok(!result.start.isCertain('second'))83 ok(!result.start.isCertain('millisecond'))84 var resultDate = result.start.date();85 var expectDate = new Date(2012, 7, 10, 17, 16);86 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)87 }88 var text = "Lets meet at 6.13 AM";89 var results = chrono.parse(text, new Date(2012,7,10));90 ok(results.length == 1, JSON.stringify( results ) )91 var result = results[0];92 if(result){93 ok(result.index == 10, 'Wrong index')94 ok(result.text == 'at 6.13 AM', result.text )95 ok(result.start, JSON.stringify(result.start) )96 ok(result.start.get('hour') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start) )97 ok(result.start.get('minute') == 13, 'Test Result - (Day) ' + JSON.stringify(result.start) )98 var resultDate = result.start.date();99 var expectDate = new Date(2012, 7, 10, 6, 13);100 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)101 }102 var text = '1-3pm';103 var results = chrono.parse(text, new Date(2012,7,10));104 ok(results.length == 1, JSON.stringify( results ) )105 var result = results[0];106 if(result){107 ok(result.index == 0, 'Wrong index')108 ok(result.text == '1-3pm', result.text )109 ok(result.start, JSON.stringify(result.start) )110 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )111 ok(result.start.get('minute') == 0, 'Test Result - (Minute) ' + JSON.stringify(result.start) )112 ok(result.start.get('meridiem') == 1, 'Test Result - (Meridiem) ' + JSON.stringify(result.start) )113 var resultDate = result.start.date();114 var expectDate = new Date(2012, 7, 10, 13, 00);115 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)116 117 ok(result.end, JSON.stringify(result.start) )118 ok(result.end.get('hour') == 15, 'Test Result - (Hour) ' + JSON.stringify(result.start) )119 ok(result.end.get('minute') == 0, 'Test Result - (Minute) ' + JSON.stringify(result.start) )120 ok(result.end.get('meridiem') == 1, 'Test Result - (Meridiem) ' + JSON.stringify(result.start) )121 var resultDate = result.end.date();122 var expectDate = new Date(2012, 7, 10, 15, 00);123 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)124 }125 var text = '11pm-2';126 var results = chrono.parse(text, new Date(2012,7,10));127 ok(results.length == 1, JSON.stringify( results ) )128 var result = results[0];129 if(result){130 ok(result.index == 0, 'Wrong index')131 ok(result.text == '11pm-2', result.text )132 ok(result.start, JSON.stringify(result.start) )133 ok(result.start.get('hour') == 23, 'Test Result - (Hour) ' + JSON.stringify(result.start) )134 ok(result.start.get('minute') == 0, 'Test Result - (Minute) ' + JSON.stringify(result.start) )135 ok(result.start.get('meridiem') == 1, 'Test Result - (Meridiem) ' + JSON.stringify(result.start) )136 var resultDate = result.start.date();137 var expectDate = new Date(2012, 7, 10, 23, 00);138 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)139 140 ok(result.end, JSON.stringify(result.start) )141 ok(result.end.get('hour') == 2, 'Test Result - (Hour) ' + JSON.stringify(result.start) )142 ok(result.end.get('minute') == 0, 'Test Result - (Minute) ' + JSON.stringify(result.start) )143 ok(result.end.get('meridiem') == 0, 'Test Result - (Meridiem) ' + JSON.stringify(result.start) )144 var resultDate = result.end.date();145 var expectDate = new Date(2012, 7, 11, 2, 00);146 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)147 }148});149test("Test - Range Expression", function() {150 var text = "8:10 - 12.32";151 var results = chrono.parse(text, new Date(2012,7,10));152 ok(results.length == 1, JSON.stringify( results ) )153 var result = results[0];154 if(result){155 ok(result.index == 0, 'Wrong index')156 ok(result.text == '8:10 - 12.32', result.text )157 ok(result.start, JSON.stringify(result.start) )158 ok(result.start.get('hour') == 8, 'Test Result - (Day) ' + JSON.stringify(result.start) )159 ok(result.start.get('minute') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )160 ok(!result.start.isCertain('day'))161 ok(!result.start.isCertain('month'))162 ok(!result.start.isCertain('year'))163 ok(result.start.isCertain('hour'))164 ok(result.start.isCertain('minute'))165 ok(!result.start.isCertain('second'))166 ok(!result.start.isCertain('millisecond'))167 var resultDate = result.start.date();168 var expectDate = new Date(2012, 7, 10, 8, 10);169 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)170 171 ok(result.end, JSON.stringify(result.start) )172 ok(result.end.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )173 ok(result.end.get('minute') == 32, 'Test Result - (Day) ' + JSON.stringify(result.start) )174 ok(!result.end.isCertain('day'))175 ok(!result.end.isCertain('month'))176 ok(!result.end.isCertain('year'))177 ok(result.end.isCertain('hour'))178 ok(result.end.isCertain('minute'))179 ok(!result.end.isCertain('second'))180 ok(!result.end.isCertain('millisecond'))181 var resultDate = result.end.date();182 var expectDate = new Date(2012, 7, 10, 12, 32);183 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)184 }185 var text = " from 6:30pm to 11:00pm ";186 var results = chrono.parse(text, new Date(2012,7,10));187 ok(results.length == 1, JSON.stringify( results ) )188 var result = results[0];189 if(result){190 ok(result.index == 1, 'Wrong index')191 ok(result.text == 'from 6:30pm to 11:00pm', result.text )192 ok(result.start, JSON.stringify(result.start) )193 ok(result.start.get('hour') == 18, 'Test Result - (Day) ' + JSON.stringify(result.start))194 ok(result.start.get('minute') == 30, 'Test Result - (Day) ' + JSON.stringify(result.start))195 ok(result.start.get('meridiem') == 1, 'Test Result - (Day) ' + JSON.stringify(result.start))196 var resultDate = result.start.date();197 var expectDate = new Date(2012, 7, 10, 18, 30);198 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)199 200 ok(result.end, JSON.stringify(result.start) )201 ok(result.end.get('hour') == 23, 'Test Result - (Day) ' + JSON.stringify(result.end) )202 ok(result.end.get('minute') == 0, 'Test Result - (Day) ' + JSON.stringify(result.end) )203 ok(result.end.get('meridiem') == 1, 'Test Result - (Day) ' + JSON.stringify(result.end) )204 var resultDate = result.end.date();205 var expectDate = new Date(2012, 7, 10, 23, 0);206 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)207 }208});209test("Test - Impossible", function() {210 var text = "8:62";211 var results = chrono.parse(text, new Date(2012,7,10));212 ok(results.length == 0, JSON.stringify( results ) )213 var text = "25:12";214 var results = chrono.parse(text, new Date(2012,7,10));215 ok(results.length == 0, JSON.stringify( results ) )216 var text = "13.12 PM";217 var results = chrono.parse(text, new Date(2012,7,10));218 ok(results.length == 0, JSON.stringify( results ) )219});220test("Test - Date + Time Expression", function() {221 var text = "Something happen on 2014-04-18 3.00 AM";222 var results = chrono.parse(text, new Date(2012,7,10));223 ok(results.length == 1, JSON.stringify( results ) )224 var result = results[0];225 if(result){226 ok(result.index == 20, 'Wrong index')227 ok(result.text == '2014-04-18 3.00 AM', result.text )228 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )229 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )230 ok(result.start.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.start) )231 ok(result.start.get('hour') == 3, 'Test Result - (Hour) ' + JSON.stringify(result.start) )232 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )233 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )234 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )235 ok(!result.start.isCertain('millisecond'))236 var resultDate = result.start.date();237 var expectDate = new Date(2014, 4-1, 18, 3, 0);238 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)239 }240 var text = "Something happen on August 10, 2012 10:12:59 pm";241 var results = chrono.parse(text, new Date(2012,7,10));242 ok(results.length == 1, JSON.stringify( results ) )243 var result = results[0];244 if(result){245 ok(result.index == 20, 'Wrong index')246 ok(result.text == 'August 10, 2012 10:12:59 pm', result.text )247 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )248 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )249 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )250 ok(result.start.get('hour') == 22, 'Test Result - (Hour) ' + JSON.stringify(result.start) )251 ok(result.start.get('minute') == 12, 'Test Result - (minute) ' + JSON.stringify(result.start) )252 ok(result.start.get('second') == 59, 'Test Result - (second) ' + JSON.stringify(result.start) )253 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )254 ok(!result.start.isCertain('millisecond'))255 var resultDate = result.start.date();256 var expectDate = new Date(2012, 8-1, 10, 22, 12, 59);257 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)258 }259 var text = "Something happen on 2014-04-18 7:00 - 8:00 AM...";260 var results = chrono.parse(text, new Date(2012,7,10));261 ok(results.length == 1, JSON.stringify( results ) )262 var result = results[0];263 if(result){264 ok(result.index == 20, 'Wrong index')265 ok(result.text == '2014-04-18 7:00 - 8:00 AM', result.text )266 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )267 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )268 ok(result.start.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.start) )269 ok(result.start.get('hour') == 7, 'Test Result - (Hour) ' + JSON.stringify(result.start) )270 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )271 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )272 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )273 ok(result.start.get('meridiem') == 0, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )274 ok(!result.start.isCertain('millisecond'))275 var resultDate = result.start.date();276 var expectDate = new Date(2014, 4-1, 18, 7, 0);277 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)278 ok(result.end.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.end) )279 ok(result.end.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.end) )280 ok(result.end.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.end) )281 ok(result.end.get('hour') == 8, 'Test Result - (Hour) ' + JSON.stringify(result.end) )282 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )283 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )284 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )285 ok(result.end.get('meridiem') == 0, 'Test Result - (meridiem) ' + JSON.stringify(result.end) )286 ok(!result.end.isCertain('millisecond'))287 var resultDate = result.end.date();288 var expectDate = new Date(2014, 4-1, 18, 8, 0);289 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)290 }291 var text = "Something happen on 2014-04-18 7:00 - 8:00 PM...";292 var results = chrono.parse(text, new Date(2012,7,10));293 ok(results.length == 1, JSON.stringify( results ) )294 var result = results[0];295 if(result){296 ok(result.index == 20, 'Wrong index')297 ok(result.text == '2014-04-18 7:00 - 8:00 PM', result.text )298 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )299 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )300 ok(result.start.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.start) )301 ok(result.start.get('hour') == 19, 'Test Result - (Hour) ' + JSON.stringify(result.start) )302 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )303 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )304 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )305 ok(result.start.get('meridiem') == 1, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )306 ok(!result.start.isCertain('millisecond'))307 var resultDate = result.start.date();308 var expectDate = new Date(2014, 4-1, 18, 19, 0);309 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)310 ok(result.end.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.end) )311 ok(result.end.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.end) )312 ok(result.end.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.end) )313 ok(result.end.get('hour') == 20, 'Test Result - (Hour) ' + JSON.stringify(result.end) )314 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )315 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )316 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )317 ok(result.end.get('meridiem') == 1, 'Test Result - (meridiem) ' + JSON.stringify(result.end) )318 ok(!result.end.isCertain('millisecond'))319 var resultDate = result.end.date();320 var expectDate = new Date(2014, 4-1, 18, 20, 0);321 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date ' + resultDate +'/' +expectDate)322 }323})324test("Test - Time Expression's Meridiem imply", function() {325 var text = "1pm-3";326 var results = chrono.parse(text, new Date(2012,7,10));327 ok(results.length == 1, JSON.stringify( results ) )328 var result = results[0];329 if(result){330 ok(result.index == 0, 'Wrong index')331 ok(result.text == '1pm-3', result.text )332 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )333 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )334 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )335 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )336 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )337 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )338 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )339 ok(result.start.get('meridiem') == 1, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )340 ok(result.start.isCertain('meridiem'), JSON.stringify(result))341 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.end) )342 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.end) )343 ok(result.end.get('day') == 11, 'Test Result - (Day) ' + JSON.stringify(result.end) )344 ok(result.end.get('hour') == 3, 'Test Result - (Hour) ' + JSON.stringify(result.end) )345 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )346 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )347 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )348 ok(!result.end.isCertain('meridiem'), JSON.stringify(result))349 }350 var text = "2014-04-18 1pm-3";351 var results = chrono.parse(text, new Date(2012,7,10));352 ok(results.length == 1, JSON.stringify( results ) )353 var result = results[0];354 if(result){355 ok(result.index == 0, 'Wrong index')356 ok(result.text == '2014-04-18 1pm-3', result.text )357 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )358 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )359 ok(result.start.get('day') == 18, 'Test Result - (Day) ' + JSON.stringify(result.start) )360 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )361 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )362 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )363 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )364 ok(result.start.get('meridiem') == 1, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )365 ok(result.start.isCertain('meridiem'), JSON.stringify(result))366 ok(result.end.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.end) )367 ok(result.end.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.end) )368 ok(result.end.get('day') == 19, 'Test Result - (Day) ' + JSON.stringify(result.end) )369 ok(result.end.get('hour') == 3, 'Test Result - (Hour) ' + JSON.stringify(result.end) )370 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )371 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )372 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )373 ok(!result.end.isCertain('meridiem'), JSON.stringify(result))374 }375 var text = "today from 1pm-3";376 var results = chrono.parse(text, new Date(2012,7,10));377 ok(results.length == 1, JSON.stringify( results ) )378 var result = results[0];379 if (result) {380 ok(result.index == 0, 'Wrong index')381 ok(result.text == 'today from 1pm-3', result.text )382 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )383 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )384 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )385 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )386 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )387 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )388 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )389 ok(result.start.get('meridiem') == 1, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )390 ok(result.start.isCertain('meridiem'), JSON.stringify(result))391 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.end) )392 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.end) )393 ok(result.end.get('day') == 11, 'Test Result - (Day) ' + JSON.stringify(result.end) )394 ok(result.end.get('hour') == 3, 'Test Result - (Hour) ' + JSON.stringify(result.end) )395 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )396 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )397 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )398 ok(!result.end.isCertain('meridiem'), JSON.stringify(result))399 }400 var text = "today from 1am-3";401 var results = chrono.parse(text, new Date(2012,7,10));402 ok(results.length == 1, JSON.stringify( results ) )403 var result = results[0];404 if (result) {405 ok(result.index == 0, 'Wrong index')406 ok(result.text == 'today from 1am-3', result.text )407 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )408 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )409 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )410 ok(result.start.get('hour') == 1, 'Test Result - (Hour) ' + JSON.stringify(result.start) )411 ok(result.start.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.start) )412 ok(result.start.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.start) )413 ok(result.start.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.start) )414 ok(result.start.get('meridiem') == 0, 'Test Result - (meridiem) ' + JSON.stringify(result.start) )415 ok(result.start.isCertain('meridiem'), JSON.stringify(result))416 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.end) )417 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.end) )418 ok(result.end.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.end) )419 ok(result.end.get('hour') == 3, 'Test Result - (Hour) ' + JSON.stringify(result.end) )420 ok(result.end.get('minute') == 0, 'Test Result - (minute) ' + JSON.stringify(result.end) )421 ok(result.end.get('second') == 0, 'Test Result - (second) ' + JSON.stringify(result.end) )422 ok(result.end.get('millisecond') == 0, 'Test Result - (millisecond) ' + JSON.stringify(result.end) )423 ok(!result.end.isCertain('meridiem'), JSON.stringify(result))424 }425})426test("Test - Timezone extraction", function() {427 var text = "friday at 2 pm";428 var result = chrono.parse(text, new Date(2016, 3, 28))[0];429 ok(result.text == text, result.text)430 ok(!result.start.isCertain('timezoneOffset'), JSON.stringify(result.start))431 ok(!result.start.get('timezoneOffset'), JSON.stringify(result.start))432 var text = "friday at 2 pm EST";433 var result = chrono.parse(text, new Date(2016, 3, 28))[0];434 ok(result.text == text, result.text)435 ok(result.start.isCertain('timezoneOffset'), JSON.stringify(result.start))436 ok(result.start.get('timezoneOffset') === -300, JSON.stringify(result.start))437 var text = "friday at 2 pm est";438 var result = chrono.parse(text, new Date(2016, 3, 28))[0];439 ok(result.text == text, result.text)440 ok(result.start.isCertain('timezoneOffset'), JSON.stringify(result.start))441 ok(result.start.get('timezoneOffset') === -300, JSON.stringify(result.start))442 var text = "friday at 2 pm establish ...";443 var result = chrono.parse(text, new Date(2016, 3, 28))[0];444 ok(result.text == 'friday at 2 pm', result.text)445 ok(!result.start.isCertain('timezoneOffset'), JSON.stringify(result.start))446 ok(!result.start.get('timezoneOffset'), JSON.stringify(result.start))447 var text = "friday at 2 pm I will do something";448 var result = chrono.parse(text, new Date(2016, 3, 28))[0];449 ok(result.text == 'friday at 2 pm', result.text)450 ok(!result.start.isCertain('timezoneOffset'), JSON.stringify(result.start))451 ok(!result.start.get('timezoneOffset'), JSON.stringify(result.start))452})453test("Test - Random date + time expression", function() {454 var text = "monday 4/29/2013 630-930am";455 var result = chrono.parse(text)[0];456 ok(result.text == text, result.text)457 458 var text = "wednesday 5/1/2013 1115am";459 var result = chrono.parse(text)[0];460 ok(result.text == text, result.text)461 462 var text = "friday 5/3/2013 1230pm";463 var result = chrono.parse(text)[0];464 ok(result.text == text, result.text)465 466 var text = "sunday 5/6/2013 750am-910am";467 var result = chrono.parse(text)[0];468 ok(result.text == text, result.text)469 var text = "monday 5/13/2013 630-930am";470 var result = chrono.parse(text)[0];471 ok(result.text == text, result.text)472 var text = "wednesday 5/15/2013 1030am";473 var result = chrono.parse(text)[0];474 ok(result.text == text, result.text)475 var text = "friday 6/21/2013 2:30";476 var result = chrono.parse(text)[0];477 ok(result.text == text, result.text)478 var text = "tuesday 7/2/2013 1-230 pm";479 var result = chrono.parse(text)[0];480 ok(result.text == text, result.text)481 var text = "Monday, 6/24/2013, 7:00pm - 8:30pm";482 var result = chrono.parse(text)[0];483 ok(result.text == text, result.text)484 var text = "Thursday6/20/2013 from 7:00 PM to 10:00 PM";485 var result = chrono.parse(text)[0];486 ok(result.text == text, result.text)487 var text = "Wednesday, July 03, 2013 2pm";488 var result = chrono.parse(text)[0];489 ok(result.text == text, result.text)490 var text = "6pm";491 var result = chrono.parse(text)[0];492 ok(result.text == text, result.text)493 var text = "6 pm";494 var result = chrono.parse(text)[0];495 ok(result.text == text, result.text)496 var text = "7-10pm";497 var result = chrono.parse(text)[0];498 ok(result.text == text, result.text)499 var text = "11.1pm";500 var result = chrono.parse(text)[0];501 ok(result.text == text, result.text)502 var text = "that I need to know or am I covered?";503 var result = chrono.parse(text);504 ok(result.length == 0, result)505 var text = "at 12";506 var result = chrono.parse(text)[0];507 ok(result.text == text, result.text)508 var text = "at noon";509 var result = chrono.parse(text)[0];510 ok(result.text == text, result.text)511 ok(result.start.get('hour') == 12, JSON.stringify(result.start))512 ok(result.start.get('hour') == 12, JSON.stringify(result.start))513 var text = "at midnight";514 var result = chrono.parse(text)[0];515 ok(result.text == text, result.text)...
test_en_middle_endian.js
Source:test_en_middle_endian.js
1test("Test - Single Expression", function() {2 var text = 'She is getting married next year (July 2017).';3 var results = chrono.parse(text, new Date(2012,7,10));4 ok(results.length == 1, JSON.stringify( results ) )5 var result = results[0];6 if(result){7 ok(result.start, JSON.stringify(result.start) )8 ok(result.start.get('year') == 2017, 'Test Result - (Year) ' + JSON.stringify(result.start) )9 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result.start) )10 ok(result.start.get('day') == 1, 'Test Result - (Day) ' + JSON.stringify(result.start) )11 ok(result.index == 34, 'Wrong index')12 ok(result.text == 'July 2017', result.text )13 var resultDate = result.start.date();14 var expectDate = new Date(2017, 7-1, 1, 12);15 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)16 }17 var text = 'She is leaving in August.';18 var results = chrono.parse(text, new Date(2012,7,10));19 ok(results.length == 1, JSON.stringify( results ) )20 var result = results[0];21 if(result){22 ok(result.start, JSON.stringify(result.start) )23 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )24 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )25 ok(result.start.get('day') == 1, 'Test Result - (Day) ' + JSON.stringify(result.start) )26 ok(result.index == 18, 'Wrong index')27 ok(result.text == 'August', result.text )28 var resultDate = result.start.date();29 var expectDate = new Date(2012, 8-1, 1, 12);30 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)31 }32 var text = 'I am arriving sometime in August, 2012, probably.';33 var results = chrono.parse(text, new Date(2012,7,10));34 ok(results.length == 1, JSON.stringify( results ) )35 var result = results[0];36 if(result){37 ok(result.start, JSON.stringify(result.start) )38 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )39 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )40 ok(result.start.get('day') == 1, 'Test Result - (Day) ' + JSON.stringify(result.start) )41 ok(result.index == 26, 'Wrong index')42 ok(result.text == 'August, 2012', result.text )43 var resultDate = result.start.date();44 var expectDate = new Date(2012, 8-1, 1, 12);45 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)46 }47 var text = 'August 10, 2012';48 var results = chrono.parse(text, new Date(2012,7,10));49 ok(results.length == 1, JSON.stringify( results ) )50 var result = results[0];51 if(result){52 ok(result.start, JSON.stringify(result.start) )53 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )54 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )55 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )56 ok(result.index == 0, 'Wrong index')57 ok(result.text == 'August 10, 2012', result.text )58 var resultDate = result.start.date();59 var expectDate = new Date(2012, 8-1, 10, 12);60 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)61 }62 var text = 'Nov 12, 2011';63 var results = chrono.parse(text, new Date(2012,7,10));64 ok(results.length == 1, JSON.stringify( results ) )65 var result = results[0];66 if(result){67 ok(result.start, JSON.stringify(result.start) )68 ok(result.start.get('year') == 2011, 'Test Result - (Year) ' + JSON.stringify(result.start) )69 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )70 ok(result.start.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )71 ok(result.index == 0, 'Wrong index')72 ok(result.text == 'Nov 12, 2011', result.text )73 var resultDate = result.start.date();74 var expectDate = new Date(2011, 11-1, 12, 12);75 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)76 }77 var text = 'The Deadline is August 10';78 var results = chrono.parse(text, new Date(2012,7,10));79 ok(results.length == 1, JSON.stringify( results ) )80 var result = results[0];81 if(result){82 ok(result.start, JSON.stringify(result.start) )83 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )84 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )85 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )86 ok(result.index == 16, 'Wrong index')87 ok(result.text == 'August 10', result.text )88 var resultDate = result.start.date();89 var expectDate = new Date(2012, 8-1, 10, 12);90 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)91 }92 var text = "The Deadline is August 10 2555 BE";93 var results = chrono.parse(text, new Date(2012,7,10));94 ok(results.length == 1, JSON.stringify( results ) )95 var result = results[0];96 if(result){97 ok(result.index == 16, 'Wrong index')98 ok(result.text == 'August 10 2555 BE', result.text )99 var resultDate = result.start.date();100 var expectDate = new Date(2012, 8-1, 10, 12);101 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)102 }103 var text = 'The Deadline is Tuesday, January 10';104 var results = chrono.parse(text, new Date(2012,7,10));105 ok(results.length == 1, JSON.stringify( results ) )106 var result = results[0];107 if(result){108 ok(result.text == 'Tuesday, January 10', result.text )109 ok(result.start, JSON.stringify(result.start) )110 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) )111 ok(result.start.get('month') == 1, 'Test Result - (Month) ' + JSON.stringify(result.start) )112 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )113 ok(result.start.get('weekday') == 2, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )114 var resultDate = result.start.date();115 var expectDate = new Date(2013, 1-1, 10, 12);116 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)117 }118 var text = 'Sun, Mar. 6, 2016';119 var results = chrono.parse(text, new Date(2012,7,10));120 ok(results.length == 1, JSON.stringify( results ) );121 var result = results[0];122 if(result){123 ok(result.start, JSON.stringify(result.start));124 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start));125 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start));126 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start));127 }128 var text = 'Sun, March 6, 2016';129 var results = chrono.parse(text, new Date(2012,7,10));130 ok(results.length == 1, JSON.stringify( results ) );131 var result = results[0];132 if(result){133 ok(result.start, JSON.stringify(result.start));134 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start));135 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start));136 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start));137 }138 var text = 'Sun., March 6, 2016';139 var results = chrono.parse(text, new Date(2012,7,10));140 ok(results.length == 1, JSON.stringify( results ) );141 var result = results[0];142 if(result){143 ok(result.start, JSON.stringify(result.start));144 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start));145 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start));146 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start));147 }148 var text = 'Sunday, March 6, 2016';149 var results = chrono.parse(text, new Date(2012,7,10));150 ok(results.length == 1, JSON.stringify( results ) );151 var result = results[0];152 if(result){153 ok(result.start, JSON.stringify(result.start));154 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start));155 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start));156 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start));157 }158 var text = 'Sunday, March 6, 2016';159 var results = chrono.parse(text, new Date(2012,7,10));160 ok(results.length == 1, JSON.stringify( results ) );161 var result = results[0];162 if(result){163 ok(result.start, JSON.stringify(result.start));164 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start));165 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start));166 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start));167 }168});169test("Test - Range expression", function() {170 var text = 'August 10 - 22, 2012';171 var results = chrono.parse(text, new Date(2012,7,10));172 ok(results.length == 1, JSON.stringify( results ) )173 var result = results[0];174 if(result){175 ok(result.index == 0, 'Wrong index')176 ok(result.text == 'August 10 - 22, 2012', result.text )177 ok(result.start, JSON.stringify(result.start) )178 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )179 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )180 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )181 var resultDate = result.start.date();182 var expectDate = new Date(2012, 8-1, 10, 12);183 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)184 185 ok(result.end, JSON.stringify(result.end) )186 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )187 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )188 ok(result.end.get('day') == 22, 'Test Result - (Day) ' + JSON.stringify(result.start) )189 var resultDate = result.end.date();190 var expectDate = new Date(2012, 8-1, 22, 12);191 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)192 }193 var text = 'August 10 to 22, 2012';194 var results = chrono.parse(text, new Date(2012,7,10));195 ok(results.length == 1, JSON.stringify( results ) )196 var result = results[0];197 if(result){198 ok(result.index == 0, 'Wrong index')199 ok(result.text == 'August 10 to 22, 2012', result.text )200 ok(result.start, JSON.stringify(result.start) )201 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )202 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )203 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )204 var resultDate = result.start.date();205 var expectDate = new Date(2012, 8-1, 10, 12);206 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)207 208 ok(result.end, JSON.stringify(result.end) )209 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )210 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )211 ok(result.end.get('day') == 22, 'Test Result - (Day) ' + JSON.stringify(result.start) )212 var resultDate = result.end.date();213 var expectDate = new Date(2012, 8-1, 22, 12);214 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)215 }216 var text = 'August 10 - November 12';217 var results = chrono.parse(text, new Date(2012,7,10));218 ok(results.length == 1, JSON.stringify( results ) )219 var result = results[0];220 if(result){221 ok(result.index == 0, 'Wrong index')222 ok(result.text == 'August 10 - November 12', result.text )223 ok(result.start, JSON.stringify(result.start) )224 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )225 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )226 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )227 var resultDate = result.start.date();228 var expectDate = new Date(2012, 8-1, 10, 12);229 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)230 231 ok(result.end, JSON.stringify(result.end) )232 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )233 ok(result.end.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )234 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )235 var resultDate = result.end.date();236 var expectDate = new Date(2012, 11-1, 12, 12);237 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)238 }239 var text = 'Aug 10 to Nov 12';240 var results = chrono.parse(text, new Date(2012,7,10));241 ok(results.length == 1, JSON.stringify( results ) )242 var result = results[0];243 if(result){244 ok(result.index == 0, 'Wrong index')245 ok(result.text == 'Aug 10 to Nov 12', result.text )246 ok(result.start, JSON.stringify(result.start) )247 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )248 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )249 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )250 var resultDate = result.start.date();251 var expectDate = new Date(2012, 8-1, 10, 12);252 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)253 254 ok(result.end, JSON.stringify(result.end) )255 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )256 ok(result.end.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )257 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )258 var resultDate = result.end.date();259 var expectDate = new Date(2012, 11-1, 12, 12);260 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)261 }262 var text = 'Aug 10 - Nov 12, 2013';263 var results = chrono.parse(text, new Date(2012,7,10));264 ok(results.length == 1, JSON.stringify( results ) )265 var result = results[0];266 if(result){267 ok(result.index == 0, 'Wrong index')268 ok(result.text == 'Aug 10 - Nov 12, 2013', result.text )269 ok(result.start, JSON.stringify(result.start) )270 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) )271 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )272 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )273 var resultDate = result.start.date();274 var expectDate = new Date(2013, 8-1, 10, 12);275 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)276 277 ok(result.end, JSON.stringify(result.end) )278 ok(result.end.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) )279 ok(result.end.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )280 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )281 var resultDate = result.end.date();282 var expectDate = new Date(2013, 11-1, 12, 12);283 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)284 }285 var text = 'Aug 10 - Nov 12, 2011';286 var results = chrono.parse(text, new Date(2012,7,10));287 ok(results.length == 1, JSON.stringify( results ) )288 var result = results[0];289 if(result){290 291 ok(result.index == 0, 'Wrong index')292 ok(result.text == 'Aug 10 - Nov 12, 2011', result.text )293 294 ok(result.start, JSON.stringify(result.start) )295 ok(result.start.get('year') == 2011, 'Test Result - (Year) ' + JSON.stringify(result.start) )296 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )297 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )298 var resultDate = result.start.date();299 var expectDate = new Date(2011, 8-1, 10, 12);300 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)301 302 ok(result.end, JSON.stringify(result.end) )303 ok(result.end.get('year') == 2011, 'Test Result - (Year) ' + JSON.stringify(result.start) )304 ok(result.end.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )305 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )306 var resultDate = result.end.date();307 var expectDate = new Date(2011, 11-1, 12, 12);308 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)309 }310});311test("Test - Impossible Dates (Strict Mode)", function() {312 313 var text = "August 32, 2014";314 var results = chrono.strict.parse(text, new Date(2012,7,10));315 ok(results.length == 0, JSON.stringify( results ) )316 var text = "Febuary 29, 2014";317 var results = chrono.strict.parse(text, new Date(2012,7,10));318 ok(results.length == 0, JSON.stringify( results ))319 var text = "August 32";320 var results = chrono.strict.parse(text, new Date(2012,7,10));321 ok(results.length == 0, JSON.stringify( results ))322 var text = "Febuary 29";323 var results = chrono.strict.parse(text, new Date(2012,7,10));324 ok(results.length == 0, JSON.stringify( results ))325});326test("Test - Impossible Dates (Casual Mode)", function() {327 328 var text = "August 32, 2015";329 var expectDate = new Date(2015, 8, 1, 12, 0);330 var results = chrono.parse(text);331 var resultDate = results[0].start.date();332 ok(results.length == 1, JSON.stringify(results) )333 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 1000, resultDate +'/' +expectDate);...
test_en_little_endian.js
Source:test_en_little_endian.js
1test("Test - Single expression", function() {2 var text = "10 August 2012";3 var results = chrono.parse(text, new Date(2012,7,10));4 ok(results.length == 1, JSON.stringify( results ) );5 var result = results[0];6 if (result) {7 ok(result.start, JSON.stringify(result.start) );8 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );9 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );10 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );11 ok(result.index == 0, 'Wrong index');12 ok(result.text == '10 August 2012', result.text );13 var resultDate = result.start.date();14 var expectDate = new Date(2012, 8-1, 10, 12);15 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)16 }17 var text = "10 August 2555 BE";18 var results = chrono.parse(text, new Date(2012,7,10));19 ok(results.length == 1, JSON.stringify( results ) );20 var result = results[0];21 if (result) {22 ok(result.index == 0, 'Wrong index');23 ok(result.text == '10 August 2555 BE', result.text );24 ok(result.start, JSON.stringify(result.start) );25 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );26 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );27 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );28 var resultDate = result.start.date();29 var expectDate = new Date(2012, 8-1, 10, 12);30 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)31 }32 var text = 'Sun 15Sep';33 var results = chrono.parse(text, new Date(2013,7,10));34 ok(results.length == 1, JSON.stringify( results ) );35 var result = results[0];36 if(result){37 ok(result.index == 0, 'Wrong index');38 ok(result.text == 'Sun 15Sep', result.text );39 ok(result.start, JSON.stringify(result.start) );40 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) );41 ok(result.start.get('month') == 9, 'Test Result - (Month) ' + JSON.stringify(result.start) );42 ok(result.start.get('day') == 15, 'Test Result - (Day) ' + JSON.stringify(result.start) );43 var resultDate = result.start.date();44 var expectDate = new Date(2013, 9-1, 15, 12);45 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)46 }47 var text = 'SUN 15SEP';48 var results = chrono.parse(text, new Date(2013,7,10));49 ok(results.length == 1, JSON.stringify( results ) );50 var result = results[0];51 if(result){52 ok(result.index == 0, 'Wrong index');53 ok(result.text == 'SUN 15SEP', result.text );54 55 ok(result.start, JSON.stringify(result.start) );56 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) );57 ok(result.start.get('month') == 9, 'Test Result - (Month) ' + JSON.stringify(result.start) );58 ok(result.start.get('day') == 15, 'Test Result - (Day) ' + JSON.stringify(result.start) );59 var resultDate = result.start.date();60 var expectDate = new Date(2013, 9-1, 15, 12);61 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)62 }63 var text = "The Deadline is 10 August";64 var results = chrono.parse(text, new Date(2012,7,10));65 ok(results.length == 1, JSON.stringify( results ) );66 var result = results[0];67 if (result) {68 ok(result.index == 16, 'Wrong index');69 ok(result.text == '10 August', result.text );70 ok(result.start, JSON.stringify(result.start) );71 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );72 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );73 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );74 var resultDate = result.start.date();75 var expectDate = new Date(2012, 8-1, 10, 12);76 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)77 }78 var text = "The Deadline is Tuesday, 10 January";79 var results = chrono.parse(text, new Date(2012,7,10));80 ok(results.length == 1, JSON.stringify( results ) );81 var result = results[0];82 if (result) {83 ok(result.index == 16, 'Wrong index');84 ok(result.text == 'Tuesday, 10 January', result.text );85 ok(result.start, JSON.stringify(result.start) );86 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) );87 ok(result.start.get('month') == 1, 'Test Result - (Month) ' + JSON.stringify(result.start) );88 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );89 ok(result.start.get('weekday') == 2, 'Test Result - (Day) ' + JSON.stringify(result.start) );90 var resultDate = result.start.date();91 var expectDate = new Date(2013, 1-1, 10, 12);92 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)93 }94 var text = "The Deadline is Tue, 10 January";95 var results = chrono.parse(text, new Date(2012,7,10));96 ok(results.length == 1, JSON.stringify( results ) );97 var result = results[0];98 if (result) {99 ok(result.index == 16, 'Wrong index');100 ok(result.text == 'Tue, 10 January', result.text );101 ok(result.start, JSON.stringify(result.start) );102 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) );103 ok(result.start.get('month') == 1, 'Test Result - (Month) ' + JSON.stringify(result.start) );104 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );105 ok(result.start.get('weekday') == 2, 'Test Result - (Day) ' + JSON.stringify(result.start) );106 var resultDate = result.start.date();107 var expectDate = new Date(2013, 1-1, 10, 12);108 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)109 }110 var text = "31st March, 2016";111 var results = chrono.parse(text, new Date(2012,7,10));112 ok(results.length == 1, JSON.stringify( results ) );113 var result = results[0];114 if (result) {115 ok(result.index == 0, 'Wrong index');116 ok(result.text == '31st March, 2016', result.text );117 ok(result.start, JSON.stringify(result.start) );118 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start) );119 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start) );120 ok(result.start.get('day') == 31, 'Test Result - (Day) ' + JSON.stringify(result.start) );121 var resultDate = result.start.date();122 var expectDate = new Date(2016, 3-1, 31, 12);123 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)124 }125 var text = "23rd february, 2016";126 var results = chrono.parse(text, new Date(2012,7,10));127 ok(results.length == 1, JSON.stringify( results ) );128 var result = results[0];129 if (result) {130 ok(result.index == 0, 'Wrong index');131 ok(result.text == '23rd february, 2016', result.text );132 ok(result.start, JSON.stringify(result.start) );133 ok(result.start.get('year') == 2016, 'Test Result - (Year) ' + JSON.stringify(result.start) );134 ok(result.start.get('month') == 2, 'Test Result - (Month) ' + JSON.stringify(result.start) );135 ok(result.start.get('day') == 23, 'Test Result - (Day) ' + JSON.stringify(result.start) );136 var resultDate = result.start.date();137 var expectDate = new Date(2016, 2-1, 23, 12);138 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)139 }140});141test("Test - Range expression", function() {142 var text = "10 - 22 August 2012";143 var results = chrono.parse(text, new Date(2012,7,10));144 ok(results.length == 1, JSON.stringify( results ) );145 var result = results[0];146 if(result){147 ok(result.index == 0, 'Wrong index');148 ok(result.text == '10 - 22 August 2012', result.text );149 ok(result.start, JSON.stringify(result.start) );150 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );151 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );152 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );153 var resultDate = result.start.date();154 var expectDate = new Date(2012, 8-1, 10, 12);155 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate);156 157 ok(result.end, JSON.stringify(result.end) );158 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );159 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );160 ok(result.end.get('day') == 22, 'Test Result - (Day) ' + JSON.stringify(result.start) );161 var resultDate = result.end.date();162 var expectDate = new Date(2012, 8-1, 22, 12);163 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)164 }165 var text = "10 to 22 August 2012";166 var results = chrono.parse(text, new Date(2012,7,10));167 ok(results.length == 1, JSON.stringify( results ) );168 var result = results[0];169 if(result){170 ok(result.index == 0, 'Wrong index');171 ok(result.text == '10 to 22 August 2012', result.text );172 ok(result.start, JSON.stringify(result.start) );173 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );174 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );175 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );176 var resultDate = result.start.date();177 var expectDate = new Date(2012, 8-1, 10, 12);178 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate);179 180 ok(result.end, JSON.stringify(result.end) );181 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.end) );182 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.end) );183 ok(result.end.get('day') == 22, 'Test Result - (Day) ' + JSON.stringify(result.end) );184 var resultDate = result.end.date();185 var expectDate = new Date(2012, 8-1, 22, 12);186 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)187 }188 var text = "10 August - 12 September";189 var results = chrono.parse(text, new Date(2012,7,10));190 ok(results.length == 1, JSON.stringify( results ) );191 var result = results[0];192 if(result){193 ok(result.index == 0, 'Wrong index');194 ok(result.text == '10 August - 12 September', result.text );195 ok(result.start, JSON.stringify(result.start) );196 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );197 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );198 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );199 var resultDate = result.start.date();200 var expectDate = new Date(2012, 8-1, 10, 12);201 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate);202 203 ok(result.end, JSON.stringify(result.end) );204 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.end) );205 ok(result.end.get('month') == 9, 'Test Result - (Month) ' + JSON.stringify(result.end) );206 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.end) );207 var resultDate = result.end.date();208 var expectDate = new Date(2012, 9-1, 12, 12);209 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)210 }211 var text = "10 August - 12 September 2013";212 var results = chrono.parse(text, new Date(2012,7,10));213 ok(results.length == 1, JSON.stringify( results ) );214 var result = results[0];215 if(result){216 ok(result.index == 0, 'Wrong index');217 ok(result.text == '10 August - 12 September 2013', result.text );218 ok(result.start, JSON.stringify(result.start) );219 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) );220 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );221 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );222 var resultDate = result.start.date();223 var expectDate = new Date(2013, 8-1, 10, 12);224 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate);225 226 ok(result.end, JSON.stringify(result.end) );227 ok(result.end.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.end) );228 ok(result.end.get('month') == 9, 'Test Result - (Month) ' + JSON.stringify(result.end) );229 ok(result.end.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.end) );230 var resultDate = result.end.date();231 var expectDate = new Date(2013, 9-1, 12, 12);232 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)233 }234});235test("Test - Combined expression", function() {236 var text = "12th of July at 19:00";237 var results = chrono.parse(text, new Date(2012,7,10));238 ok(results.length == 1, JSON.stringify( results ) );239 var result = results[0];240 if(result){241 ok(result.index == 0, 'Wrong index');242 ok(result.text == '12th of July at 19:00', result.text );243 ok(result.start, JSON.stringify(result.start) );244 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );245 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result) );246 ok(result.start.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) );247 var resultDate = result.start.date();248 var expectDate = new Date(2012, 7-1, 12, 19, 0);249 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)250 }251 var text = "5 May 12:00";252 var results = chrono.parse(text, new Date(2012,7,10));253 ok(results.length == 1, JSON.stringify( results ) );254 var result = results[0];255 if(result){256 ok(result.index == 0, 'Wrong index');257 ok(result.text == '5 May 12:00', result.text );258 ok(result.start, JSON.stringify(result.start) );259 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );260 ok(result.start.get('month') == 5, 'Test Result - (Month) ' + JSON.stringify(result) );261 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) );262 var resultDate = result.start.date();263 var expectDate = new Date(2012, 5-1, 5, 12, 0);264 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)265 }266 var text = "7 May 11:00";267 var results = chrono.parse(text, new Date(2012,7,10));268 ok(results.length == 1, JSON.stringify( results ) );269 270 var result = results[0];271 if(result){272 ok(result.index == 0, 'Wrong index');273 ok(result.text == '7 May 11:00', result.text );274 ok(result.start, JSON.stringify(result.start) );275 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );276 ok(result.start.get('month') == 5, 'Test Result - (Month) ' + JSON.stringify(result) );277 ok(result.start.get('day') == 7, 'Test Result - (Day) ' + JSON.stringify(result.start) );278 ok(result.start.get('hour') == 11, 'Test Result - (Day) ' + JSON.stringify(result.start) );279 var resultDate = result.start.date();280 var expectDate = new Date(2012, 5-1, 7, 11, 0);281 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)282 }283});284test("Test - Impossible Dates (Strict Mode)", function() {285 286 var text = "32 August 2014";287 var results = chrono.strict.parse(text, new Date(2012,7,10));288 ok(results.length == 0, JSON.stringify( results ) );289 var text = "29 February 2014";290 var results = chrono.strict.parse(text, new Date(2012,7,10));291 ok(results.length == 0, JSON.stringify( results ));292 var text = "32 August";293 var results = chrono.strict.parse(text, new Date(2012,7,10));294 ok(results.length == 0, JSON.stringify( results ));295 var text = "29 February";296 var results = chrono.strict.parse(text, new Date(2013,7,10));297 ok(results.length == 0, JSON.stringify( results ))298});299test("Test - Impossible Dates (Casual Mode)", function() {300 301 var text = "32 August 2015";302 var expectDate = new Date(2015, 8, 1, 12, 0);303 var results = chrono.parse(text);304 var resultDate = results[0].start.date();305 ok(results.length == 1, JSON.stringify(results) );306 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 1000, resultDate +'/' +expectDate);...
test_en_casual.js
Source:test_en_casual.js
1test("Test - Single Expression", function() {2 var text = "The Deadline is now";3 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 8, 9, 10, 11));4 ok(results.length == 1, JSON.stringify( results ) );5 var result = results[0];6 if(result){7 ok(result.index == 16, 'Wrong index');8 ok(result.text == 'now', result.text );9 ok(result.start, JSON.stringify(result.start) );10 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );11 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );12 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );13 ok(result.start.get('hour') == 8, 'Test Result - (Hour) ' + JSON.stringify(result.start) );14 ok(result.start.get('minute') == 9, 'Test Result - (Minute) ' + JSON.stringify(result.start) );15 ok(result.start.get('second') == 10, 'Test Result - (Second) ' + JSON.stringify(result.start) );16 ok(result.start.get('millisecond') == 11, 'Test Result - (Millisecond) ' + JSON.stringify(result.start) );17 var resultDate = result.start.date();18 var expectDate = new Date(2012, 7, 10, 8, 9, 10, 11);19 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)20 }21 var text = "The Deadline is today";22 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));23 ok(results.length == 1, JSON.stringify( results ) );24 var result = results[0];25 if(result){26 ok(result.index == 16, 'Wrong index');27 ok(result.text == 'today', result.text );28 ok(result.start, JSON.stringify(result.start) );29 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );30 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );31 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );32 var resultDate = result.start.date();33 var expectDate = new Date(2012, 7, 10, 12);34 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)35 }36 var text = "The Deadline is Tomorrow";37 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));38 ok(results.length == 1, JSON.stringify( results ) );39 var result = results[0];40 if(result){41 ok(result.index == 16, 'Wrong index');42 ok(result.text == 'Tomorrow', result.text );43 ok(result.start, JSON.stringify(result.start) );44 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );45 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );46 ok(result.start.get('day') == 11, 'Test Result - (Day) ' + JSON.stringify(result.start) );47 var resultDate = result.start.date();48 var expectDate = new Date(2012, 7, 11, 12);49 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)50 }51 // Say.."Tomorrow" in the late night (1 AM)52 var text = "The Deadline is Tomorrow";53 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 1));54 ok(results.length == 1, JSON.stringify( results ) );55 var result = results[0];56 if(result){57 var resultDate = result.start.date();58 var expectDate = new Date(2012, 7, 10, 12);59 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)60 }61 var text = "The Deadline was yesterday";62 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));63 ok(results.length == 1, JSON.stringify( results ) );64 var result = results[0];65 if(result){66 ok(result.index == 17, 'Wrong index');67 ok(result.text == 'yesterday', result.text );68 ok(result.start, JSON.stringify(result.start) );69 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );70 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );71 ok(result.start.get('day') == 9, 'Test Result - (Day) ' + JSON.stringify(result.start) );72 var resultDate = result.start.date();73 var expectDate = new Date(2012, 7, 9, 12);74 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)75 }76 var text = "The Deadline was last night ";77 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));78 ok(results.length == 1, JSON.stringify( results ) );79 var result = results[0];80 if(result){81 ok(result.index == 17, 'Wrong index');82 ok(result.text == 'last night', result.text );83 ok(result.start, JSON.stringify(result.start) );84 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );85 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );86 ok(result.start.get('day') == 9, 'Test Result - (Day) ' + JSON.stringify(result.start) );87 ok(result.start.get('hour') == 0, 'Test Result - (hour) ' + JSON.stringify(result.start) );88 var resultDate = result.start.date();89 var expectDate = new Date(2012, 7, 9, 0);90 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)91 }92 var text = "The Deadline was this morning ";93 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));94 ok(results.length == 1, JSON.stringify( results ) );95 var result = results[0];96 if(result){97 ok(result.index == 17, 'Wrong index');98 ok(result.text == 'this morning', result.text );99 ok(result.start, JSON.stringify(result.start) );100 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );101 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );102 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );103 ok(result.start.get('hour') == 6, 'Test Result - (hour) ' + JSON.stringify(result.start) );104 var resultDate = result.start.date();105 var expectDate = new Date(2012, 7, 10, 6);106 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)107 }108 var text = "The Deadline was this afternoon ";109 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));110 ok(results.length == 1, JSON.stringify( results ) );111 var result = results[0];112 if(result){113 ok(result.index == 17, 'Wrong index');114 ok(result.text == 'this afternoon', result.text );115 ok(result.start, JSON.stringify(result.start) );116 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );117 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );118 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );119 ok(result.start.get('hour') == 15, 'Test Result - (hour) ' + JSON.stringify(result.start) );120 var resultDate = result.start.date();121 var expectDate = new Date(2012, 7, 10, 15);122 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)123 }124 var text = "The Deadline was this evening ";125 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));126 ok(results.length == 1, JSON.stringify( results ) );127 var result = results[0];128 if(result){129 ok(result.index == 17, 'Wrong index');130 ok(result.text == 'this evening', result.text );131 ok(result.start, JSON.stringify(result.start) );132 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );133 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );134 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );135 ok(result.start.get('hour') == 18, 'Test Result - (hour) ' + JSON.stringify(result.start) );136 var resultDate = result.start.date();137 var expectDate = new Date(2012, 7, 10, 18);138 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)139 }140});141test("Test - Combined Expression", function() {142 var text = "The Deadline is today 5PM";143 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));144 ok(results.length == 1, JSON.stringify( results ) );145 var result = results[0];146 if(result){147 ok(result.index == 16, 'Wrong index');148 ok(result.text == 'today 5PM', result.text );149 ok(result.start, JSON.stringify(result.start) );150 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );151 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );152 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );153 ok(result.start.get('hour') == 17, 'Test Result - (Day) ' + JSON.stringify(result.start) );154 var resultDate = result.start.date();155 var expectDate = new Date(2012, 7, 10, 17);156 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)157 }158});159test("Test - Casual date range", function() {160 var text = "The event is today - next friday";161 var results = chrono.casual.parse(text, new Date(2012, 7, 4, 12));162 ok(results.length == 1, JSON.stringify( results ) );163 var result = results[0];164 if(result){165 ok(result.index == 13, 'Wrong index');166 ok(result.text == 'today - next friday', result.text );167 ok(result.start, JSON.stringify(result.start) );168 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );169 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );170 ok(result.start.get('day') == 4, 'Test Result - (Day) ' + JSON.stringify(result.start) );171 ok(result.start.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) );172 var resultDate = result.start.date();173 var expectDate = new Date(2012, 7, 4, 12);174 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)175 ok(result.end, JSON.stringify(result.start) );176 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );177 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );178 ok(result.end.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );179 ok(result.end.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) );180 var resultDate = result.end.date();181 var expectDate = new Date(2012, 7, 10, 12);182 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)183 }184 var text = "The event is today - next friday";185 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));186 ok(results.length == 1, JSON.stringify( results ) );187 var result = results[0];188 if(result){189 ok(result.index == 13, 'Wrong index');190 ok(result.text == 'today - next friday', result.text );191 ok(result.start, JSON.stringify(result.start) );192 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );193 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );194 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );195 ok(result.start.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) );196 var resultDate = result.start.date();197 var expectDate = new Date(2012, 7, 10, 12);198 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)199 ok(result.end, JSON.stringify(result.start) );200 ok(result.end.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );201 ok(result.end.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );202 ok(result.end.get('day') == 17, 'Test Result - (Day) ' + JSON.stringify(result.start) );203 ok(result.end.get('hour') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) );204 var resultDate = result.end.date();205 var expectDate = new Date(2012, 7, 17, 12);206 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)207 }208});209test('Test - Random text', function() {210 var text = "tonight";211 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];212 ok(result.text == text, result.text);213 ok(result.start.get('year') == 2012, JSON.stringify(result.start));214 ok(result.start.get('month') == 1, JSON.stringify(result.start));215 ok(result.start.get('day') == 1, JSON.stringify(result.start));216 ok(result.start.get('hour') == 22, JSON.stringify(result.start));217 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start));218 var text = "tonight 8pm";219 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];220 ok(result.text == text, result.text);221 ok(result.start.get('hour') == 20, JSON.stringify(result.start));222 ok(result.start.get('year') == 2012, JSON.stringify(result.start));223 ok(result.start.get('month') == 1, JSON.stringify(result.start));224 ok(result.start.get('day') == 1, JSON.stringify(result.start));225 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start));226 var text = "tonight at 8";227 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];228 ok(result.text == text, result.text);229 ok(result.start.get('hour') == 20, JSON.stringify(result.start));230 ok(result.start.get('year') == 2012, JSON.stringify(result.start));231 ok(result.start.get('month') == 1, JSON.stringify(result.start));232 ok(result.start.get('day') == 1, JSON.stringify(result.start));233 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start));234 var text = "thurs";235 var result = chrono.parse(text)[0];236 ok(result.text == text, result.text);237 ok(result.start.get('weekday') == 4, result.text);238 var text = "thurs";239 var result = chrono.parse(text)[0];240 ok(result.text == text, result.text);241 ok(result.start.get('weekday') == 4, result.text)242});243test('Test - Random negative text', function() {244 var text = "notoday";245 var results = chrono.parse(text);246 ok(results.length == 0, JSON.stringify(results) );247 var text = "tdtmr";248 var results = chrono.parse(text);249 ok(results.length == 0, JSON.stringify(results) );250 var text = "xyesterday";251 var results = chrono.parse(text);252 ok(results.length == 0, JSON.stringify(results) );253 var text = "nowhere";254 var results = chrono.parse(text);255 ok(results.length == 0, JSON.stringify(results) );256 var text = "noway";257 var results = chrono.parse(text);258 ok(results.length == 0, JSON.stringify(results) );259 var text = "knowledge";260 var results = chrono.parse(text);261 ok(results.length == 0, JSON.stringify(results) )...
test_en_time_ago.js
Source:test_en_time_ago.js
1test("Test - Single Expression", function() {2 var text = "5 days ago, we did something";3 var results = chrono.parse(text, new Date(2012,7,10));4 ok(results.length == 1, JSON.stringify( results ) );5 var result = results[0];6 if(result){7 ok(result.start, JSON.stringify(result.start) );8 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );9 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );10 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) );11 ok(result.index == 0, 'Wrong index');12 ok(result.text == '5 days ago', result.text );13 var resultDate = result.start.date();14 var expectDate = new Date(2012, 8-1, 5, 12);15 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)16 }17 var text = "10 days ago, we did something";18 var results = chrono.parse(text, new Date(2012,7,10));19 ok(results.length == 1, JSON.stringify( results ) );20 var result = results[0];21 if(result){22 ok(result.start, JSON.stringify(result.start) );23 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );24 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result.start) );25 ok(result.start.get('day') == 31, 'Test Result - (Day) ' + JSON.stringify(result.start) );26 ok(result.index == 0, 'Wrong index');27 ok(result.text == '10 days ago', result.text );28 var resultDate = result.start.date();29 var expectDate = new Date(2012, 7-1, 31, 12);30 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)31 }32 var text = "15 minute ago";33 var results = chrono.parse(text, new Date(2012,7,10,12,14));34 ok(results.length == 1, JSON.stringify( results ) );35 var result = results[0];36 if(result){37 ok(result.index == 0, 'Wrong index');38 ok(result.text == '15 minute ago', result.text );39 ok(result.start.get('hour') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) );40 ok(result.start.get('minute') == 59, 'Test Result - (Day) ' + JSON.stringify(result.start) );41 var resultDate = result.start.date();42 var expectDate = new Date(2012,7,10,11,59);43 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)44 }45 var text = "15 minute earlier";46 var results = chrono.parse(text, new Date(2012,7,10,12,14));47 ok(results.length == 1, JSON.stringify( results ) );48 var result = results[0];49 if(result){50 ok(result.index == 0, 'Wrong index');51 ok(result.text == '15 minute earlier', result.text );52 ok(result.start.get('hour') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) );53 ok(result.start.get('minute') == 59, 'Test Result - (Day) ' + JSON.stringify(result.start) );54 var resultDate = result.start.date();55 var expectDate = new Date(2012,7,10,11,59);56 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)57 }58 var text = "15 minute before";59 var results = chrono.parse(text, new Date(2012,7,10,12,14));60 ok(results.length == 1, JSON.stringify( results ) );61 var result = results[0];62 if(result){63 ok(result.index == 0, 'Wrong index');64 ok(result.text == '15 minute before', result.text );65 ok(result.start.get('hour') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) );66 ok(result.start.get('minute') == 59, 'Test Result - (Day) ' + JSON.stringify(result.start) );67 var resultDate = result.start.date();68 var expectDate = new Date(2012,7,10,11,59);69 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)70 }71 var text = " 12 hours ago";72 var results = chrono.parse(text, new Date(2012,7,10,12,14));73 ok(results.length == 1, JSON.stringify( results ) );74 var result = results[0];75 if(result){76 ok(result.index == 3, 'Wrong index');77 ok(result.text == '12 hours ago', result.text );78 ok(result.start.get('hour') == 0, 'Test Result - (Month) ' + JSON.stringify(result.start) );79 ok(result.start.get('minute') == 14, 'Test Result - (Day) ' + JSON.stringify(result.start) );80 var resultDate = result.start.date();81 var expectDate = new Date(2012,7,10,0,14);82 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)83 }84 var text = " half an hour ago";85 var results = chrono.parse(text, new Date(2012,7,10,12,14));86 ok(results.length == 1, JSON.stringify( results ) );87 var result = results[0];88 if(result){89 ok(result.index == 3, 'Wrong index');90 ok(result.text == 'half an hour ago', result.text );91 ok(result.start.get('hour') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) );92 ok(result.start.get('minute') == 44, 'Test Result - (Day) ' + JSON.stringify(result.start) );93 var resultDate = result.start.date();94 var expectDate = new Date(2012,7,10,11,44);95 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)96 }97 var text = "12 hours ago I did something";98 var results = chrono.parse(text, new Date(2012,7,10,12,14));99 ok(results.length == 1, JSON.stringify( results ) );100 var result = results[0];101 if(result){102 ok(result.index == 0, 'Wrong index');103 ok(result.text == '12 hours ago', result.text );104 ok(result.start.get('hour') == 0, 'Test Result - (Month) ' + JSON.stringify(result.start) );105 ok(result.start.get('minute') == 14, 'Test Result - (Day) ' + JSON.stringify(result.start) );106 var resultDate = result.start.date();107 var expectDate = new Date(2012,7,10,0,14);108 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)109 }110 var text = "12 seconds ago I did something";111 var results = chrono.parse(text, new Date(2012, 7, 10, 12, 14));112 ok(results.length == 1, JSON.stringify( results ) );113 var result = results[0];114 if(result){115 ok(result.index == 0, 'Wrong index');116 ok(result.text == '12 seconds ago', result.text );117 ok(result.start.get('hour') == 12, 'Test Result - (Month) ' + JSON.stringify(result.start) );118 ok(result.start.get('minute') == 13, 'Test Result - (Day) ' + JSON.stringify(result.start) );119 ok(result.start.get('second') == 48, 'Test Result - (Day) ' + JSON.stringify(result.start) );120 var resultDate = result.start.date();121 var expectDate = new Date(2012, 7, 10, 12, 13, 48);122 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)123 }124 var text = "three seconds ago I did something";125 var results = chrono.parse(text, new Date(2012, 7, 10, 12, 14));126 ok(results.length == 1, JSON.stringify( results ) );127 var result = results[0];128 if(result){129 ok(result.index == 0, 'Wrong index');130 ok(result.text == 'three seconds ago', result.text );131 ok(result.start.get('hour') == 12, 'Test Result - (Month) ' + JSON.stringify(result.start) );132 ok(result.start.get('minute') == 13, 'Test Result - (Day) ' + JSON.stringify(result.start) );133 ok(result.start.get('second') == 57, 'Test Result - (Day) ' + JSON.stringify(result.start) );134 var resultDate = result.start.date();135 var expectDate = new Date(2012, 7, 10, 12, 13, 57);136 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)137 }138});139test("Test - Single Expression (Casual)", function() {140 var text = "5 months ago, we did something";141 var results = chrono.parse(text, new Date(2012, 8-1,10));142 ok(results.length == 1, JSON.stringify( results ) );143 var result = results[0];144 if(result){145 ok(result.start, JSON.stringify(result.start) );146 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );147 ok(result.start.get('month') == 3, 'Test Result - (Month) ' + JSON.stringify(result.start) );148 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );149 ok(result.index == 0, 'Wrong index');150 ok(result.text == '5 months ago', result.text );151 var resultDate = result.start.date();152 var expectDate = new Date(2012, 3-1, 10, 12);153 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)154 }155 var text = "5 years ago, we did something";156 var results = chrono.parse(text, new Date(2012, 8-1,10));157 ok(results.length == 1, JSON.stringify( results ) );158 var result = results[0];159 if(result){160 ok(result.start, JSON.stringify(result.start) );161 ok(result.start.get('year') == 2007, 'Test Result - (Year) ' + JSON.stringify(result.start) );162 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) );163 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) );164 ok(result.index == 0, 'Wrong index');165 ok(result.text == '5 years ago', result.text );166 var resultDate = result.start.date();167 var expectDate = new Date(2007, 8-1, 10, 12);168 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)169 }170 var text = "a week ago, we did something";171 var results = chrono.parse(text, new Date(2012, 8-1, 3));172 ok(results.length == 1, JSON.stringify( results ) );173 var result = results[0];174 if(result){175 ok(result.start, JSON.stringify(result.start) );176 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );177 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result.start) );178 ok(result.start.get('day') == 27, 'Test Result - (Day) ' + JSON.stringify(result.start) );179 ok(result.index == 0, 'Wrong index');180 ok(result.text == 'a week ago', result.text );181 var resultDate = result.start.date();182 var expectDate = new Date(2012, 7-1, 27, 12);183 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)184 }185 var text = "a few days ago, we did something";186 var results = chrono.parse(text, new Date(2012, 8-1, 3));187 ok(results.length == 1, JSON.stringify( results ) );188 var result = results[0];189 if(result){190 ok(result.start, JSON.stringify(result.start) );191 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) );192 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result.start) );193 ok(result.start.get('day') == 31, 'Test Result - (Day) ' + JSON.stringify(result.start) );194 ok(result.index == 0, 'Wrong index');195 ok(result.text == 'a few days ago', result.text );196 var resultDate = result.start.date();197 var expectDate = new Date(2012, 7-1, 31, 12);198 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)199 }200});201test("Test - Single Expression (Strict)", function() {202 var text = "15 minute before";203 var results = chrono.strict.parse(text, new Date(2012,7,10,12,14));204 ok(results.length == 0, JSON.stringify( results ) );205 var text = "a week ago, we did something";206 var results = chrono.strict.parse(text, new Date(2012, 8-1, 3));207 ok(results.length == 0, JSON.stringify( results ) )...
test_es_casual.js
Source:test_es_casual.js
1test("Test - Single Expression", function() {2 var text = "La fecha lÃmite es ahora";3 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 8, 9, 10, 11));4 ok(results.length == 1, JSON.stringify( results ) )5 var result = results[0];6 if(result){7 ok(result.index == 19, 'Wrong index')8 ok(result.text == 'ahora', result.text )9 ok(result.start, JSON.stringify(result.start) )10 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )11 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )12 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )13 ok(result.start.get('hour') == 8, 'Test Result - (Hour) ' + JSON.stringify(result.start) )14 ok(result.start.get('minute') == 9, 'Test Result - (Minute) ' + JSON.stringify(result.start) )15 ok(result.start.get('second') == 10, 'Test Result - (Second) ' + JSON.stringify(result.start) )16 ok(result.start.get('millisecond') == 11, 'Test Result - (Millisecond) ' + JSON.stringify(result.start) )17 var resultDate = result.start.date();18 var expectDate = new Date(2012, 7, 10, 8, 9, 10, 11);19 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)20 }21 var text = "La fecha lÃmite es hoy";22 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));23 ok(results.length == 1, JSON.stringify( results ) )24 var result = results[0];25 if(result){26 ok(result.index == 19, 'Wrong index')27 ok(result.text == 'hoy', result.text )28 ok(result.start, JSON.stringify(result.start) )29 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )30 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )31 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )32 var resultDate = result.start.date();33 var expectDate = new Date(2012, 7, 10, 12);34 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)35 }36 var text = "La fecha lÃmite es Mañana";37 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));38 ok(results.length == 1, JSON.stringify( results ) )39 var result = results[0];40 if(result){41 ok(result.index == 19, 'Wrong index')42 ok(result.text == 'Mañana', result.text )43 ok(result.start, JSON.stringify(result.start) )44 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )45 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )46 ok(result.start.get('day') == 11, 'Test Result - (Day) ' + JSON.stringify(result.start) )47 var resultDate = result.start.date();48 var expectDate = new Date(2012, 7, 11, 12);49 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)50 }51 // Say.."Tomorrow" in the late night (1 AM)52 var text = "La fecha lÃmite es Tomorrow";53 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 1));54 ok(results.length == 1, JSON.stringify( results ) )55 var result = results[0];56 if(result){57 var resultDate = result.start.date();58 var expectDate = new Date(2012, 7, 10, 12);59 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)60 }61 var text = "La fecha lÃmite fue ayer";62 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));63 ok(results.length == 1, JSON.stringify( results ) )64 var result = results[0];65 if(result){66 ok(result.index == 20, 'Wrong index')67 ok(result.text == 'ayer', result.text )68 ok(result.start, JSON.stringify(result.start) )69 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )70 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )71 ok(result.start.get('day') == 9, 'Test Result - (Day) ' + JSON.stringify(result.start) )72 var resultDate = result.start.date();73 var expectDate = new Date(2012, 7, 9, 12);74 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)75 }76 var text = "La fehca lÃmite fue anoche ";77 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));78 ok(results.length == 1, JSON.stringify( results ) )79 var result = results[0];80 if(result){81 ok(result.index == 20, 'Wrong index')82 ok(result.text == 'anoche', result.text )83 ok(result.start, JSON.stringify(result.start) )84 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )85 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )86 ok(result.start.get('day') == 9, 'Test Result - (Day) ' + JSON.stringify(result.start) )87 ok(result.start.get('hour') == 0, 'Test Result - (hour) ' + JSON.stringify(result.start) )88 var resultDate = result.start.date();89 var expectDate = new Date(2012, 7, 9, 0);90 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)91 }92 var text = "La fecha lÃmite fue esta mañana ";93 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));94 ok(results.length == 1, JSON.stringify( results ) )95 var result = results[0];96 if(result){97 ok(result.index == 20, 'Wrong index')98 ok(result.text == 'esta mañana', result.text )99 ok(result.start, JSON.stringify(result.start) )100 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )101 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )102 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )103 ok(result.start.get('hour') == 6, 'Test Result - (hour) ' + JSON.stringify(result.start) )104 var resultDate = result.start.date();105 var expectDate = new Date(2012, 7, 10, 6);106 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)107 }108 var text = "La fecha lÃmite fue esta tarde ";109 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));110 ok(results.length == 1, JSON.stringify( results ) )111 var result = results[0];112 if(result){113 ok(result.index == 20, 'Wrong index')114 ok(result.text == 'esta tarde', result.text )115 ok(result.start, JSON.stringify(result.start) )116 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )117 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )118 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )119 ok(result.start.get('hour') == 18, 'Test Result - (hour) ' + JSON.stringify(result.start) )120 var resultDate = result.start.date();121 var expectDate = new Date(2012, 7, 10, 18);122 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)123 }124});125test("Test - Combined Expression", function() {126 var text = "La fecha lÃmite es hoy 5PM";127 var results = chrono.casual.parse(text, new Date(2012, 7, 10, 12));128 ok(results.length == 1, JSON.stringify( results ) )129 var result = results[0];130 if(result){131 ok(result.index == 19, 'Wrong index')132 ok(result.text == 'hoy 5PM', result.text )133 ok(result.start, JSON.stringify(result.start) )134 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )135 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )136 ok(result.start.get('day') == 10, 'Test Result - (Day) ' + JSON.stringify(result.start) )137 ok(result.start.get('hour') == 17, 'Test Result - (Day) ' + JSON.stringify(result.start) )138 var resultDate = result.start.date();139 var expectDate = new Date(2012, 7, 10, 17);140 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)141 }142});143test('Test - Random text', function() {144 var text = "esta noche";145 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];146 ok(result.text == text, result.text)147 ok(result.start.get('year') == 2012, JSON.stringify(result.start))148 ok(result.start.get('month') == 1, JSON.stringify(result.start))149 ok(result.start.get('day') == 1, JSON.stringify(result.start))150 ok(result.start.get('hour') == 22, JSON.stringify(result.start))151 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start))152 var text = "esta noche 8pm";153 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];154 ok(result.text == text, result.text)155 ok(result.start.get('hour') == 20, JSON.stringify(result.start))156 ok(result.start.get('year') == 2012, JSON.stringify(result.start))157 ok(result.start.get('month') == 1, JSON.stringify(result.start))158 ok(result.start.get('day') == 1, JSON.stringify(result.start))159 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start))160 var text = "esta noche at 8"; // TODO161 var result = chrono.parse(text, new Date(2012, 1-1, 1, 12))[0];162 ok(result.text == text, result.text)163 ok(result.start.get('hour') == 20, JSON.stringify(result.start))164 ok(result.start.get('year') == 2012, JSON.stringify(result.start))165 ok(result.start.get('month') == 1, JSON.stringify(result.start))166 ok(result.start.get('day') == 1, JSON.stringify(result.start))167 ok(result.start.get('meridiem') == 1, JSON.stringify(result.start))168 var text = "jueves";169 var result = chrono.parse(text)[0];170 ok(result.text == text, result.text)171 ok(result.start.get('weekday') == 4, result.text)172 var text = "viernes";173 var result = chrono.parse(text)[0];174 ok(result.text == text, result.text)175 ok(result.start.get('weekday') == 5, result.text)176})177test('Test - Random negative text', function() {178 var text = "nohoy";179 var results = chrono.parse(text);180 ok(results.length == 0, JSON.stringify(results) )181 var text = "hymañana";182 var results = chrono.parse(text);183 ok(results.length == 0, JSON.stringify(results) )184 var text = "xayer";185 var results = chrono.parse(text);186 ok(results.length == 0, JSON.stringify(results) )187 var text = "porahora";188 var results = chrono.parse(text);189 ok(results.length == 0, JSON.stringify(results) )190 var text = "ahoraxsd";191 var results = chrono.parse(text);192 ok(results.length == 0, JSON.stringify(results) )...
test_en_inter_std.js
Source:test_en_inter_std.js
1test("Test - Single Expression", function() {2 var text = "Let's finish this before this 2013-2-7.";3 var results = chrono.parse(text, new Date(2012,7,8));4 ok(results.length == 1, JSON.stringify( results ) )5 var result = results[0];6 if(result){7 ok(result.start, JSON.stringify(result.start) )8 ok(result.start.get('year') == 2013, 'Test Result - (Year) ' + JSON.stringify(result.start) )9 ok(result.start.get('month') == 2, 'Test Result - (Month) ' + JSON.stringify(result.start) )10 ok(result.start.get('day') == 7, 'Test Result - (Day) ' + JSON.stringify(result.start) )11 var resultDate = (result.start.date());12 var expectDate = (new Date(2013,1,7,12));13 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)14 }15 var text = "1994-11-05T08:15:30-05:30";16 var results = chrono.parse(text, new Date(2012,7,8));17 ok(results.length == 1, JSON.stringify( results ) )18 var result = results[0];19 if(result){20 ok(result.start, JSON.stringify(result.start) )21 ok(result.start.get('year') == 1994, 'Test Result - (Year) ' + JSON.stringify(result.start) )22 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )23 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) )24 ok(result.start.get('hour') == 8, 'Test Result - (Hour) ' + JSON.stringify(result.start) )25 ok(result.start.get('minute') == 15, 'Test Result - (Minute) ' + JSON.stringify(result.start) )26 ok(result.start.get('second') == 30, 'Test Result - (Second) ' + JSON.stringify(result.start) )27 ok(result.start.get('timezoneOffset') == -330, 'Test Result - (Second) ' + JSON.stringify(result.start) )28 ok(result.text == text, result.text)29 30 var resultDate = result.start.date();31 var expectDate = new Date(784043130000);32 33 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)34 } 35 var text = "1994-11-05T13:15:30";36 var results = chrono.parse(text, new Date(2012,7,8));37 ok(results.length == 1, JSON.stringify( results ) )38 var result = results[0];39 if(result){40 ok(result.start, JSON.stringify(result.start) )41 ok(result.start.get('year') == 1994, 'Test Result - (Year) ' + JSON.stringify(result.start) )42 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )43 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) )44 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )45 ok(result.start.get('minute') == 15, 'Test Result - (Minute) ' + JSON.stringify(result.start) )46 ok(result.start.get('second') == 30, 'Test Result - (Second) ' + JSON.stringify(result.start) )47 ok(result.start.get('timezoneOffset') == 0, 'Test Result - (Timezone) ' + JSON.stringify(result.start) )48 ok(result.text == text, result.text)49 50 var resultDate = result.start.date();51 var expectDate = new Date(784041330000);52 53 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)54 } 55 var text = "2015-07-31T12:00:00";56 var results = chrono.parse(text, new Date(2012,7,8));57 ok(results.length == 1, JSON.stringify( results ) )58 59 var result = results[0];60 if(result){61 ok(result.start, JSON.stringify(result.start) )62 ok(result.start.get('year') == 2015, 'Test Result - (Year) ' + JSON.stringify(result.start) )63 ok(result.start.get('month') == 7, 'Test Result - (Month) ' + JSON.stringify(result.start) )64 ok(result.start.get('day') == 31, 'Test Result - (Day) ' + JSON.stringify(result.start) )65 ok(result.start.get('hour') == 12, 'Test Result - (Hour) ' + JSON.stringify(result.start) )66 ok(result.start.get('minute') == 0, 'Test Result - (Minute) ' + JSON.stringify(result.start) )67 ok(result.start.get('second') == 0, 'Test Result - (Second) ' + JSON.stringify(result.start) )68 ok(result.start.get('timezoneOffset') == 0, 'Test Result - (Timezone) ' + JSON.stringify(result.start) )69 ok(result.text == text, result.text)70 71 var resultDate = result.start.date();72 var expectDate = new Date(1438344000000);73 74 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)75 } 76 var text = "1994-11-05T13:15:30Z";77 var results = chrono.parse(text, new Date(2012,7,8));78 ok(results.length == 1, JSON.stringify( results ) )79 var result = results[0];80 if(result){81 ok(result.start, JSON.stringify(result.start) )82 ok(result.start.get('year') == 1994, 'Test Result - (Year) ' + JSON.stringify(result.start) )83 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )84 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) )85 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )86 ok(result.start.get('minute') == 15, 'Test Result - (Minute) ' + JSON.stringify(result.start) )87 ok(result.start.get('second') == 30, 'Test Result - (Second) ' + JSON.stringify(result.start) )88 ok(result.start.get('timezoneOffset') == 0, 'Test Result - (Second) ' + JSON.stringify(result.start) )89 ok(result.text == text, result.text)90 91 var resultDate = result.start.date();92 var expectDate = new Date(784041330000);93 94 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)95 } 96 var text = "1994-11-05T13:15:30Z";97 var results = chrono.parse(text, new Date(2012,7,8));98 ok(results.length == 1, JSON.stringify( results ) )99 var result = results[0];100 if(result){101 ok(result.start, JSON.stringify(result.start) )102 ok(result.start.get('year') == 1994, 'Test Result - (Year) ' + JSON.stringify(result.start) )103 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )104 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) )105 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )106 ok(result.start.get('minute') == 15, 'Test Result - (Minute) ' + JSON.stringify(result.start) )107 ok(result.start.get('second') == 30, 'Test Result - (Second) ' + JSON.stringify(result.start) )108 ok(result.start.get('timezoneOffset') == 0, 'Test Result - (Second) ' + JSON.stringify(result.start) )109 ok(result.text == text, result.text)110 111 var resultDate = result.start.date();112 var expectDate = new Date(784041330000);113 114 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)115 }116 var text = "- 1994-11-05T13:15:30Z";117 var results = chrono.parse(text, new Date(2012,7,8));118 ok(results.length == 1, JSON.stringify( results ) )119 var result = results[0];120 if(result){121 ok(result.start, JSON.stringify(result.start) )122 ok(result.start.get('year') == 1994, 'Test Result - (Year) ' + JSON.stringify(result.start) )123 ok(result.start.get('month') == 11, 'Test Result - (Month) ' + JSON.stringify(result.start) )124 ok(result.start.get('day') == 5, 'Test Result - (Day) ' + JSON.stringify(result.start) )125 ok(result.start.get('hour') == 13, 'Test Result - (Hour) ' + JSON.stringify(result.start) )126 ok(result.start.get('minute') == 15, 'Test Result - (Minute) ' + JSON.stringify(result.start) )127 ok(result.start.get('second') == 30, 'Test Result - (Second) ' + JSON.stringify(result.start) )128 ok(result.start.get('timezoneOffset') == 0, 'Test Result - (Second) ' + JSON.stringify(result.start) )129 ok(result.index == 2, result.index)130 ok(result.text == '1994-11-05T13:15:30Z', result.text)131 132 var resultDate = result.start.date();133 var expectDate = new Date(784041330000);134 135 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.start.date() ' + resultDate +'/' +expectDate)136 }137});138test("Test - Compare with native js", function() {139 var text = '1994-11-05T13:15:30Z';140 var result = chrono.parse(text)[0];141 var expect = new Date(text);142 ok(result.text == text);143 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)144 var text = '1994-02-28T08:15:30-05:30';145 var result = chrono.parse(text)[0];146 var expect = new Date(text);147 ok(result.text == text);148 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)149 var text = '1994-11-05T08:15:30-05:30';150 var result = chrono.parse(text)[0];151 var expect = new Date(text);152 ok(result.text == text);153 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)154 var text = '1994-11-05T08:15:30+11:30';155 var result = chrono.parse(text)[0];156 var expect = new Date(text);157 ok(result.text == text);158 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)159 var text = '2014-11-30T08:15:30-05:30';160 var result = chrono.parse(text)[0];161 var expect = new Date(text);162 ok(result.text == text);163 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)164 var text = 'Sat, 21 Feb 2015 11:50:48 -0500';165 var result = chrono.parse(text)[0];166 var expect = new Date(text);167 ok(result.text == text);168 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)169 var text = '22 Feb 2015 04:12:00 -0000';170 var result = chrono.parse(text)[0];171 var expect = new Date(text);172 ok(result.text == text);173 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)174 var text = '0000-01-01T00:00:00-00:00';175 var result = chrono.parse(text)[0];176 var expect = new Date(text);177 ok(result.text == text);178 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)179 var text = '9999-12-31T23:59:00-00:00';180 var result = chrono.parse(text)[0];181 var expect = new Date(text);182 183 ok(result.text == text);184 ok(Math.abs(expect.getTime() - result.start.date().getTime()) <= 1000)...
test_en_weekday.js
Source:test_en_weekday.js
1test("Test - Single Expression", function() {2 var text = "Monday";3 var results = chrono.casual.parse(text, new Date(2012,7,9));4 ok(results.length == 1, JSON.stringify( results ) )5 var result = results[0];6 if(result){7 ok(result.index == 0, 'Wrong index')8 ok(result.text == 'Monday', result.text )9 ok(result.start, JSON.stringify(result.start) )10 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )11 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )12 ok(result.start.get('day') == 6, 'Test Result - (Day) ' + JSON.stringify(result.start) )13 ok(result.start.get('weekday') == 1, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )14 ok(!result.start.isCertain('day'))15 ok(!result.start.isCertain('month'))16 ok(!result.start.isCertain('year'))17 ok(result.start.isCertain('weekday'))18 var resultDate = result.start.date();19 var expectDate = new Date(2012, 7, 6, 12);20 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)21 }22 var text = "Monday (forward dates only)";23 var results = chrono.casual.parse(text, new Date(2012,7,9), {forwardDatesOnly: true});24 ok(results.length == 1, JSON.stringify( results ) )25 var result = results[0];26 if(result){27 ok(result.index == 0, 'Wrong index')28 ok(result.text == 'Monday', result.text )29 ok(result.start, JSON.stringify(result.start) )30 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )31 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )32 ok(result.start.get('day') == 13, 'Test Result - (Day) ' + JSON.stringify(result.start) )33 ok(result.start.get('weekday') == 1, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )34 ok(!result.start.isCertain('day'))35 ok(!result.start.isCertain('month'))36 ok(!result.start.isCertain('year'))37 ok(result.start.isCertain('weekday'))38 var resultDate = result.start.date();39 var expectDate = new Date(2012, 7, 13, 12);40 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)41 }42 var text = "Thursday";43 var results = chrono.casual.parse(text, new Date(2012,7,9));44 ok(results.length == 1, JSON.stringify( results ) )45 var result = results[0];46 if(result){47 ok(result.index == 0, 'Wrong index')48 ok(result.text == 'Thursday', result.text )49 ok(result.start, JSON.stringify(result.start) )50 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )51 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )52 ok(result.start.get('day') == 9, 'Test Result - (Day) ' + JSON.stringify(result.start) )53 ok(result.start.get('weekday') == 4, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )54 var resultDate = result.start.date();55 var expectDate = new Date(2012, 7, 9, 12);56 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)57 }58 var text = "Sunday";59 var results = chrono.casual.parse(text, new Date(2012,7,9));60 ok(results.length == 1, JSON.stringify( results ) )61 var result = results[0];62 if(result){63 ok(result.index == 0, 'Wrong index')64 ok(result.text == 'Sunday', result.text )65 ok(result.start, JSON.stringify(result.start) )66 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )67 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )68 ok(result.start.get('day') == 12, 'Test Result - (Day) ' + JSON.stringify(result.start) )69 ok(result.start.get('weekday') == 0, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )70 var resultDate = result.start.date();71 var expectDate = new Date(2012, 7, 12, 12);72 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)73 }74 var text = "The Deadline is last Friday...";75 var results = chrono.casual.parse(text, new Date(2012,7,9));76 ok(results.length == 1, JSON.stringify( results ) )77 var result = results[0];78 if(result){79 ok(result.index == 16, 'Wrong index')80 ok(result.text == 'last Friday', result.text )81 ok(result.start, JSON.stringify(result.start) )82 ok(result.start.get('year') == 2012, 'Test Result - (Year) ' + JSON.stringify(result.start) )83 ok(result.start.get('month') == 8, 'Test Result - (Month) ' + JSON.stringify(result.start) )84 ok(result.start.get('day') == 3, 'Test Result - (Day) ' + JSON.stringify(result.start) )85 ok(result.start.get('weekday') == 5, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )86 var resultDate = result.start.date();87 var expectDate = new Date(2012, 7, 3, 12);88 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)89 }90 var text = "Let's have a meeting on Friday next week";91 var results = chrono.casual.parse(text, new Date(2015, 3, 18));92 ok(results.length == 1, JSON.stringify( results ) )93 var result = results[0];94 if(result){95 ok(result.index == 24, 'Wrong index')96 ok(result.text == 'Friday next week', result.text )97 ok(result.start, JSON.stringify(result.start) )98 ok(result.start.get('year') == 2015, 'Test Result - (Year) ' + JSON.stringify(result.start) )99 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )100 ok(result.start.get('day') == 24, 'Test Result - (Day) ' + JSON.stringify(result.start) )101 ok(result.start.get('weekday') == 5, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )102 var resultDate = result.start.date();103 var expectDate = new Date(2015, 3, 24, 12);104 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)105 }106 var text = "I plan on taking the day off on Tuesday, next week";107 var results = chrono.casual.parse(text, new Date(2015, 3, 18));108 ok(results.length == 1, JSON.stringify( results ) )109 var result = results[0];110 if(result){111 ok(result.index == 32, 'Wrong index')112 ok(result.text == 'Tuesday, next week', result.text )113 ok(result.start, JSON.stringify(result.start) )114 ok(result.start.get('year') == 2015, 'Test Result - (Year) ' + JSON.stringify(result.start) )115 ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) )116 ok(result.start.get('day') == 21, 'Test Result - (Day) ' + JSON.stringify(result.start) )117 ok(result.start.get('weekday') == 2, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )118 var resultDate = result.start.date();119 var expectDate = new Date(2015, 3, 21, 12);120 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)121 }122});123test("Test - Weekday Overlap", function() {124 var text = "Sunday, December 7, 2014";125 var results = chrono.casual.parse(text, new Date(2012,7,9));126 ok(results.length == 1, JSON.stringify( results ) )127 var result = results[0];128 if(result){129 ok(result.index == 0, 'Wrong index')130 ok(result.text == 'Sunday, December 7, 2014', result.text )131 ok(result.start, JSON.stringify(result.start) )132 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )133 ok(result.start.get('month') == 12, 'Test Result - (Month) ' + JSON.stringify(result.start) )134 ok(result.start.get('day') == 7, 'Test Result - (Day) ' + JSON.stringify(result.start) )135 ok(result.start.get('weekday') == 0, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )136 ok(result.start.isCertain('day'))137 ok(result.start.isCertain('month'))138 ok(result.start.isCertain('year'))139 ok(result.start.isCertain('weekday'))140 var resultDate = result.start.date();141 var expectDate = new Date(2014, 12-1, 7, 12);142 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)143 }144 var text = "Sunday 12/7/2014";145 var results = chrono.casual.parse(text, new Date(2012,7,9));146 ok(results.length == 1, JSON.stringify( results ) )147 var result = results[0];148 if(result){149 ok(result.index == 0, 'Wrong index')150 ok(result.text == 'Sunday 12/7/2014', result.text )151 ok(result.start, JSON.stringify(result.start) )152 ok(result.start.get('year') == 2014, 'Test Result - (Year) ' + JSON.stringify(result.start) )153 ok(result.start.get('month') == 12, 'Test Result - (Month) ' + JSON.stringify(result.start) )154 ok(result.start.get('day') == 7, 'Test Result - (Day) ' + JSON.stringify(result.start) )155 ok(result.start.get('weekday') == 0, 'Test Result - (Weekday) ' + JSON.stringify(result.start) )156 ok(result.start.isCertain('day'))157 ok(result.start.isCertain('month'))158 ok(result.start.isCertain('year'))159 ok(result.start.isCertain('weekday'))160 var resultDate = result.start.date();161 var expectDate = new Date(2014, 12-1, 7, 12);162 ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate)163 }...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .pause(10000)9 .startPerformanceRecord({profileName: 'myProfile'})10 .pause(20000)11 .stopPerformanceRecord({profileName: 'myProfile'})12 .end();13var webdriverio = require('webdriverio');14var options = {15 desiredCapabilities: {16 }17};18var client = webdriverio.remote(options);19 .init()20 .pause(10000)21 .startPerformanceRecord({profileName: 'myProfile'})22 .pause(20000)23 .stopPerformanceRecord({profileName: 'myProfile'})24 .end();25var webdriverio = require('webdriverio');26var options = {27 desiredCapabilities: {28 }29};30var client = webdriverio.remote(options);31 .init()32 .pause(10000)33 .startPerformanceRecord({profileName: 'myProfile'})34 .pause(20000)35 .stopPerformanceRecord({profileName: 'myProfile'})36 .savePerformanceData({profileName: 'myProfile', 'path/to/myProfile.mobileperformance'})37 .end();38var webdriverio = require('webdriverio');39var options = {40 desiredCapabilities: {
Using AI Code Generation
1const {remote} = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async function () {7 const client = await remote(opts);8 await client.start();9 await client.pause(10000);10 await client.deleteSession();11})();12[0-0] 2020-12-11T10:00:00.000Z INFO webdriver: DATA {13[0-0] capabilities: {14[0-0] alwaysMatch: {15[0-0] appium: {16[0-0] },17[0-0] },18[0-0] firstMatch: [ {} ]19[0-0] },20[0-0] desiredCapabilities: {21[0-0] }22[0-0] }23[0-0] 2020-12-11T10:00:00.000Z INFO webdriver: COMMAND start()
Using AI Code Generation
1const wdio = require('webdriverio');2const assert = require('assert');3describe('Appium XCUITest Driver', function() {4 it('should start a session', async function() {5 const opts = {6 capabilities: {7 }8 };9 const client = await wdio.remote(opts);10 await client.start();11 await client.pause(5000);12 await client.deleteSession();13 });14});15exports.config = {16 capabilities: [{17 }],18 appium: {19 args: {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!