import { parse, isValid, format as formatDate } from 'date-fns';

/**
 * Custom parse behavior on top of date-fns parse function.
 * @param {String} date
 * @param {String} format
 * @return {Date|null}
 */
export const parseDate = (date, format) => {
  const parsed = parse(date, format, new Date());

  // if date is not valid or the formatted output after parsing does not match
  // the string value passed in (avoids overflows)
  if (!isValid(parsed) || formatDate(parsed, format) !== date) {
    return null;
  }

  return parsed;
};

@@ -59,16 +59,26 @@
 -fns';%0A%0A
+// @flow%0A%0A
 /**%0A * C
@@ -137,81 +137,8 @@
 on.%0A
- * @param %7BString%7D date%0A * @param %7BString%7D format%0A * @return %7BDate%7Cnull%7D%0A
  */%0A
@@ -144,21 +144,24 @@
 %0Aexport 
-const
+function
  parseDa
@@ -166,28 +166,46 @@
 Date
- =
  (date
-, format) =%3E
+: string, format: string): ?Date
  %7B%0A 

add flow typings for date utils