How to use the moment.isMoment function in moment

To help you get started, we’ve selected a few moment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeekAb / picker.js / js / datepicker.js View on Github external
parseDate(value, format = this.config.format) {
      // @see http://momentjs.com/docs/#/parsing/

      // return any current moment
      if (moment.isMoment(value)) {
        if (!value.isValid()) {
          this.throwError(`Invalid moment: ${value} provided.`)
        }

        return this.newMoment(value)
      }
      else if (typeof value === "string") {
        // parse with locale and strictness
        let m = moment(value, format, this.config.lang, true)

        if (!m.isValid()) {
          this.throwError(`Invalid moment: ${value} for format: ${format} and locale: ${this.config.lang}`)
        }

        return m
      }
github RodgerLai / nodejs-nedb-excel / src / components / DBTable / InnerForm.js View on Github external
filterQueryObj(oldObj) {
    // 将提交的值中undefined的去掉
    const newObj = {};
    for (const key in oldObj) {
      if (oldObj[key]) {
        // 对于js的日期类型, 要转换成字符串再传给后端
        if (oldObj[key] instanceof Date) {
          newObj[key] = oldObj[key].format('yyyy-MM-dd HH:mm:ss');
        } else if (moment.isMoment(oldObj[key])) {  // 处理moment对象
          newObj[key] = oldObj[key].format('YYYY-MM-DD HH:mm:ss');
        } else {
          newObj[key] = oldObj[key];
        }
      }
    }
    logger.debug('old queryObj: %o, new queryObj %o', oldObj, newObj);
    return newObj;
  }
github elastic / kibana / x-pack / legacy / plugins / ml / public / jobs / jobs_list / components / start_datafeed_modal / time_range_selector / time_range_selector.js View on Github external
getTabItems() {
    const datePickerTimes = {
      start: moment.isMoment(this.props.startTime) ? this.props.startTime : this.latestTimestamp,
      end: moment.isMoment(this.props.endTime) ? this.props.endTime : this.now,
    };
    const formattedStartTime = this.latestTimestamp.format(TIME_FORMAT);

    // Show different labels for the start time depending on whether
    // the job has seen any data yet
    const showContinueLabels = this.latestTimestamp.valueOf() > 0;
    const startLabels =
      showContinueLabels === true
        ? [
            ,
github arfedulov / semantic-ui-calendar-react / test / pickers / testYearPicker.js View on Github external
it('initialized with moment', () => {
    const date = moment('2015-05-01');
    const wrapper = mount();
    assert(moment.isMoment(wrapper.state('date')), 'has moment instance in `date` state field');
    assert(wrapper.state('date').isSame(date), 'initialize `date` state field with moment provided in `initializeWith` prop');
  });
});
github iuap-design / bee.tinper.org / tinper-bee / bee-datepicker / src / rc-calendar / util / index.js View on Github external
export function syncTime(from, to) {
  if (!moment.isMoment(from) || !moment.isMoment(to)) return;
  to.hour(from.hour());
  to.minute(from.minute());
  to.second(from.second());
}
github NSFI / ppfish-components / source / components / BizTimePicker / index.js View on Github external
constructor(props) {
    super(props);
    const value = getValueFromTime(props.value || props.defaultValue);
    if( value[0] && !moment.isMoment(value[0]) || !value[1] && moment.isMoment(value[1]) ) {
      throw new Error('The value/defaultValue of BizTimePicker must be a moment object array');
    }
    this.state = {
      showDate: getShowDateFromValue(props.value || props.defaultValue || props.quickTimeOption[0], props.format),
      open: props.open
    };
  }
github JedWatson / react-select / docs / examples / Experimental.js View on Github external
const createOptionForDate = d => {
  const date = moment.isMoment(d) ? d : moment(d);
  return {
    date,
    value: date.toDate(),
    label: date.calendar(null, {
      sameDay: '[Today] (Do MMM YYYY)',
      nextDay: '[Tomorrow] (Do MMM YYYY)',
      nextWeek: '[Next] dddd (Do MMM YYYY)',
      lastDay: '[Yesterday] (Do MMM YYYY)',
      lastWeek: '[Last] dddd (Do MMM YYYY)',
      sameElse: 'Do MMMM YYYY',
    }),
  };
};
github elastic / kibana / src / core_plugins / timelion / server / lib / date_math.js View on Github external
export default function parse(text, roundUp) {
  if (!text) {
    return undefined;
  }
  if (moment.isMoment(text)) {
    return text;
  }
  if (_.isDate(text)) {
    return moment(text);
  }

  let time;
  let mathString = '';
  let index;
  let parseString;

  if (text.substring(0, 3) === 'now') {
    time = moment();
    mathString = text.substring('now'.length);
  } else {
    index = text.indexOf('||');
github elastic / kibana / x-pack / legacy / plugins / canvas / canvas_plugin_src / renderers / time_filter / components / pretty_duration / lib / format_duration.ts View on Github external
function formatTime(time: string | Moment, roundUp = false) {
  if (moment.isMoment(time)) {
    return time.format('lll');
  } else {
    if (time === 'now') {
      return 'now';
    } else {
      const tryParse = dateMath.parse(time, { roundUp });
      return moment.isMoment(tryParse) ? '~ ' + tryParse.fromNow() : time;
    }
  }
}