Detect dates between lines and times using pulses

I have a line like this

Occurs every 1 weeks on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday effective 2015-07-23T00:00:00 from T16:00:00 to T17:00:00


You can see that I have words, times and dates. I need to apply formats to dates and times and internationalization to strings.

The code works like this

var result = '';
// get values as an array
var arrValue = value.split(' '), resultArr = [];
// iterate in each element
for (var i = 0; i < arrValue.length; i++) {
    // validate is a date
    if (moment(arrValue[i], moment.ISO_8601).isValid() && (arrValue[i].indexOf('T') != -1)) {
        // push into array
        // validate is a time
    } else if (moment('0001-01-01' + arrValue[i], moment.ISO_8601).isValid() && (arrValue[i].indexOf('T') != -1)) {
        // push as a result the date
        resultArr.push(moment('0001-01-01' + arrValue[i]).format('LT'));
    } else {
        // push the string in the collection
        resultArr.push(sgI18NService.translate(['portfolio', 'activity-recurrence-field-' + arrValue[i]], arrValue[i]));


which works fine (then I join lines). The problem is that it doesn't work properly in IE to recognize some strings and it confuses them as Date, for example after I split the strings that I was getting every day as a string and when I evaluate

moment('0001-01-01Thursday,', moment.ISO_8601).isValid()


I'm wrong in Chrome (that's ok since Thursday is a string, not a date), but in IE I get the truth. I have checked and it looks like it is converting invalid date to minimum date

Tue Jan 01 1901 00:00:00 GMT-0500


This example was when evaluating the second if. I have a problem of getting the correct dates from Thursday and Tuesday. What am I doing wrong? How can I split strings from dates and from time in IE?

edit: strings are limited, I have another string combination but they are not entered by the user.


source to share

1 answer

Well since my input strings were limited and I knew I would have a case, I matched the string with numbers



worked for me



All Articles