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 cornerstonejs / react-cornerstone-viewport / src / helpers / formatDA.js View on Github external
export default function formatDA(date, strFormat = 'MMM d, yyyy') {
  if (!date) {
    return;
  }

  // Goal: 'Apr 5, 1999'
  try {
    const parsedDateTime = parse(date, 'yyyyMMdd', new Date());
    const formattedDateTime = format(parsedDateTime, strFormat);

    return formattedDateTime;
  } catch (err) {
    // swallow?
  }

  return;
}
github upvalue / meditations / frontend / src / habits / HabitsContainerState.ts View on Github external
const scopeMounted = (currentDate: string, date: string): ScopeMountedResult => {
  const currentDateObj = parse(currentDate, 'yyyy-MM', baseDate);
  // If year
  const yearCheck = parse(date, 'yyyy', baseDate);
  const monthCheck = parse(date, 'yyyy-MM', baseDate);
  const dayCheck = parse(date, 'yyyy-MM-dd', baseDate);
  if (isValid(yearCheck)) {
    return format(currentDateObj, 'yyyy') === date && 'Year';
  } else if (isValid(dayCheck)) {
    return currentDate === format(dayCheck, 'yyyy-MM') && 'Days';
  } else if (isValid(monthCheck)) {
    // Must come after days check
    return format(currentDateObj, 'yyyy-MM') === date && 'Month';
  }
  return false;
}
github hyunchel / melon-chart-api / test / dateRange.js View on Github external
const isValidDaily = function isValidDaily(startDate, endDate, givenDate) {
  const start = parse(startDate);
  const end = parse(endDate);
  const given = parse(givenDate);
  return (isSameDay(start, given)) && (isSameDay(end, given));
};
github ui-model / ui-model / projects / ui-model / common / src / lib / calendar / calendar.spec.ts View on Github external
it('weekend', () => {
      expect(calendar.isWeekEnd(parse('2017-02-13'))).toBeFalsy();
      expect(calendar.isWeekEnd(parse('2017-02-12'))).toBeTruthy();
      expect(calendar.isWeekEnd(parse('2017-02-18'))).toBeTruthy();
    });
    it('same month', () => {
github gpbl / react-day-picker / package / lib / index.esm.js View on Github external
function onBlur(e) {
        var el = e.target;
        var day = parse(el.value, formatStr, new Date(), options);
        if (isValid(day) || !options.required) {
            if (onBlur)
                onBlur(e);
            return;
        }
        setSelectedDay(initialSelectedDay);
        setCurrentMonth(initialSelectedDay || new Date());
        setInputValue(initialInputValue || '');
    }
    function onFocus(e) {
github madebymany / front-end-london / gatsby-node.js View on Github external
exports.onCreateNode = ({ node, actions }) => {
  const { createNodeField } = actions
  if (node.internal.type === `EventsJson`) {
    const parsedDate = parse(node.date, "yyyy-MM-dd HH:mm", new Date())
    createNodeField({
      node,
      name: "timestamp",
      value: parsedDate.getTime(),
    })

    const parsedTickets = parse(
      node.tickets_released,
      "yyyy-MM-dd HH:mm",
      new Date()
    )
    createNodeField({
      node,
      name: "ticket_timestamp",
      value: parsedTickets.getTime(),
    })
github joker1007 / crono_trigger / web / app / src / SchedulableRecord.tsx View on Github external
private formatTime(iso8601: string | null): string {
    if (iso8601 === null) {
      return "";
    }
    const date = parse(iso8601);
    return format(date, "YYYY/MM/DD (ddd) HH:mm:ss Z");
  }
github canonical-web-and-design / snapcraft.io / static / js / publisher / release / selectors / index.js View on Github external
.filter(b => {
      return differenceInDays(now, parse(b.when)) <= 30;
    })
    .reverse();
github floatdrop / node-cctz / bench.js View on Github external
.add('Parse           (date-fns)', () => {
		dateFns.parse('2015-09-22 09:35:12+03:00');
	})
	.add('Parse             (moment)', () => {
github nginformatica / flipper-ui / src / charts / LineVerticalBarChart.tsx View on Github external
    (x: string) => parse(x as string, 'yyyy-MM-dd', new Date())