Welcome to mirror list, hosted at ThFree Co, Russian Federation.

datetime_range.js « utils « lib « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f0a03874949fa39813f43e1c911710fdcd0c44c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import dateformat from '~/lib/dateformat';

export const isValidDateString = (dateString) => {
  if (typeof dateString !== 'string' || !dateString.trim()) {
    return false;
  }

  let isoFormatted;
  try {
    isoFormatted = dateformat(dateString, 'isoUtcDateTime');
  } catch (e) {
    if (e instanceof TypeError) {
      // not a valid date string
      return false;
    }
    throw e;
  }
  return !Number.isNaN(Date.parse(isoFormatted));
};