javascript - Detect dates between strings and times using momentjs -
i have string this
occurs every 1 weeks on sunday, monday, tuesday, wednesday, thursday, friday , saturday effective 2015-07-23t00:00:00 t16:00:00 t17:00:00
you can see got words, times , dates. need apply formats dates , times, , internationalization strings.
the code works this
var result = ''; // values array var arrvalue = value.split(' '), resultarr = []; // iterate in each element (var = 0; < arrvalue.length; i++) { // validate date if (moment(arrvalue[i], moment.iso_8601).isvalid() && (arrvalue[i].indexof('t') != -1)) { // push array resultarr.push(moment(arrvalue[i]).format('l')); // validate time } else if (moment('0001-01-01' + arrvalue[i], moment.iso_8601).isvalid() && (arrvalue[i].indexof('t') != -1)) { // push result date resultarr.push(moment('0001-01-01' + arrvalue[i]).format('lt')); } else { // push string in collection resultarr.push(sgi18nservice.translate(['portfolio', 'activity-recurrence-field-' + arrvalue[i]], arrvalue[i])); } }
which works fine (then join strings). problem in ie not working recognize strings, , confuses them date, example, after split strings got every day string , when evaluate
moment('0001-01-01thursday,', moment.iso_8601).isvalid()
i false in chrome (which fine, since thursday string, not date) in ie true. checked , looks transforming invalid date minimum date
tue jan 01 1901 00:00:00 gmt-0500
that example when evaluating second if. have issue of getting valid dates thursday , tuesday. i'm doing wrong ? how can difference strings dates , times in ie ?
edit: strings limited, have different combination of string not entered user.
well, input strings limited , knew case have, matched string have numbers
/\d/.test()
worked me
Comments
Post a Comment