首页 > 解决方案 > React-native 函数在调试模式下工作但不在发布模式下

问题描述

我厌倦了一整天来解决这个问题,下面的函数不能在发布模式下工作,但它正在调试模式下工作。它应该返回日期范围。

import moment from 'moment';

this.state = {
startDate: '01-01-2019',
endDate: '02-02-2019'
};
getArr(checkedWeekDay) {
    const { endDate, startDate } = this.state;

    const dateRange = [];
    const endOfRange = moment(endDate).endOf('month');
    const startOfRange = moment(startDate).startOf('month').day(checkedWeekDay);
    const S = 7;
    const O = 1;

    if (startOfRange.date() > S) startOfRange.add(S, 'days');

    for (let $index = startOfRange; $index < endOfRange; $index.add(O, 'M')) {
      const startOfIndex = moment($index).startOf('month').day(checkedWeekDay);

      if (startOfIndex.date() > S) startOfIndex.add(S, 'days');
      const startIndex = startOfIndex.clone();

      while (startOfIndex.month() === startIndex.month()) {
        if (startIndex >= moment(startDate) && startIndex <= moment(endDate)) {
          dateRange.push(startIndex.format('YYYY-MM-DD'));
        }
        startIndex.add(S, 'days');
      }
    }
    return dateRange;
  }

this.getArr(5);

结果应该如下,

["2019-01-04", "2019-01-11", "2019-01-18", "2019-01-25", "2019-02-01"]

标签: iosreactjsreact-nativemomentjs

解决方案


推荐阅读