How to use the date-fns/parse function in date-fns

To help you get started, we’ve selected a few date-fns 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 grubersjoe / react-github-calendar / src / lib / services / contributions.js View on Github external
function getBlocksForYear(year, data, fullYear) {
  const now = new Date();
  const firstDate = fullYear ? subYears(now, 1) : parse(`${year}-01-01`);
  const lastDate = fullYear ? now : parse(`${year}-12-31`);

  let weekStart = firstDate;

  // The week starts on Sunday - add days to get to next sunday if neccessary
  if (getDay(firstDate) !== 0) {
    weekStart = addDays(firstDate, getDay(firstDate));
  }

  // Fetch graph data for first row (Sundays)
  const firstRowDates = [];
  while (weekStart <= lastDate) {
    const date = format(weekStart, DATE_FORMAT);

    firstRowDates.push({
      date,
github iotaledger / industry-marketplace / ServiceApp / src / components / add-asset / index.js View on Github external
async submit() {
    const { operation, submodel, assetStart, assetEnd } = this.state;
    const { location } = this.context.user;
    const startDate = parse(assetStart);
    const endDate = parse(assetEnd);

    if (!this.state.operation)
      return alert('Please specify required operation');
    if (!this.state.assetStart || !startDate || !isValid(startDate) || !isFuture(startDate))
      return alert('Please enter a valid date/time when the request starts');
    if (!this.state.assetEnd || !endDate || !isValid(endDate) || compareDesc(startDate, endDate) !== 1)
      return alert('Please enter a valid date/time when the request ends');


    const submodelValues = {};
    submodel.forEach(({ semanticId, value, valueType }) => {
      if (['date', 'dateTime', 'dateTimeStamp'].includes(valueType)) {
        submodelValues[semanticId] = Date.parse(value);
      } if (valueType === 'boolean') {
        submodelValues[semanticId] = Boolean(value);
github vusion / cloud-ui / src / u-calendar-day.vue / index.js View on Github external
value(value, oldValue) {
            const newDate = parse(value);
            const oldDate = parse(oldValue);
            if (isEqual(newDate, oldDate))
                return;
            this.initDate();
        },
    },
github clauderic / react-infinite-calendar / src / Calendar / index.js View on Github external
updateYears(props = this.props) {
    this._min = parse(props.min);
    this._max = parse(props.max);
    this._minDate = parse(props.minDate);
    this._maxDate = parse(props.maxDate);

    const min = this._min.getFullYear();
    const minMonth = this._min.getMonth();
    const max = this._max.getFullYear();
    const maxMonth = this._max.getMonth();

    const months = [];
    let year, month;
    for (year = min; year <= max; year++) {
      for (month = 0; month < 12; month++) {
        if (
          year === min && month < minMonth ||
          year === max && month > maxMonth
        ) {
          continue;
        }
github gpbl / react-day-picker / docs / src / code-samples / examples / input-date-fns.js View on Github external
function parseDate(str, format, locale) {
  const parsed = dateFnsParse(str, format, { locale });
  if (DateUtils.isDate(parsed)) {
    return parsed;
  }
  return undefined;
}
github AdguardTeam / AdGuardHome / client / src / helpers / helpers.js View on Github external
export const formatTime = (time, options = DEFAULT_TIME_FORMAT) => {
    const parsedTime = dateParse(time);
    return dateFormat(parsedTime, options);
};
github Hacker0x01 / react-datepicker / src / date_utils.js View on Github external
dateFormat = dateFormat
      .match(longFormattingTokensRegExp)
      .map(function(substring) {
        var firstCharacter = substring[0];
        if (firstCharacter === "p" || firstCharacter === "P") {
          var longFormatter = longFormatters[firstCharacter];
          return localeObject
            ? longFormatter(substring, localeObject.formatLong)
            : firstCharacter;
        }
        return substring;
      })
      .join("");

    if (value.length > 0) {
      parsedDate = parse(value, dateFormat.slice(0, value.length), new Date());
    }

    if (!isValid(parsedDate)) {
      parsedDate = new Date(value);
    }
  }

  return isValid(parsedDate) && strictParsingValueMatch ? parsedDate : null;
}
github ThymeApp / thyme / src / core / reportQueryString.js View on Github external
export function queryStringTo(): Date {
  const { to } = currentQueryString();

  if (!to) {
    return endOfWeek(new Date(), { weekStartsOn: 1 });
  }

  return parse(to);
}
github clauderic / react-infinite-calendar / src / Calendar / withRange.js View on Github external
function handleYearSelect(date, {displayKey, onSelect, selected, setScrollDate}) {

  setScrollDate(date);
  onSelect(getSortedSelection(
    Object.assign({}, selected, {[displayKey]: parse(date)}))
  );
}